const i18n = { kz: { appTitle: 'ЖС Платформасы', subtitle: 'Қазақтелеком АҚ — 2026 жылғы ӨҚ шаралар жоспары', totalEvents: 'Жоспардағы шаралар', doneEvents: 'Орындалды', inProgress: 'Жұмыста', delayed: 'Кешігіп тұр', notStarted: 'Басталмады', allSections: 'Барлық бөлімдер', allBranches: 'Барлық филиалдар', allStatuses: 'Барлық статус', statusDone: 'Орындалды', statusInProgress: 'Жұмыста', statusDelayed: 'Кешігіп тұр', statusNotStarted: 'Басталмады', addEvent: '+ Шара', exportReport: 'Есепті шығару', history: 'Есептер тарихы', name: 'Атауы', section: 'Бөлім', branch: 'Филиал', responsible: 'Жауаптылар', due: 'Мерзімі', finishForm: 'Аяқтау формасы', status: 'Статус', progress: 'Прогресс', actions: 'Әрекеттер', date: 'Күні', period: 'Кезеңі', format: 'Форматы', who: 'Кім құраған', statusSent: 'Жіберу статусы', back: 'Артқа', nameKz: 'Атауы (Қазақша)', nameRu: 'Атауы (Орысша)', description: 'Сипаттамасы', done: 'Аяқталу күні', comment: 'Пікір', cancel: 'Бас тарту', save: 'Сақтау', year2026: '2026', q12026: '2026 Q1', q22026: '2026 Q2', q32026: '2026 Q3', q42026: '2026 Q4', excel: 'Excel', pdf: 'PDF', html: 'HTML', allData: 'Барлық деректер', delayedOnly: 'Тек кешігендер', generate: 'Қалыптастыру', notSent: 'Жіберілмеген', sent: 'Жіберілді', sec1: 'I. Адамдар. Қауіпсіздік мәдениеті', sec2: 'II. Жабдықтар қауіпсіздігі', sec3: 'III. Апаттар мен ТЖ-ға дайындық', sec4: 'IV. ПБ бойынша ақпараттық жұмыс', sec5: 'V. ИИ және цифрландыру' }, ru: { appTitle: 'Платформа ПБ', subtitle: 'АО «Казахтелеком» — План мероприятий по ПБ на 2026 год', totalEvents: 'Всего мероприятий', doneEvents: 'Выполнено', inProgress: 'В работе', delayed: 'Задержано', notStarted: 'Не начато', allSections: 'Все секции', allBranches: 'Все филиалы', allStatuses: 'Все статусы', statusDone: 'Выполнено', statusInProgress: 'В работе', statusDelayed: 'Задержано', statusNotStarted: 'Не начато', addEvent: '+ Мероприятие', exportReport: 'Выгрузить отчёт', history: 'История отчётов', name: 'Название', section: 'Секция', branch: 'Филиал', responsible: 'Ответственные', due: 'Срок', finishForm: 'Форма завершения', status: 'Статус', progress: 'Прогресс', actions: 'Действия', date: 'Дата', period: 'Период', format: 'Формат', who: 'Кто сформировал', statusSent: 'Статус отправки', back: 'Назад', nameKz: 'Название (Қазақша)', nameRu: 'Название (Русский)', description: 'Описание', done: 'Дата завершения', comment: 'Комментарий', cancel: 'Отмена', save: 'Сохранить', year2026: '2026', q12026: 'Q1 2026', q22026: 'Q2 2026', q32026: 'Q3 2026', q42026: 'Q4 2026', excel: 'Excel', pdf: 'PDF', html: 'HTML', allData: 'Все данные', delayedOnly: 'Только задержанные', generate: 'Сформировать', notSent: 'Не отправлен', sent: 'Отправлен', sec1: 'I. Люди. Культура безопасности', sec2: 'II. Безопасность оборудования', sec3: 'III. Аварии и ЧС', sec4: 'IV. ПБ: информационная работа', sec5: 'V. ИИ и цифровизация' } }; const SECTION_NAMES = { 1: 'sec1', 2: 'sec2', 3: 'sec3', 4: 'sec4', 5: 'sec5' }; let currentLang = 'kz'; let allEvents = []; let allReports = []; async function api(path, method = 'GET', body) { const opts = { method, headers: { 'Content-Type': 'application/json' } }; if (body) opts.body = JSON.stringify(body); const res = await fetch(path, opts); return res.json(); } async function loadData() { allEvents = await api('/api/events'); allReports = await api('/api/reports'); renderDashboard(); renderHistory(); } function t(key) { return i18n[currentLang][key] || key; } function updateI18n() { document.querySelectorAll('[data-i18n]').forEach(el => { el.textContent = t(el.getAttribute('data-i18n')); }); } function formatDate(d) { if (!d) return '—'; const dt = new Date(d); return dt.toLocaleDateString(currentLang === 'kz' ? 'kk-KZ' : 'ru-RU', { year: 'numeric', month: '2-digit', day: '2-digit' }); } function renderDashboard() { const sections = [...new Set(allEvents.map(e => e.sec))].sort((a, b) => a - b); const filterSection = document.getElementById('filter-section'); const prevVal = filterSection.value; filterSection.innerHTML = '' + sections.map(s => '').join(''); filterSection.value = prevVal; const total = allEvents.length; const done = allEvents.filter(e => e.s === 'done').length; const inProg = allEvents.filter(e => e.s === 'in_progress').length; const delayed = allEvents.filter(e => e.s === 'delayed').length; const notSt = allEvents.filter(e => e.s === 'not_started').length; document.getElementById('kpi-total').textContent = total; document.getElementById('kpi-done').textContent = done; document.getElementById('kpi-progress').textContent = inProg; document.getElementById('kpi-delayed').textContent = delayed; const secVal = filterSection.value; const sVal = document.getElementById('filter-status').value; let filtered = allEvents; if (secVal) filtered = filtered.filter(e => e.sec == secVal); if (sVal) filtered = filtered.filter(e => e.s === sVal); const tbody = document.getElementById('events-tbody'); tbody.innerHTML = ''; let currentSec = null; filtered.forEach(e => { if (e.sec !== currentSec) { currentSec = e.sec; const secName = t(SECTION_NAMES[e.sec] || 'sec' + e.sec); tbody.innerHTML += '' + secName + ''; } const name = currentLang === 'kz' ? e.dname.kz : e.dname.ru; const statusKey = 'status' + e.s.charAt(0).toUpperCase() + e.s.slice(1).replace('_', ''); const statusClass = 'status-' + e.s; tbody.innerHTML += '' + '' + name + '' + '' + e.r.replace(/\n/g, '
') + '' + '' + formatDate(e.due) + '' + '' + (e.finishForm || '—') + '' + '' + t(statusKey) + '' + '
' + e.p + '%' + '' + ' ' + '' + '' + ''; }); } function renderHistory() { const tbody = document.getElementById('reports-tbody'); tbody.innerHTML = ''; allReports.forEach(r => { const sentChip = r.statusSent === 'sent' ? 'status-done' : 'status-not_started'; const sentLabel = t(r.statusSent === 'sent' ? 'sent' : 'notSent'); tbody.innerHTML += '' + '' + formatDate(r.createdAt) + '' + '' + r.period + '' + '' + r.format + '' + '' + (r.who || '—') + '' + '' + sentLabel + '' + '' + ' ' + '' + '' + ''; }); } document.querySelectorAll('.lang-btn').forEach(btn => { btn.addEventListener('click', () => { currentLang = btn.dataset.lang; document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); btn.classList.add('active'); updateI18n(); renderDashboard(); renderHistory(); }); }); document.getElementById('filter-section').addEventListener('change', renderDashboard); document.getElementById('filter-status').addEventListener('change', renderDashboard); document.getElementById('btn-add-event').addEventListener('click', () => { document.getElementById('event-form').reset(); document.getElementById('event-id').value = ''; document.getElementById('event-modal-title').textContent = t('addEvent'); document.getElementById('event-modal').classList.add('open'); }); function editEvent(id) { const e = allEvents.find(ev => ev.id === id); if (!e) return; document.getElementById('event-form').reset(); document.getElementById('event-id').value = e.id; document.getElementById('name-kz').value = e.dname.kz; document.getElementById('name-ru').value = e.dname.ru; document.getElementById('sec').value = e.sec; document.getElementById('t').value = e.t; document.getElementById('r').value = e.r; document.getElementById('due').value = e.due; document.getElementById('done').value = e.done || ''; document.getElementById('s').value = e.s; document.getElementById('p').value = e.p; document.getElementById('finish-form').value = e.finishForm || ''; document.getElementById('ai').value = e.ai; document.getElementById('event-modal-title').textContent = e.dname[currentLang]; document.getElementById('event-modal').classList.add('open'); } document.getElementById('event-form').addEventListener('submit', async (e) => { e.preventDefault(); const id = document.getElementById('event-id').value; const data = { dname: { kz: document.getElementById('name-kz').value, ru: document.getElementById('name-ru').value }, sec: parseInt(document.getElementById('sec').value), b: 0, t: document.getElementById('t').value, r: document.getElementById('r').value, due: document.getElementById('due').value, done: document.getElementById('done').value || null, s: document.getElementById('s').value, p: parseInt(document.getElementById('p').value) || 0, finishForm: document.getElementById('finish-form').value, ai: document.getElementById('ai').value }; if (id) { await api('/api/events/' + id, 'PUT', data); } else { await api('/api/events', 'POST', data); } closeModal('event-modal'); loadData(); }); function deleteEvent(id) { if (!confirm(t('cancel'))) return; api('/api/events/' + id, 'DELETE').then(() => loadData()); } document.getElementById('btn-export').addEventListener('click', () => { document.getElementById('export-modal').classList.add('open'); }); document.getElementById('btn-generate-report').addEventListener('click', async () => { const data = { period: document.getElementById('report-period').value, format: document.getElementById('report-format').value, scope: document.getElementById('report-scope').value, who: 'Аналитик' }; await api('/api/reports', 'POST', data); closeModal('export-modal'); loadData(); }); function downloadReport(id) { const r = allReports.find(rep => rep.id === id); if (!r) return; alert(t('exportReport') + ': ' + r.period + ' (' + r.format + ')'); } function deleteReport(id) { if (!confirm(t('cancel'))) return; api('/api/reports/' + id, 'DELETE').then(() => loadData()); } document.getElementById('btn-history').addEventListener('click', () => { document.getElementById('view-dashboard').classList.remove('active'); document.getElementById('view-history').classList.add('active'); }); document.getElementById('btn-back-dashboard').addEventListener('click', () => { document.getElementById('view-history').classList.remove('active'); document.getElementById('view-dashboard').classList.add('active'); }); function closeModal(id) { document.getElementById(id).classList.remove('open'); } loadData(); updateI18n();