From fb879b1a2301e6bb43e783833867761108f434be Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Sun, 27 Jul 2025 22:19:08 +0000 Subject: [PATCH] button fixed --- public/index.html | 2 +- public/js/admin.js | 61 ++++++++++++++++++++++++++++++++-------------- public/js/ui.js | 16 ++++++------ 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/public/index.html b/public/index.html index 8666c27..8179d62 100644 --- a/public/index.html +++ b/public/index.html @@ -7,7 +7,6 @@ - @@ -454,5 +453,6 @@ } }); + \ No newline at end of file diff --git a/public/js/admin.js b/public/js/admin.js index 4c504b8..cf196d1 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -1,3 +1,18 @@ +// Ensure tab event listeners are attached after everything is defined +window.addEventListener('DOMContentLoaded', () => { + setTimeout(() => { + const tabButtons = document.querySelectorAll('#adminTabs button'); + tabButtons.forEach(button => { + button.addEventListener('click', (e) => { + e.preventDefault(); + const tabId = button.getAttribute('data-tab'); + if (tabId && typeof window.switchTab === 'function') { + window.switchTab(tabId); + } + }); + }); + }, 0); +}); // Global variables for admin functionality // --- Weeks input logic --- // Populate active week dropdown from weeksContainer @@ -104,8 +119,7 @@ window.switchTab = function switchTab(targetId) { // Highlight the active button document.querySelectorAll('#adminTabs button').forEach(btn => { - const onclick = btn.getAttribute('onclick'); - if (onclick && onclick.includes(targetId)) { + if (btn.getAttribute('data-tab') === targetId) { btn.classList.add('active'); } }); @@ -146,6 +160,19 @@ window.switchTab = function switchTab(targetId) { loadUserDropdowns(); break; } + // Attach admin tab event listeners after switchTab is defined + window.addEventListener('DOMContentLoaded', () => { + const tabButtons = document.querySelectorAll('#adminTabs button'); + tabButtons.forEach(button => { + button.addEventListener('click', (e) => { + e.preventDefault(); + const tabId = button.getAttribute('data-tab'); + if (tabId) { + window.switchTab(tabId); + } + }); + }); + }); }; // Load users from server @@ -753,22 +780,20 @@ function populatePasswordUserDropdown() { // Add event listeners for admin tabs as backup to onclick window.addEventListener('DOMContentLoaded', () => { - setTimeout(() => { - const tabButtons = document.querySelectorAll('#adminTabs button'); - tabButtons.forEach(button => { - button.addEventListener('click', (e) => { - e.preventDefault(); - const tabId = button.getAttribute('data-tab'); - if (tabId) { - console.log('Tab clicked:', tabId); - if (typeof window.switchTab === 'function') { - window.switchTab(tabId); - } else { - console.error('switchTab function not available'); - } + const tabButtons = document.querySelectorAll('#adminTabs button'); + tabButtons.forEach(button => { + button.addEventListener('click', (e) => { + e.preventDefault(); + const tabId = button.getAttribute('data-tab'); + if (tabId) { + console.log('Tab clicked:', tabId); + if (typeof window.switchTab === 'function') { + window.switchTab(tabId); + } else { + console.error('switchTab function not available'); } - }); + } }); - console.log('✅ Tab event listeners added to', tabButtons.length, 'buttons'); - }, 500); + }); + console.log('✅ Tab event listeners added to', tabButtons.length, 'buttons'); }); \ No newline at end of file diff --git a/public/js/ui.js b/public/js/ui.js index fb7bb78..6b3042c 100644 --- a/public/js/ui.js +++ b/public/js/ui.js @@ -99,15 +99,13 @@ function showAdmin() { }); // Set default tab to tabWords and enable tab buttons - setTimeout(() => { - document.querySelectorAll('#adminTabs button').forEach(btn => btn.disabled = false); - if (typeof window.switchTab === 'function') { - window.switchTab("tabWords"); - console.log("✅ Default tab set to tabWords"); - } else { - console.error("switchTab function not available"); - } - }, 100); + document.querySelectorAll('#adminTabs button').forEach(btn => btn.disabled = false); + if (typeof window.switchTab === 'function') { + window.switchTab("tabWords"); + console.log("✅ Default tab set to tabWords"); + } else { + console.error("switchTab function not available"); + } } else { console.error("Admin panel not found"); }