diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-05-20 18:31:15 +0200 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-05-20 18:31:15 +0200 |
commit | 70854102b66f8cac32e925398120c4f6731206d1 (patch) | |
tree | 3fd0aaa98d808df70f27971979a6b6498fef36be /assets | |
parent | fixed even mroe geeky operators (?) (diff) | |
download | beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar.gz beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar.bz2 beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar.lz beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar.xz beziapp-70854102b66f8cac32e925398120c4f6731206d1.tar.zst beziapp-70854102b66f8cac32e925398120c4f6731206d1.zip |
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/messaging.js | 90 | ||||
-rw-r--r-- | assets/pages-src/messaging.bvr | 1 |
2 files changed, 57 insertions, 34 deletions
diff --git a/assets/js/messaging.js b/assets/js/messaging.js index 34963a3..dba57ef 100644 --- a/assets/js/messaging.js +++ b/assets/js/messaging.js @@ -38,40 +38,62 @@ function htmlDecode(value) { // --------------------------------- // Try to fetch name:id directory -function loadDirectory() { - $.ajax({ - url: DIRECTORY_URL, - crossDomain: true, - - dataType: "json", - cache: false, - type: "GET", - - success: (data) => { - // If we were able to retrieve it, update the saved directory - localforage.setItem("directory", data); - directory = data; - // Populate autocomplete - populateAutocomplete(); - }, - - error: () => { - // Otherwise, try to retrieve stored directory - localforage.getItem("directory").then((stored_directory) => { - if (stored_directory === null) { - // If unable, set directory to null (so other functions know that we don't have it) - UIAlert( D("nameDirectoryNotSet"), "loadDirectory(): stored_directory === null" ); - directory = null; - // Disable send button - document.getElementById("msg-send").disabled = true; - } else { - directory = stored_directory; - // Populate autocomplete - populateAutocomplete(); - } - }); - } - }); +async function loadDirectory() { + $.ajax({ + url: DIRECTORY_URL, + crossDomain: true, + dataType: "json", + cache: false, + type: "GET", + success: async function (data) { + // If we were able to retrieve it, update the saved directory + let promises_to_run = [ + localforage.getItem("username").then((value) => { + username = value; + }), + localforage.getItem("password").then((value) => { + password = value; + }), + localforage.getItem("grades").then((value) => { + grades = value; + }) + ]; + await Promise.all(promises_to_run); + var gsecdata; + try { + let gsecInstance = new gsec(); + await gsecInstance.login(username, password); + gsecdata = await gsecInstance.fetchTeachersDirectory().catch( (err) => { + gsecErrorHandlerUI(err); + setLoading(false); + }); + } catch (err) { + gsecErrorHandlerUI(err); + setLoading(false); + } + directory = {...gsecdata, ...data }; + console.log(directory); + localforage.setItem("directory", directory); + // Populate autocomplete + populateAutocomplete(); + }, + error: () => { + // Otherwise, try to retrieve stored directory + localforage.getItem("directory").then((stored_directory) => { + if (stored_directory === null) { + // If unable, set directory to null (so other functions know that we don't have it) + UIAlert( D("nameDirectoryNotSet"), "loadDirectory(): stored_directory === null" ); + directory = null; + // Disable send button + document.getElementById("msg-send").disabled = true; + } else { + directory = stored_directory; + // Populate autocomplete + populateAutocomplete(); + } + }); + } + }); } function populateAutocomplete() { diff --git a/assets/pages-src/messaging.bvr b/assets/pages-src/messaging.bvr index 91d4ff7..abc7e79 100644 --- a/assets/pages-src/messaging.bvr +++ b/assets/pages-src/messaging.bvr @@ -24,6 +24,7 @@ <script src="/js/lang/bundle.js"></script> <script src="/js/lib/xss.js"></script> <script src="/js/lib/sjcl.js"></script> + <script src="/js/gsec.js"></script> <link rel="shortcut icon" type="image/png" href="/favicon.png" /> <script type="text/javascript" src="/js/messaging.js"></script> |