// JavaScript для управления категориями class CategoryManager { constructor() { this.warehouse = new WarehouseManager(); this.categories = []; this.currentCategory = null; this.init(); } async init() { try { // Проверяем авторизацию if (!auth.isUserAuthenticated()) { console.log('Пользователь не авторизован, перенаправление на login.html'); window.location.href = '../login.html'; return; } // Проверяем права доступа if (!auth.hasRole('admin')) { console.log('Пользователь не имеет прав администратора'); auth.showNotification('Недостаточно прав для доступа к этой странице', 'danger'); window.location.href = '../index.html'; return; } console.log('Инициализация управления категориями для администратора:', auth.getCurrentUser()?.name); // Загружаем данные await this.loadCategories(); this.updateStatistics(); this.renderCategoriesTable(); this.bindEvents(); // Загружаем категории в выпадающее меню await this.loadCategoriesDropdown(); this.updateUserInfo(); } catch (error) { console.error('Ошибка инициализации:', error); auth.showNotification('Ошибка загрузки данных', 'danger'); } } // Загрузка категорий async loadCategories() { this.categories = await this.warehouse.getCategories(); } // Обновление статистики updateStatistics() { const totalCategories = this.categories.length; const activeCategories = this.categories.filter(cat => cat.active).length; const emptyCategories = this.categories.filter(cat => cat.itemCount === 0).length; // Получаем общее количество позиций const allItems = this.warehouse.getAllItemsSync(); const totalItems = allItems.length; $('#totalCategories').text(totalCategories); $('#totalItems').text(totalItems); $('#activeCategories').text(activeCategories); $('#emptyCategories').text(emptyCategories); } // Рендеринг таблицы категорий renderCategoriesTable() { const tbody = $('#categoriesTable tbody'); tbody.empty(); if (this.categories.length === 0) { tbody.append(`
Добавьте первую категорию для начала работы
${category.icon || 'fas fa-tag'}