diff --git a/public/auth.js b/public/auth.js index ddf5c48..cddd1ec 100644 --- a/public/auth.js +++ b/public/auth.js @@ -83,11 +83,84 @@ function showMainInterface() { document.getElementById('current-user').textContent = userInfo; - // 👇 СОЗДАЕМ НАВИГАЦИЮ ПОСЛЕ УСТАНОВКИ ПОЛЬЗОВАТЕЛЯ 👇 - createUserNavigation(); + // 👇 ПЕРЕЗАГРУЗКА ВСЕХ СКРИПТОВ ПОСЛЕ АВТОРИЗАЦИИ 👇 + reloadAllScripts(); +} - document.getElementById('tasks-controls').style.display = 'block'; +// Функция для перезагрузки всех скриптов +function reloadAllScripts() { + console.log('🔄 Перезагрузка всех скриптов после авторизации...'); + // Список скриптов для перезагрузки (в правильном порядке) + const scriptsToReload = [ + 'users.js', + 'ui.js', + 'signature.js', + 'tasks.js', + 'kanban.js', + 'files.js', + 'profile.js', + 'time-selector.js', + 'openTaskChat.js', + 'tasks_files.js', + 'navbar.js', + 'chat-ui.js', + 'document-fields.js', + 'main.js' + ]; + + // Удаляем существующие скрипты + scriptsToReload.forEach(src => { + const existingScripts = document.querySelectorAll(`script[src="${src}"]`); + existingScripts.forEach(script => script.remove()); + }); + + // Загружаем скрипты последовательно + loadScriptsSequentially(scriptsToReload, 0); +} + +function loadScriptsSequentially(scripts, index) { + if (index >= scripts.length) { + console.log('✅ Все скрипты успешно перезагружены'); + + // Инициализация после загрузки всех скриптов + setTimeout(() => { + initializeAfterReload(); + }, 100); + + return; + } + + const script = document.createElement('script'); + script.src = scripts[index]; + script.onload = () => { + console.log(`✅ Загружен: ${scripts[index]}`); + loadScriptsSequentially(scripts, index + 1); + }; + script.onerror = (error) => { + console.error(`❌ Ошибка загрузки ${scripts[index]}:`, error); + loadScriptsSequentially(scripts, index + 1); + }; + + document.head.appendChild(script); +} + +function initializeAfterReload() { + console.log('🚀 Инициализация интерфейса после перезагрузки...'); + + // Создаем навигацию + if (typeof createNavigation === 'function') { + createNavigation(); + } else { + console.warn('⚠️ createNavigation не найдена, пробуем позже...'); + setTimeout(() => { + if (typeof createNavigation === 'function') { + createNavigation(); + } + }, 200); + } + + // Настраиваем отображение чекбокса удаленных задач const showDeletedLabel = document.querySelector('.show-deleted-label'); if (showDeletedLabel) { if (currentUser.role === 'admin') { @@ -97,30 +170,36 @@ function showMainInterface() { } } - loadUsers(); - loadTasks(); - loadActivityLogs(); - showSection('tasks'); - loadKanbanTasks(); + // Загружаем данные + if (typeof loadUsers === 'function') { + loadUsers(); + } - showingTasksWithoutDate = false; + if (typeof loadTasks === 'function') { + loadTasks(); + } + + if (typeof loadActivityLogs === 'function') { + loadActivityLogs(); + } + + if (typeof loadKanbanTasks === 'function') { + loadKanbanTasks(); + } + + // Показываем секцию задач + if (typeof showSection === 'function') { + showSection('tasks'); + } + + // Сбрасываем состояние кнопки задач без даты + window.showingTasksWithoutDate = false; const btn = document.getElementById('tasks-no-date-btn'); if (btn) btn.classList.remove('active'); -} -// Новая функция для создания навигации -function createUserNavigation() { - if (typeof createNavigation === 'function') { - console.log('🔄 Создание навигации для пользователя:', currentUser.role); - createNavigation(); - } else { - console.warn('⚠️ Функция createNavigation не найдена'); - // Если функция не загружена, пробуем еще раз через небольшую задержку - setTimeout(() => { - if (typeof createNavigation === 'function') { - console.log('🔄 Повторная попытка создания навигации'); - createNavigation(); - } - }, 100); + + // Переустанавливаем обработчики событий + if (typeof setupEventListeners === 'function') { + setupEventListeners(); } } @@ -172,6 +251,13 @@ async function logout() { await fetch('/api/logout', { method: 'POST' }); currentUser = null; showLoginInterface(); + + // Очищаем интерфейс + document.querySelector('.container').style.display = 'none'; + document.querySelectorAll('.section').forEach(section => { + section.classList.remove('active'); + }); + } catch (error) { console.error('Ошибка выхода:', error); } diff --git a/public/index.html b/public/index.html index 9c97028..3a9f91d 100644 --- a/public/index.html +++ b/public/index.html @@ -6,24 +6,29 @@ School CRM - Управление задачами + + - - + + + --> + +