Add QC shifts, add proper icon, check for app permissions, adjust styles, fix UI bugs, prepare login UI for quick access mode
82 lines
2.5 KiB
JavaScript
82 lines
2.5 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 = [];
|
|
|
|
var cardSettings = {
|
|
"qwikclock_punchinout": {"classes": "col-sm-12 col-md-4 col-lg-4 col-xl-4 order-1"},
|
|
"qwikclock_myshifts": {"classes": "col-sm-12 col-md-8 col-lg-8 col-xl-6 order-2"}
|
|
};
|
|
|
|
function loadCard(type, apiurl, title) {
|
|
$.get("cards/" + type + ".html", {}, function (html) {
|
|
console.log(type + " " + apiurl + " " + title);
|
|
var cardClasses = "col-sm-12 col-md-6 col-lg-6 col-xl-4 order-12";
|
|
if (cardSettings.hasOwnProperty(type) && cardSettings[type].hasOwnProperty("classes")) {
|
|
cardClasses = cardSettings[type]["classes"];
|
|
}
|
|
var box = $('<div class="col ' + cardClasses + '" 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");
|
|
$("#refresh-btn").css("display", "inline-block"); |