From fd8e5e9ebec4b324b7cd713649b5cbd11a723a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Wed, 7 Feb 2024 18:31:01 +0100 Subject: [PATCH] Test JS --- assets/script.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/assets/script.js b/assets/script.js index 1f9e0f5..8c9bd9d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -1,4 +1,5 @@ let UserInfo = {}; + async function handleResponse(data, successMessage, failureMessage) { const statusMessageContainer = document.getElementById("statusMessageContainer"); @@ -67,7 +68,7 @@ async function handlePageResponse(data) { if (data.Page) { pageArea.innerHTML = data.Page; - if(data.PageLocation){ + if (data.PageLocation) { history.pushState({}, "", data.PageLocation); } } @@ -134,7 +135,7 @@ async function doPageAction(requestData, wantsReturn = false) { } } -async function initAjaxNavigationEvents(){ +async function initAjaxNavigationEvents() { const allLinks = document.querySelectorAll('.navsite_link, .navpage_link'); const pageLinks = document.querySelectorAll('.navpage_link'); @@ -168,25 +169,25 @@ async function initAjax() { await onPageLoad(); } -async function onPageLoad(){ +async function onPageLoad() { await restoreUserInfo(); let currentSite = localStorage.getItem("currentSite"); let currentPage = localStorage.getItem("currentPage"); - if(currentSite === "home" && currentPage === "settings"){ - if(document.getElementById("user-settings")){ + if (currentSite === "home" && currentPage === "settings") { + if (document.getElementById("user-settings")) { await populateUserInfoFields(UserInfo); } - if(document.getElementById("admin-settings")){ + if (document.getElementById("admin-settings")) { await listActivationCodes(true); await listUsers(true); } } - if(currentSite === "home" && currentPage === "account") { + if (currentSite === "home" && currentPage === "account") { await showDashboardGreeting(); } } -async function navigateTo(site, page){ +async function navigateTo(site, page) { const data = { action: "getPage", site: site, @@ -199,14 +200,14 @@ async function navigateTo(site, page){ }); } -async function softReload(){ +async function softReload() { let currentSite = localStorage.getItem("currentSite"); let currentPage = localStorage.getItem("currentPage"); await navigateTo(currentSite, currentPage); umami.track("softReload"); } -async function refreshNavbar(){ +async function refreshNavbar() { const data = { action: "getNavigation", }; @@ -334,10 +335,10 @@ async function populateUserInfoFields(userData) { document.getElementById("updateNewEmail").value = userData.Email || ""; } -async function restoreUserInfo(){ +async function restoreUserInfo() { for (let i = 0; i < localStorage.length; i++) { let key = localStorage.key(i); - if (key.startsWith("UserInfo_")){ + if (key.startsWith("UserInfo_")) { let keyClean = key.replace("UserInfo_", ""); UserInfo[keyClean] = localStorage.getItem(key); } @@ -348,15 +349,15 @@ async function getUserInfo() { const data = { action: "get_user_info", }; + const result = await doAction('/account', data, "User info retrieved Successfully!", "User info retrieval failed.", true); + + if (result && result.Status === "Success") { + result.UserInfo.forEach((value, index) => { + localStorage.setItem("UserInfo_" + index, value); + UserInfo[index] = value; + }); + } - doAction('/account', data, "User info retrieved Successfully!", "User info retrieval failed.", true) .then((result) => { - if (result && result.Status === "Success") { - result.UserInfo.forEach(function callback(value, index) { - localStorage.setItem("UserInfo_" + index, value); - UserInfo[index] = value; - }); - } - }); } //User settings end @@ -377,7 +378,7 @@ async function addActivationCodes() { }); } -async function listUsers(silent=false) { +async function listUsers(silent = false) { const data = { action: "list_users", }; @@ -390,7 +391,7 @@ async function listUsers(silent=false) { }); } -async function listActivationCodes(silent=false) { +async function listActivationCodes(silent = false) { const data = { action: "list_activation_codes", }; @@ -421,6 +422,7 @@ async function deleteActivationCode(activationCode) { await listActivationCodes(); umami.track("deleteActivationCode"); } + //Admin settings end if (document.readyState !== "loading") {