From 295afbc82d1d39551cec58447801bea5f9192a98 Mon Sep 17 00:00:00 2001
From: Sammy Ndabo
Date: Sat, 21 Dec 2024 20:33:19 +0200
Subject: [PATCH] ENH: implement the themes switcher logic
---
views/default3.handlebars | 89 +++++++++++++++++++++++++++++++++++++--
1 file changed, 85 insertions(+), 4 deletions(-)
diff --git a/views/default3.handlebars b/views/default3.handlebars
index 1ab401da..ea8233d3 100644
--- a/views/default3.handlebars
+++ b/views/default3.handlebars
@@ -597,6 +597,7 @@
Delete account
Create login token
+ Switch theme
@@ -1111,7 +1112,7 @@
@@ -14183,6 +14184,86 @@
}
}
+ function account_showThemesSwitcher() {
+ if (xxdialogMode) return false;
+ var themes = [
+ { value: "default", label: "Default" },
+ { value: "cerulean", label: "Cerulean" },
+ { value: "cosmo", label: "Cosmo" },
+ { value: "cyborg", label: "Cyborg" },
+ { value: "darkly", label: "Darkly" },
+ { value: "flatly", label: "Flatly" },
+ { value: "journal", label: "Journal" },
+ { value: "litera", label: "Litera" },
+ { value: "lumen", label: "Lumen" },
+ { value: "lux", label: "Lux" },
+ { value: "materia", label: "Materia" },
+ { value: "minty", label: "Minty" },
+ { value: "morph", label: "Morph" },
+ { value: "pulse", label: "Pulse" },
+ { value: "sandstone", label: "Sandstone" },
+ { value: "simplex", label: "Simplex" },
+ { value: "sketchy", label: "Sketchy" },
+ { value: "solar", label: "Solar" },
+ { value: "spacelab", label: "Spacelab" },
+ { value: "united", label: "United" },
+ { value: "vapor", label: "Vapor" },
+ { value: "yeti", label: "Yeti" },
+ { value: "zephyr", label: "Zephyr" }
+ ];
+ var currentTheme = getstore('theme') || 'default';
+ var lastThemes = JSON.parse(getstore('lastThemes') || '[]');
+
+ var x = '
';
+ x += '
';
+
+ setModalContent('xxAddAgent', 'Switch Theme', x);
+ showModal('xxAddAgentModal', 'idx_dlgOkButton');
+ return false;
+ }
+
+ function account_switchThemeEx() {
+ var themeSwitcher = document.getElementById("theme-switcher");
+ const selectedTheme = themeSwitcher.value;
+ const safeTheme = encodeURIComponent(selectedTheme);
+ var themeStylesheet = document.getElementById("theme-stylesheet");
+ var newThemeStylesheet = `styles/themes/${safeTheme}/bootstrap.min.css`;
+ themeStylesheet.href = newThemeStylesheet;
+
+ // Save selected theme
+ putstore('theme', selectedTheme);
+
+ // Update last 4 themes selected
+ var lastThemes = JSON.parse(getstore('lastThemes') || '[]');
+ if (!lastThemes.includes(selectedTheme)) {
+ if (lastThemes.length >= 4) {
+ lastThemes.pop();
+ }
+ lastThemes.unshift(selectedTheme);
+ } else {
+ lastThemes = lastThemes.filter(theme => theme !== selectedTheme);
+ lastThemes.unshift(selectedTheme);
+ }
+ putstore('lastThemes', JSON.stringify(lastThemes));
+ }
+
function account_createMesh() {
// Check if we are disallowed from creating a device group
if ((userinfo.siteadmin != 0xFFFFFFFF) && ((userinfo.siteadmin & 64) != 0)) {
@@ -20600,4 +20681,4 @@