Frontend: Refactor indexjs
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
67cc929158
commit
0958bc92f5
@ -1,38 +1,21 @@
|
|||||||
// Init:
|
// Init:
|
||||||
setQls();
|
pageInit();
|
||||||
clearLoading();
|
|
||||||
|
|
||||||
async function sidebarOpen() {
|
async function pageInit() {
|
||||||
document.getElementById("sidebar").style.width = "50%";
|
await loadQuickLinks();
|
||||||
document.getElementById("sidebar_open_short").style.display = "none";
|
hideLoading();
|
||||||
document.getElementById("sidebar_close_short").style.display = "block";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sidebarClose() {
|
|
||||||
document.getElementById("sidebar").style.width = "0%"
|
|
||||||
document.getElementById("sidebar_open_short").style.display = "block";
|
|
||||||
document.getElementById("sidebar_close_short").style.display = "none";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gotoBoard(station){
|
async function gotoBoard(station){
|
||||||
window.location.assign(`${window.location.origin}/board.html?stn=${station}`)
|
window.location.assign(`${window.location.origin}/board.html?stn=${station}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setQls(){
|
async function loadQuickLinks(){
|
||||||
var qlOpt = JSON.parse(localStorage.getItem("qlOpt"))
|
var data = await getQuickLinks(); // From lib.main
|
||||||
var qlDef = ["bri","lwh","srd","mtp","rda","cfn","sml","shh","pri","avn","sar","svb"]
|
var buttons = "";
|
||||||
if (qlOpt) {
|
for(var i = 0; i < data.length; i++) {
|
||||||
for(var i = 0; i < qlOpt.length; i++) {
|
buttons += `
|
||||||
console.log(`Button: ${qlOpt[i]}`)
|
<button class="actionbutton" onclick="gotoBoard('${data[i]}')">${data[i].toUpperCase()}</button>`
|
||||||
var btn = `<button class="actionbutton" onclick="gotoBoard('${qlOpt[i]}')">${qlOpt[i].toUpperCase()}</button>`
|
|
||||||
console.log(btn);
|
|
||||||
document.getElementById("quick_links").insertAdjacentHTML("beforeend", btn) // Append btn
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(var i = 0; i < qlDef.length; i++) {
|
|
||||||
console.log(`Button: ${qlDef[i]}`)
|
|
||||||
var btn = `<button class="actionbutton" onclick="gotoBoard('${qlDef[i]}')">${qlDef[i].toUpperCase()}</button>`
|
|
||||||
document.getElementById("quick_links").insertAdjacentHTML("beforeend", btn) // Append btn
|
|
||||||
}
|
}
|
||||||
}
|
document.getElementById("quick_links").insertAdjacentHTML("beforeend", buttons)
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ async function storageAvailable(type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Delays */
|
/* Timeouts */
|
||||||
/* Usage: '' */
|
/* Usage: '' */
|
||||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
@ -43,6 +43,19 @@ async function log(msg, type) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Menu Control */
|
||||||
|
async function sidebarOpen() {
|
||||||
|
document.getElementById("sidebar").style.width = "50%";
|
||||||
|
document.getElementById("sidebar_open_short").style.display = "none";
|
||||||
|
document.getElementById("sidebar_close_short").style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sidebarClose() {
|
||||||
|
document.getElementById("sidebar").style.width = "0%"
|
||||||
|
document.getElementById("sidebar_open_short").style.display = "block";
|
||||||
|
document.getElementById("sidebar_close_short").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
/* Loading Box Control */
|
/* Loading Box Control */
|
||||||
async function hideLoading() {
|
async function hideLoading() {
|
||||||
document.getElementById("loading").style = "display: none;";
|
document.getElementById("loading").style = "display: none;";
|
||||||
@ -50,7 +63,7 @@ async function hideLoading() {
|
|||||||
|
|
||||||
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
|
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
|
||||||
async function clearLoading() {
|
async function clearLoading() {
|
||||||
log("Depreciated function called - clearLoading()", "WARN")
|
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN")
|
||||||
await hideLoading();
|
await hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,3 +74,15 @@ async function showLoading() {
|
|||||||
async function setLoadingDesc(desc) {
|
async function setLoadingDesc(desc) {
|
||||||
document.getElementById("loading_desc").textContent = `${desc}`;
|
document.getElementById("loading_desc").textContent = `${desc}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fetch User Settings */
|
||||||
|
async function getQuickLinks() {
|
||||||
|
try {
|
||||||
|
var data = JSON.parse(localStorage.getItem("qlOpt"));
|
||||||
|
} catch (err) {
|
||||||
|
var data =
|
||||||
|
["bri","lwh","srd","mtp","rda","cfn",
|
||||||
|
"sml","shh","pri","avn","sar","svb"];
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user