From 8ff87ec2a8957bf23889dae201099b43227439ec Mon Sep 17 00:00:00 2001 From: kalugin66 Date: Sat, 7 Feb 2026 00:56:09 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/admin-script.js | 88 ++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 30 deletions(-) diff --git a/public/admin-script.js b/public/admin-script.js index 98e8afe..db50039 100644 --- a/public/admin-script.js +++ b/public/admin-script.js @@ -119,6 +119,8 @@ async function logout() { } function showAdminSection(sectionName) { + console.log('showAdminSection called with:', sectionName); + // Убираем активный класс у всех вкладок document.querySelectorAll('.admin-tab').forEach(tab => { tab.classList.remove('active'); @@ -130,48 +132,74 @@ function showAdminSection(sectionName) { }); // Находим и активируем соответствующую вкладку - const tab = document.querySelector(`.admin-tab[onclick*="showAdminSection('${sectionName}')"]`); - if (tab) { - tab.classList.add('active'); - } else { - // Альтернативный поиск если выше не сработал - const tabs = document.querySelectorAll('.admin-tab'); - tabs.forEach(t => { - if (t.textContent.toLowerCase().includes(sectionName)) { - t.classList.add('active'); + const tabs = document.querySelectorAll('.admin-tab'); + let tabFound = false; + + tabs.forEach(tab => { + const onclick = tab.getAttribute('onclick'); + if (onclick && onclick.includes(`showAdminSection('${sectionName}')`)) { + tab.classList.add('active'); + tabFound = true; + } + }); + + // Если не нашли по onclick, ищем по тексту + if (!tabFound) { + tabs.forEach(tab => { + const tabText = tab.textContent.toLowerCase(); + if (tabText.includes(sectionName.toLowerCase())) { + tab.classList.add('active'); } }); } // Активируем соответствующую секцию - const section = document.getElementById(`admin-${sectionName}`); + const sectionId = `admin-${sectionName}-section`; + let section = document.getElementById(sectionId); + + // Если не нашли по такому ID, пробуем другие варианты + if (!section) { + if (sectionName === 'users') { + section = document.getElementById('admin-users-section'); + } else if (sectionName === 'dashboard') { + section = document.getElementById('admin-dashboard'); + } else if (sectionName === 'stats') { + section = document.getElementById('admin-stats-section'); + } else { + // Пробуем найти по частичному совпадению + const sections = document.querySelectorAll('.admin-section'); + sections.forEach(s => { + if (s.id.includes(sectionName)) { + section = s; + } + }); + } + } + if (section) { section.classList.add('active'); + console.log('Activated section:', section.id); } else { - // Если секция не найдена по ID, ищем по другому шаблону - const sections = document.querySelectorAll('.admin-section'); - sections.forEach(s => { - if (s.id.includes(sectionName)) { - s.classList.add('active'); - } - }); + console.error('Section not found for:', sectionName); } // Загружаем данные для активной секции - if (sectionName === 'users') { - loadUsers(); - } else if (sectionName === 'dashboard') { - if (typeof renderDashboard === 'function') { - renderDashboard(); + setTimeout(() => { + if (sectionName === 'users') { + console.log('Loading users...'); + loadUsers(); + } else if (sectionName === 'dashboard') { + console.log('Loading dashboard...'); + if (typeof renderDashboard === 'function') { + renderDashboard(); + } + } else if (sectionName === 'stats') { + console.log('Loading stats...'); + if (typeof renderStatsSection === 'function') { + renderStatsSection(); + } } - } else if (sectionName === 'stats') { - if (typeof renderStatsSection === 'function') { - renderStatsSection(); - } else if (typeof checkAndRenderStats === 'function') { - // Альтернативный вызов если функция переименована - checkAndRenderStats(); - } - } + }, 50); } async function loadUsers() {