|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function loadHomePage(reload) {
|
|
|
|
if (typeof reload == 'undefined') {
|
|
|
|
reload = false;
|
|
|
|
}
|
|
|
|
$.post(localStorage.getItem("syncurl"), {
|
|
|
|
username: localStorage.getItem("username"),
|
|
|
|
key: localStorage.getItem("key"),
|
|
|
|
action: "listapps"
|
|
|
|
}, function (data) {
|
|
|
|
if (data.status === 'OK') {
|
|
|
|
if (!reload) {
|
|
|
|
loadingProgressDialog.setProgress(80);
|
|
|
|
}
|
|
|
|
var appcards = [];
|
|
|
|
Object.keys(data.apps).forEach(function (k) {
|
|
|
|
var app = data.apps[k];
|
|
|
|
var iconurl = app.icon;
|
|
|
|
if (!app.icon.startsWith("http")) {
|
|
|
|
iconurl = app.url + app.icon;
|
|
|
|
}
|
|
|
|
if (!app.card) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
appcards.push({
|
|
|
|
api: app.mobileapi,
|
|
|
|
url: app.url,
|
|
|
|
icon: iconurl,
|
|
|
|
title: app.title,
|
|
|
|
text: app.card.string,
|
|
|
|
color: app.card.color
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (reload) {
|
|
|
|
// Make it seem like it's doing something on fast connections
|
|
|
|
setTimeout(function () {
|
|
|
|
app.ptr.done();
|
|
|
|
router.navigate("/home", {
|
|
|
|
context: {
|
|
|
|
appcards: appcards
|
|
|
|
},
|
|
|
|
reloadCurrent: true
|
|
|
|
});
|
|
|
|
}, 500);
|
|
|
|
} else {
|
|
|
|
loadingProgressDialog.setProgress(90);
|
|
|
|
router.navigate("/home", {
|
|
|
|
context: {
|
|
|
|
appcards: appcards
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(".view-main").on("click", "#applist .applist-item", function () {
|
|
|
|
launchapp($(this).data("api"), $(this).data("url"), $(this).data("icon"), $(this).data("title"));
|
|
|
|
});
|
|
|
|
loadingProgressDialog.setProgress(100);
|
|
|
|
loadingProgressDialog.close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (reload) {
|
|
|
|
app.ptr.done();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loadingProgressDialog.close();
|
|
|
|
app.dialog.alert(data.msg, "Error", function () {
|
|
|
|
restartApplication();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, "json").fail(function () {
|
|
|
|
loadingProgressDialog.close();
|
|
|
|
app.dialog.alert("Could not connect to the server. Try again later.", "Error", function () {
|
|
|
|
restartApplication();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(".view-main").on("ptr:refresh", ".ptr-content", function () {
|
|
|
|
loadHomePage(true);
|
|
|
|
});
|