Files
chocomae/src/web/js/main.js
T

95 lines
2.0 KiB
JavaScript

let maestroID = -1;
$(document).ready(function() {
loadMaestroID();
});
function loadMaestroID() {
maestroID = sessionStorage.getItem("maestroID");
if(maestroID === null) {
maestroID = -1;
sessionStorage.setItem("maestroID", maestroID);
}
maestroID = Number(maestroID);
console.log("loaded maestroID : " + maestroID);
}
function saveMaestroID(maestroID) {
sessionStorage.setItem("maestroID", maestroID);
// console.log("saved maestroID : " + maestroID);
}
function getParentDirectory(url) {
let directories = url.split("/");
if(directories.length < 2)
return "";
return directories[directories.length - 2];
}
function getPage(url) {
let directories = url.split("/");
if(directories.length < 1)
return "";
return directories[directories.length - 1];
}
function goHome() {
let url = window.location.href;
if(getParentDirectory(url) === "maestro") {
if(getPage(url) !== "main_menu.html")
location.href = "./../maestro/main_menu.html";
return;
}
// parent directory is "main"
if(getPage(url) === "faq.html") {
if(maestroID === -1) {
location.href = "./../main/index.html";
} else {
location.href = "./../maestro/main_menu.html";
}
} else if(getPage(url) !== "index.html")
location.href = "./../main/index.html";
}
function logout() {
sessionStorage.clear();
maestroID = -1;
sessionStorage.setItem("maestroID", maestroID);
location.href = './../main/index.html';
}
function showErrorMessage(message, type) {
console.log("showErrorMessage : " + message);
let messageBox = $("#message_box");
if(!messageBox)
return;
let alertType = "";
switch(type) {
case "success":
alertType = "alert-success";
break;
case "warning":
alertType = "alert-warning";
break;
case "info":
alertType = "alert-info";
break;
case "error":
default:
alertType = "alert-danger";
}
messageBox.html(
'<div class="alert ' + alertType + '" role="alert">'
+ '<button type="button" class="close" data-dismiss="alert">&times;</button>'
+ message
+ '</div>'
);
}