/* 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: false }, init: true, initOnDeviceReady: false, routes: routes }); var mainView = app.views.create('.view-main', { url: "/" }); var router = mainView.router; function restartApplication() { window.location = "index.html"; } 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 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", { username: localStorage.getItem("username"), password: localStorage.getItem("password") }, function (data) { callback(true); }, function (msg) { callback(false); }); } if (localStorage.getItem("configured") == null) { router.navigate("/signin"); } else { checkLogin(function (valid) { if (valid) { callAPI("playerexists", { username: localStorage.getItem("username"), password: localStorage.getItem("password") }, function (resp) { if (resp.exists == true) { router.navigate("/home"); } else { router.navigate("/chooseteam"); } }, function (msg) { router.navigate("/signin"); }); } else { router.navigate("/signin"); } }); }