summaryrefslogtreecommitdiffstats
path: root/js/initialize.js
diff options
context:
space:
mode:
authorrstular <rok@stular.eu>2020-02-17 15:15:55 +0100
committerrstular <rok@stular.eu>2020-02-17 15:15:55 +0100
commitfefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94 (patch)
tree803184e820a5002418a19ce4685d4621b7910b76 /js/initialize.js
parentneki sm delu, sam ne do konca (diff)
downloadbeziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar.gz
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar.bz2
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar.lz
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar.xz
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.tar.zst
beziapp-fefeee7ccf1b6fb6a133c8b9c5eb07b1760c2d94.zip
Diffstat (limited to 'js/initialize.js')
-rw-r--r--js/initialize.js36
1 files changed, 20 insertions, 16 deletions
diff --git a/js/initialize.js b/js/initialize.js
index 2023921..ca29e2f 100644
--- a/js/initialize.js
+++ b/js/initialize.js
@@ -1,15 +1,13 @@
function getUrlParameter(sParam) {
- var sPageURL = window.location.search.substring(1),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
- }
+ const url_params = new URLSearchParams(window.location.search);
+ const found_param = url_params.get(sParam);
+ if (found_param === null) {
+ return ""
+ } else {
+ return found_param
}
-};
+}
+
function setupStorage() {
promises_to_run = [
localforage.setItem("logged_in", false),
@@ -21,7 +19,8 @@ function setupStorage() {
localforage.setItem("gradings", []),
localforage.setItem("grades", []),
localforage.setItem("absences", {}),
- localforage.setItem("messages", {})
+ localforage.setItem("messages", {}),
+ localforage.setItem("directory", {})
];
Promise.all(promises_to_run)
@@ -36,15 +35,20 @@ localforage.getItem("logged_in")
// This code runs once the value has been loaded
// from the offline store.
if (value === null) {
+ // Setup the storage if it doesn't exist
setupStorage();
} else if (value === false) {
+ // If storage exists, but user isn't logged in, redirect to login
window.location.replace("/login.html");
} else {
- if(getUrlParameter("m")) {
- window.location.replace("pages/messaging.html?"+getUrlParameter("m"));
- } else {
- window.location.replace("/pages/timetable.html");
- }
+ // User is logged in, execute appropriate action
+
+ if (getUrlParameter("m") !== "") {
+ window.location.replace("/pages/messaging.html?m=" + getUrlParameter("m"));
+ } else {
+ window.location.replace("/pages/timetable.html");
+ }
+
}
}
).catch(