diff options
author | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-10 19:54:09 +0100 |
---|---|---|
committer | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-10 19:54:09 +0100 |
commit | 23b17dda901e5df3b9c73fc4d9129243cbf60a15 (patch) | |
tree | 9d9003929912ad999ca540a407ab486dfa40fbe7 /js/setup-storage.js | |
parent | 1.0.12-beta: podpora za jezike (diff) | |
download | beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.gz beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.bz2 beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.lz beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.xz beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.zst beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.zip |
Diffstat (limited to '')
-rw-r--r-- | js/setup-storage.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/js/setup-storage.js b/js/setup-storage.js new file mode 100644 index 0000000..8a6604c --- /dev/null +++ b/js/setup-storage.js @@ -0,0 +1,36 @@ +async function setupStorage(force = false) { + let logged_in, setup_promises; + promises_check_if_already_installed = [ + localforage.getItem("logged_in").then( function(val) { + console.log("[setupStorage] logged in status: "+val); + logged_in = val; + }) + ]; + await Promise.all(promises_check_if_already_installed); + let promises_update = [ + localforage.setItem("profile", {}), + localforage.setItem("timetable", []), + localforage.setItem("teachers", []), + localforage.setItem("gradings", []), + localforage.setItem("grades", []), + localforage.setItem("absences", {}), + localforage.setItem("messages", {}), + localforage.setItem("directory", {}), + localforage.setItem("meals", {}) + ]; + if(logged_in && force == false) { // torej, če je že bila prijava narejena, ne posodobi backwards-compatible vrednosti (username, password,...) + await Promise.all(promises_update); + console.log("[setupStorage] user logged in: only updated"); + } else { + let promises_first_install = [ + localforage.setItem("logged_in", false), + localforage.setItem("username", ""), + localforage.setItem("password", ""), + localforage.setItem("chosenLang", "en") + ]; + await localforage.clear(); + await Promises.all(promises_first_install); + console.log("[setupStorage] user not logged in: set up whole database"); + } +} + |