You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Station/js/home.js

72 lines
2.1 KiB
JavaScript

/*
* 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 loadedCardTypes = [];
var totalCardTypes = [];
function loadCard(type, apiurl, title) {
$.get("cards/" + type + ".html", {}, function (html) {
console.log(type + " " + apiurl + " " + title);
var box = $('<div class="col col-sm-12 col-md-6 col-lg-6 col-xl-4" id=""></div>');
var card = $('<div class="card card_app card_' + type + '" style="width: 100%;" data-title="' + title + '" data-apiurl="' + apiurl + '"></div>');
$(card).html(html);
$(box).html(card);
$("#card-box").append(box);
if (loadedCardTypes.indexOf(type) == -1) {
loadedCardTypes.push(type);
}
});
}
function applyCardTitles() {
$(".card_app").each(function () {
var title = $(this).data("title");
$(this).find(".card_title").text(title);
});
}
function waitForCardsToLoadThenInjectScripts() {
// How's *that* for self-documenting code?
for (var i = 0; i < totalCardTypes.length; i++) {
if (loadedCardTypes.indexOf(totalCardTypes[i]) == -1) {
setTimeout(waitForCardsToLoadThenInjectScripts, 50);
return;
}
}
applyCardTitles();
for (var i = 0; i < loadedCardTypes.length; i++) {
$.getScript('cards/js/' + loadedCardTypes[i] + '.js');
}
}
getApps(function (apps) {
console.log(apps);
for (var appname in apps) {
if (!apps.hasOwnProperty(appname)) {
continue;
}
var app = apps[appname];
console.log(app);
console.log(" " + app.url);
console.log(" " + app.title);
if (typeof app.station_features !== "undefined" && app.station_features.length > 0) {
for (var type in app.station_features) {
if (!app.station_features.hasOwnProperty(type)) {
continue;
}
totalCardTypes.push(app.station_features[type]);
loadCard(app.station_features[type], app.url + "/api.php", app.title);
}
}
}
waitForCardsToLoadThenInjectScripts();
});
startSessionTimeout();
$("#sign-out-btn").css("display", "inline-block");