|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
var $$ = Dom7;
|
|
|
|
|
|
|
|
// Detect platform and run platform-specific setup code
|
|
|
|
// for Cordova, NW.js, or the browser
|
|
|
|
initPlatform();
|
|
|
|
|
|
|
|
Template7.global = {
|
|
|
|
qrenabled: (platform_type == "cordova")
|
|
|
|
};
|
|
|
|
|
|
|
|
var app = new Framework7({
|
|
|
|
root: "#app",
|
|
|
|
name: "TerranQuest",
|
|
|
|
id: "com.netsyms.terranquest.TerranQuest",
|
|
|
|
theme: platform_theme,
|
|
|
|
card: {
|
|
|
|
swipeToClose: false
|
|
|
|
},
|
|
|
|
popup: {
|
|
|
|
backdrop: true
|
|
|
|
},
|
|
|
|
init: true,
|
|
|
|
initOnDeviceReady: false,
|
|
|
|
routes: routes
|
|
|
|
});
|
|
|
|
|
|
|
|
var mainView = app.views.create('.view-main', {
|
|
|
|
url: "/"
|
|
|
|
});
|
|
|
|
|
|
|
|
var router = mainView.router;
|
|
|
|
|
|
|
|
function restartApplication() {
|
|
|
|
window.location = "index.html";
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout() {
|
|
|
|
localStorage.clear();
|
|
|
|
restartApplication();
|
|
|
|
}
|
|
|
|
|
|
|
|
router.on("pageInit", function (pagedata) {
|
|
|
|
pagedata.$el.find('script').each(function (el) {
|
|
|
|
if ($$(this).attr('src')) {
|
|
|
|
var s = document.createElement('script');
|
|
|
|
s.src = $$(this).attr('src');
|
|
|
|
$$('head').append(s);
|
|
|
|
} else {
|
|
|
|
eval($$(this).text());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the server is alive.
|
|
|
|
* @param {function} callback
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
function isServerAlive(callback) {
|
|
|
|
callAPIRawResponse("ping", {}, function (data) {
|
|
|
|
callback(true);
|
|
|
|
}, function (msg, xhr) {
|
|
|
|
app.preloader.hide();
|
|
|
|
if (xhr.status == 401) {
|
|
|
|
callback(true);
|
|
|
|
} else if (xhr.status == 400) {
|
|
|
|
callback(true);
|
|
|
|
} else {
|
|
|
|
callback(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the saved username and password are valid.
|
|
|
|
* @param {function} callback A function that will be called with a boolean argument indicating validity.
|
|
|
|
* @return {undefined}
|
|
|
|
*/
|
|
|
|
function checkLogin(callback) {
|
|
|
|
if (localStorage.getItem("username") === null || localStorage.getItem("password") === null) {
|
|
|
|
callback(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callAPI("ping", {}, function (data) {
|
|
|
|
callback(true);
|
|
|
|
}, function (msg) {
|
|
|
|
callback(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localStorage.getItem("configured") == null) {
|
|
|
|
router.navigate("/signin");
|
|
|
|
} else {
|
|
|
|
checkClientVersion(function (ok) {
|
|
|
|
if (ok) {
|
|
|
|
// Version OK
|
|
|
|
checkLogin(function (valid) {
|
|
|
|
if (valid) {
|
|
|
|
callAPI("playerexists", {}, function (resp) {
|
|
|
|
if (resp.exists == true) {
|
|
|
|
router.navigate("/home");
|
|
|
|
} else {
|
|
|
|
router.navigate("/chooseteam");
|
|
|
|
}
|
|
|
|
}, function (msg) {
|
|
|
|
router.navigate("/signin");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
router.navigate("/signin");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Version incompatible
|
|
|
|
router.navigate("/upgrade");
|
|
|
|
}
|
|
|
|
}, function () {
|
|
|
|
router.navigate("/connection");
|
|
|
|
});
|
|
|
|
}
|