diff options
author | rstular <rok@stular.eu> | 2020-01-29 12:49:35 +0100 |
---|---|---|
committer | rstular <rok@stular.eu> | 2020-01-29 12:49:35 +0100 |
commit | a62819260d9c0d9bc0292f19be896c2c9b5ab422 (patch) | |
tree | 73794332dfdfc06d2ef00e11662a4238804da678 /js/initialize.js | |
download | beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar.gz beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar.bz2 beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar.lz beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar.xz beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.tar.zst beziapp-a62819260d9c0d9bc0292f19be896c2c9b5ab422.zip |
Diffstat (limited to '')
-rw-r--r-- | js/initialize.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/js/initialize.js b/js/initialize.js new file mode 100644 index 0000000..bfad5fc --- /dev/null +++ b/js/initialize.js @@ -0,0 +1,39 @@ +function setupStorage() { + promises_to_run = [ + localforage.setItem("logged_in", false), + localforage.setItem("username", ""), + localforage.setItem("password", ""), + localforage.setItem("profile", {}), + localforage.setItem("timetable", []), + localforage.setItem("teachers", []), + localforage.setItem("gradings", []), + localforage.setItem("grades", []), + localforage.setItem("absences", {}), + localforage.setItem("messages", {}) + ]; + + Promise.all(promises_to_run) + .then( + window.location.replace("/login.html") + ); +} + +localforage.getItem("logged_in") + .then( + function (value) { + // This code runs once the value has been loaded + // from the offline store. + if (value === null) { + setupStorage(); + } else if (value === false) { + window.location.replace("/login.html"); + } else { + window.location.replace("/pages/teachers.html"); + } + } + ).catch( + function (err) { + // This code runs if there were any errors + console.log(err); + } + ); |