This commit is contained in:
Bruno Rybársky 2024-02-07 18:31:01 +01:00
parent c4c9e021e4
commit fd8e5e9ebe

@ -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);
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) {
result.UserInfo.forEach((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") {