diff options
author | rstular <rok@stular.eu> | 2020-05-16 20:08:05 +0200 |
---|---|---|
committer | rstular <rok@stular.eu> | 2020-05-16 20:08:33 +0200 |
commit | 9d88acff4d715cdc6b44c8955049bb0289fb17f7 (patch) | |
tree | b7b2c5c14098c52e52e3cd334362d98f4491ecae /js/absences.js | |
parent | Bug fix - handling afternoon lessons (diff) | |
download | beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar.gz beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar.bz2 beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar.lz beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar.xz beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.tar.zst beziapp-9d88acff4d715cdc6b44c8955049bb0289fb17f7.zip |
Diffstat (limited to 'js/absences.js')
-rw-r--r-- | js/absences.js | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/js/absences.js b/js/absences.js index 9bc4a83..c0d08a7 100644 --- a/js/absences.js +++ b/js/absences.js @@ -1,6 +1,9 @@ // const API_ENDPOINT = "https://gimb.tk/test.php"; // deprecated // const API_ENDPOINT = "http://localhost:5000/test.php"; -var absences; + +/** + * Redirects user to login page if it's not logged int + */ async function checkLogin() { localforage.getItem("logged_in").then(function (value) { // This code runs once the value has been loaded @@ -14,7 +17,10 @@ async function checkLogin() { }); } -// Set loading bar visibility +/** + * Sets visibility of the loading bar + * @param {boolean} state Desired visibility + */ function setLoading(state) { if (state) { $("#loading-bar").removeClass("hidden"); @@ -23,10 +29,14 @@ function setLoading(state) { } } -async function loadAbsences(force_refresh = false) { +/** + * Loads absences from API and displays them + * @param {boolean} forceRefresh If true, cached absences are ignored + */ +async function loadAbsences(forceRefresh = false) { setLoading(true); // Load required data - let promises_to_run = [ + let promisesToRun = [ localforage.getItem("username").then(function (value) { username = value; }), @@ -37,12 +47,12 @@ async function loadAbsences(force_refresh = false) { absences = value; }) ]; - await Promise.all(promises_to_run); + await Promise.all(promisesToRun); // If we don't have a list of absences, query it - if (absences === null || force_refresh) { + if (absences === null || forceRefresh) { try { let gsecInstance = new gsec(); - await gsecInstance.login(username, password); + await gsecInstance.login(username, password); let date = {}; date.from = $("#datepicker-from").val().split("."); date.till = $("#datepicker-to").val().split("."); @@ -91,11 +101,16 @@ async function loadAbsences(force_refresh = false) { } } +/** + * Display absences data - called by loadAbsences + */ function displayData() { absences.forEach(absence => { let li = document.createElement("li"); + + // dateString comes from bundle.js + let date_string = dateString.longFormatted(absence["date"]); - let date_string = dateString.longFormatted(absence["date"]); // javascript sucks - zakaj ob vsej svoji "preprostosti" ne morm met Date za key objecta!?!?'!!11~ let header = document.createElement("div"); header.className = "collapsible-header"; header.innerText = date_string; @@ -112,7 +127,7 @@ function displayData() { let subject_row = document.createElement("tr"); let subject_lesson_icon = document.createElement("td"); let subject_lesson_text = document.createElement("td"); - subject_lesson_text.innerText = S("lesson") + " " + lesson; + subject_lesson_text.innerText = `${S("lesson")} ${lesson}`; let subject_lesson_icon_i = document.createElement("i"); subject_lesson_icon_i.className = "material-icons"; @@ -151,6 +166,9 @@ function displayData() { }); } +/** + * Clear all displayed absences + */ function clearAbsences() { const table = document.getElementById("absences-col"); while (table.firstChild) { @@ -158,11 +176,17 @@ function clearAbsences() { } } +/** + * Force reloading of absences + */ function refreshAbsences() { clearAbsences(); loadAbsences(true); } +/** + * Setup date pickers (from date and to date) + */ function setupPickers() { // Setup pickers var date_object = new Date(); |