178 lines
28 KiB
HTML
178 lines
28 KiB
HTML
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Беличья нора — админка</title>
|
|
<style>
|
|
:root { color-scheme: light; font-family: "Trebuchet MS", ui-sans-serif, sans-serif; background: #f4f1eb; color: #292725; --ink:#292725; --muted:#625d57; --line:#ded9d1; --paper:#fffdfa; --accent:#9a542e; --danger:#8e3630; --focus:#9a542e; }
|
|
* { box-sizing: border-box; }
|
|
body { margin: 0; background: #f4f1eb; color: var(--ink); }
|
|
main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 64px; }
|
|
h1 { margin: 0; font: 500 clamp(2rem, 4vw, 3.25rem)/1 Georgia, "Times New Roman", serif; letter-spacing: -.035em; }
|
|
h2 { margin: 0 0 8px; font: 500 2rem/1.1 Georgia, "Times New Roman", serif; }
|
|
.muted, .intro { color: var(--muted); }
|
|
.intro { max-width: 520px; margin: 10px 0 0; line-height: 1.55; }
|
|
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
|
|
.record-count { color: var(--muted); font-size: .85rem; white-space: nowrap; }
|
|
.tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 22px 0 4px; border-bottom: 1px solid var(--line); }
|
|
.tab { min-height: 36px; padding: 7px 13px; border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--muted); font-size: .84rem; }
|
|
.tab:hover { border-color: #cfc8bf; background: #fffaf3; color: var(--ink); }
|
|
.tab[aria-selected="true"] { border-color: var(--ink); background: var(--ink); color: #fffdfa; }
|
|
.auth-view { width: min(480px, 100%); margin: 14vh auto 0; padding: 34px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); box-shadow: 0 12px 35px #3b302414; }
|
|
.auth-view p { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
|
|
.auth-form { display: flex; gap: 10px; }
|
|
.auth-form input { flex: 1; min-width: 0; }
|
|
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 20px 0; }
|
|
.control-group { display: grid; gap: 6px; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }
|
|
input, select, button { min-height: 42px; border-radius: 7px; font: inherit; }
|
|
input, select { border: 1px solid #cbc5bc; background: var(--paper); color: var(--ink); padding: 9px 12px; outline: none; }
|
|
input { min-width: 245px; }
|
|
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #b86f3b22; }
|
|
button { border: 1px solid var(--ink); padding: 9px 16px; background: var(--ink); color: #fffdfa; cursor: pointer; font-weight: 650; transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out; }
|
|
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
|
|
button:hover { background: #45413d; }
|
|
button:disabled { cursor: wait; opacity: .55; }
|
|
.error { min-height: 22px; margin: 0 0 12px; color: var(--danger); font-size: .9rem; }
|
|
.hidden { display: none !important; }
|
|
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); box-shadow: 0 12px 35px #3b302414; }
|
|
table { width: 100%; min-width: 1240px; border-collapse: separate; border-spacing: 0; }
|
|
th, td { padding: 15px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid #ebe7e0; }
|
|
th { position: sticky; top: 0; z-index: 1; background: #f8f5f0; color: #69635d; font-size: .72rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
|
|
tbody tr:last-child td { border-bottom: 0; }
|
|
tbody tr:hover td { background: #fff8ef; }
|
|
td { color: #3d3935; font-size: .91rem; line-height: 1.45; }
|
|
.id-cell { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
.person { min-width: 155px; }
|
|
.person strong { display: block; color: var(--ink); font-weight: 700; }
|
|
.person span { display: block; margin-top: 2px; color: var(--muted); font-size: .82rem; }
|
|
.mode { color: #8f4d26; font-size: .78rem; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }
|
|
.photos { display: flex; flex-wrap: wrap; gap: 5px; max-width: 300px; }
|
|
.photos button { width: 78px; height: 58px; min-height: 0; padding: 0; overflow: hidden; border: 0; border-radius: 5px; background: #e8e2d9; }
|
|
.photos img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
.photos button:hover { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
.message { max-width: 460px; margin: 0; white-space: pre-wrap; color: #514b45; font: inherit; font-size: .84rem; line-height: 1.5; }
|
|
.delete { min-height: 34px; padding: 6px 10px; border-color: #d9b8b2; background: transparent; color: var(--danger); font-size: .82rem; }
|
|
.delete:hover { border-color: var(--danger); background: #fff1ef; color: var(--danger); }
|
|
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
|
|
.admin-section { padding-top: 28px; }
|
|
.applications { padding-top: 4px; }
|
|
.application-layout { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(380px, 1.2fr); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--paper); }
|
|
.application-list { border-right: 1px solid var(--line); }.application-item { display: block; width: 100%; min-height: 76px; padding: 15px 16px; border: 0; border-bottom: 1px solid #ebe7e0; border-radius: 0; background: transparent; color: var(--ink); text-align: left; }.application-item:last-child { border-bottom: 0; }.application-item[aria-selected="true"] { background: #f0f7ee; }.application-item strong,.application-item span { display:block; }.application-item span { margin-top:4px; color:var(--muted); font-size:.82rem; }.application-detail { min-height: 360px; padding: 25px; }.application-detail dl { display:grid; grid-template-columns: 150px 1fr; gap:12px 16px; margin:22px 0; }.application-detail dt { color:var(--muted); font-size:.8rem; font-weight:750; text-transform:uppercase; letter-spacing:.05em; }.application-detail dd { margin:0; white-space:pre-wrap; }.application-detail .photos { max-width:none; }.application-detail .photos button { width:120px; height:90px; }.accept { border-color:#247036; background:#247036; }.accept:hover { background:#185627; }
|
|
dialog { width: min(900px, calc(100% - 32px)); padding: 0; border: 1px solid #5a524b; border-radius: 10px; background: #24211f; color: #fffdfa; box-shadow: 0 24px 80px #211b18aa; }
|
|
dialog::backdrop { background: #211b1877; }
|
|
.gallery { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 12px; padding: 16px; }
|
|
.gallery img { display: block; width: 100%; max-height: 72vh; object-fit: contain; }
|
|
.gallery button { width: 44px; min-height: 44px; padding: 0; border-color: #665d56; background: #3a3430; font-size: 1.25rem; }
|
|
.gallery button:hover { background: #514840; }
|
|
.gallery-footer { display: flex; justify-content: space-between; align-items: center; padding: 0 18px 16px; color: #c8bfb8; font-size: .85rem; }
|
|
.gallery-footer button { min-height: 34px; padding: 5px 10px; }
|
|
@media (max-width: 720px) { main { width: calc(100% - 28px); padding-top: 28px; } .topbar { display: block; } .record-count { display: block; margin-top: 18px; } .controls { display: grid; grid-template-columns: 1fr 1fr; } .control-group:first-child, .controls > button { grid-column: 1 / -1; } input { min-width: 0; width: 100%; } .auth-form { display: grid; } .application-layout { grid-template-columns: 1fr; }.application-list { border-right:0; border-bottom:1px solid var(--line); }.application-detail dl { grid-template-columns:1fr; gap:4px; }.application-detail dd { margin-bottom:14px; } }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<section id="authView" class="auth-view">
|
|
<h2>Админская панель</h2>
|
|
<p>Введите пароль администратора, чтобы открыть историю отчётов.</p>
|
|
<form id="authForm" class="auth-form">
|
|
<input id="password" type="password" autocomplete="current-password" placeholder="Пароль" required>
|
|
<button type="submit" id="authButton">Войти</button>
|
|
</form>
|
|
</section>
|
|
|
|
<section id="appView" class="hidden">
|
|
<header class="topbar">
|
|
<div><h1>Админская панель</h1><p class="intro">Расчёты и обращения из VK-бота и веб-формы.</p></div>
|
|
</header>
|
|
<nav class="tabs" aria-label="Раздел админской панели">
|
|
<button class="admin-tab tab" type="button" data-admin-view="reports" aria-selected="true">Отчёты</button>
|
|
<button class="admin-tab tab" type="button" data-admin-view="applications" aria-selected="false">Заявки</button>
|
|
</nav>
|
|
<section id="reportsView" class="admin-section">
|
|
<header class="topbar">
|
|
<div><h1>История отчётов</h1><p class="intro">Подтверждённые расчёты из VK-бота и веб-калькулятора.</p></div>
|
|
<div class="record-count" id="recordCount">Записи не загружены</div>
|
|
</header>
|
|
<nav class="tabs" aria-label="Категория отчётов">
|
|
<button class="tab" type="button" data-category="all" aria-selected="true">Все</button>
|
|
<button class="tab" type="button" data-category="inspection" aria-selected="false">Осмотры</button>
|
|
<button class="tab" type="button" data-category="lu" aria-selected="false">Лазание (ЛУ)</button>
|
|
<button class="tab" type="button" data-category="zu" aria-selected="false">Зоркость (ЗУ)</button>
|
|
<button class="tab" type="button" data-category="training" aria-selected="false">ПУ / уроки</button>
|
|
</nav>
|
|
<section class="controls" aria-label="Фильтры истории">
|
|
<label class="control-group">Сортировать по<select id="sort"><option value="cat">Коту</option><option value="kitten">Котёнку</option><option value="photo">Фото</option><option value="date">Дате</option><option value="message">Сообщению</option><option value="author">Автору</option><option value="id">ID</option></select></label>
|
|
<label class="control-group">Порядок<select id="direction"><option value="asc">По возрастанию</option><option value="desc" selected>По убыванию</option></select></label>
|
|
<label class="control-group">Кот<select id="catFilter"><option value="">Все коты</option></select></label>
|
|
<label class="control-group">Котёнок<select id="kittenFilter"><option value="">Все котята</option></select></label>
|
|
<button id="load" type="button">Обновить</button>
|
|
</section>
|
|
<p class="error" id="error" role="alert"></p>
|
|
<div class="table-wrap"><table><thead><tr><th>Кот</th><th>Котята</th><th>Фото</th><th>Дата</th><th>Сообщение</th><th>Автор</th><th>ID</th><th></th></tr></thead><tbody id="rows"><tr><td class="empty" colspan="8">Загрузка истории…</td></tr></tbody></table></div>
|
|
</section>
|
|
<section id="applicationsView" class="admin-section applications hidden" aria-labelledby="applicationsTitle"><header class="topbar"><div><h2 id="applicationsTitle">Заявки</h2><p class="intro">Новые обращения из VK-бота и веб-формы.</p></div><div class="record-count" id="applicationCount">Заявки не загружены</div></header><nav class="tabs" aria-label="Статус заявок"><button class="application-tab tab" type="button" data-status="pending" aria-selected="true">Новые</button><button class="application-tab tab" type="button" data-status="accepted" aria-selected="false">Принятые</button></nav><div class="application-layout"><div id="applicationList" class="application-list"><p class="empty">Загрузка заявок…</p></div><article id="applicationDetail" class="application-detail"><p class="empty">Выберите заявку слева.</p></article></div></section>
|
|
</section>
|
|
</main>
|
|
|
|
<dialog id="galleryDialog">
|
|
<div class="gallery"><button id="prevPhoto" type="button" aria-label="Предыдущее фото">←</button><img id="galleryImage" alt="Фото отчёта"><button id="nextPhoto" type="button" aria-label="Следующее фото">→</button></div>
|
|
<div class="gallery-footer"><span id="galleryCounter"></span><button id="closeGallery" type="button">Закрыть</button></div>
|
|
</dialog>
|
|
|
|
<script>
|
|
const authView = document.querySelector('#authView');
|
|
const appView = document.querySelector('#appView');
|
|
const authForm = document.querySelector('#authForm');
|
|
const password = document.querySelector('#password');
|
|
const authButton = document.querySelector('#authButton');
|
|
const sort = document.querySelector('#sort');
|
|
const direction = document.querySelector('#direction');
|
|
const catFilter = document.querySelector('#catFilter');
|
|
const kittenFilter = document.querySelector('#kittenFilter');
|
|
const rows = document.querySelector('#rows');
|
|
const error = document.querySelector('#error');
|
|
const recordCount = document.querySelector('#recordCount');
|
|
const loadButton = document.querySelector('#load');
|
|
const galleryDialog = document.querySelector('#galleryDialog');
|
|
const galleryImage = document.querySelector('#galleryImage');
|
|
const galleryCounter = document.querySelector('#galleryCounter');
|
|
let items = [], galleryPhotos = [], galleryIndex = 0, activeCategory = 'all';
|
|
let applications = [], activeApplicationStatus = 'pending', selectedApplicationId = null, activeAdminView = 'reports';
|
|
|
|
function personData(input) { return {name: input.escort_name || input.character_name || '', id: input.escort_id || input.character_id || ''}; }
|
|
function kittenEntries(input) {
|
|
const entries = [];
|
|
if (input.kitten_name || input.kitten_id) entries.push({name: input.kitten_name || 'Котёнок', id: input.kitten_id || ''});
|
|
(input.extra_kittens || []).forEach(item => entries.push({name: item.name || item[0] || 'Котёнок', id: item.id || item[1] || ''}));
|
|
return entries;
|
|
}
|
|
function personCell(person) { const node = document.createElement('td'); node.className = 'person'; const strong = document.createElement('strong'); strong.textContent = person.name || '—'; const small = document.createElement('span'); small.textContent = person.id ? `[${person.id}]` : 'ID не указан'; node.append(strong, small); return node; }
|
|
function photoCell(attachments) {
|
|
const node = document.createElement('td'); const gallery = document.createElement('div'); gallery.className = 'photos';
|
|
const validPhotos = (attachments || []).filter(photo => photo.mirror_url || photo.url);
|
|
validPhotos.forEach((photo, index) => { const url = photo.mirror_url || photo.url; const button = document.createElement('button'); button.type = 'button'; button.title = 'Открыть фото'; const image = document.createElement('img'); image.src = url; image.alt = 'Фото отчёта'; image.loading = 'lazy'; button.append(image); button.addEventListener('click', () => openGallery(validPhotos, index)); gallery.append(button); });
|
|
if (gallery.childElementCount) node.append(gallery); else node.textContent = '—'; return node;
|
|
}
|
|
function textForSort(item, field) { const input = item.input || {}; const person = personData(input); const kittens = kittenEntries(input); if (field === 'cat') return `${person.name} ${person.id}`.toLocaleLowerCase(); if (field === 'kitten') return kittens.map(item => `${item.name} ${item.id}`).join(',').toLocaleLowerCase(); if (field === 'photo') return (input.attachments || []).length; if (field === 'date') return item.created_at || ''; if (field === 'message') return item.message || ''; if (field === 'author') return String(item.actor_id || ''); return Number(item.id) || 0; }
|
|
function categoryFor(item) { const input = item.input || {}; if (input.mode === 'inspection') return 'inspection'; if (input.mode === 'training') return 'training'; if (input.skill === 'ЛУ') return 'lu'; if (input.skill === 'ЗУ') return 'zu'; return 'other'; }
|
|
function filteredItems() { const cat = catFilter.value; const kitten = kittenFilter.value; return items.filter(item => { const input = item.input || {}; const person = personData(input); const kittens = kittenEntries(input); return (activeCategory === 'all' || categoryFor(item) === activeCategory) && (!cat || String(person.id) === cat) && (!kitten || kittens.some(entry => String(entry.id) === kitten)); }).sort((a, b) => { const av = textForSort(a, sort.value), bv = textForSort(b, sort.value); const result = typeof av === 'number' && typeof bv === 'number' ? av - bv : String(av).localeCompare(String(bv), 'ru', {numeric: true, sensitivity: 'base'}); return direction.value === 'asc' ? result : -result; }); }
|
|
function fillFilters() { const cats = new Map(), kittens = new Map(); items.forEach(item => { const input = item.input || {}; const person = personData(input); if (person.id) cats.set(String(person.id), person.name); kittenEntries(input).forEach(entry => { if (entry.id) kittens.set(String(entry.id), entry.name); }); }); const catValue = catFilter.value, kittenValue = kittenFilter.value; catFilter.replaceChildren(new Option('Все коты', '')); [...cats.entries()].sort((a,b) => a[1].localeCompare(b[1], 'ru')).forEach(([id,name]) => catFilter.add(new Option(`${name} [${id}]`, id))); kittenFilter.replaceChildren(new Option('Все котята', '')); [...kittens.entries()].sort((a,b) => a[1].localeCompare(b[1], 'ru')).forEach(([id,name]) => kittenFilter.add(new Option(`${name} [${id}]`, id))); if ([...catFilter.options].some(option => option.value === catValue)) catFilter.value = catValue; if ([...kittenFilter.options].some(option => option.value === kittenValue)) kittenFilter.value = kittenValue; }
|
|
function render() { rows.replaceChildren(); const visible = filteredItems(); recordCount.textContent = `${visible.length} из ${items.length} записей`; if (!visible.length) { const row = document.createElement('tr'); const cell = document.createElement('td'); cell.className = 'empty'; cell.colSpan = 8; cell.textContent = 'По выбранным условиям записей нет.'; row.append(cell); rows.append(row); return; } visible.forEach(item => { const input = item.input || {}; const row = document.createElement('tr'); row.append(personCell(personData(input))); const kittenCell = document.createElement('td'); kittenCell.className = 'person'; kittenEntries(input).forEach(entry => { const strong = document.createElement('strong'); strong.textContent = entry.name; const small = document.createElement('span'); small.textContent = entry.id ? `[${entry.id}]` : 'ID не указан'; kittenCell.append(strong, small); }); if (!kittenCell.childElementCount) kittenCell.textContent = '—'; row.append(kittenCell, photoCell(input.attachments), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.created_at || '—'; return cell; })()); const message = document.createElement('td'); const pre = document.createElement('pre'); pre.className = 'message'; pre.textContent = item.message; message.append(pre); row.append(message, (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.actor_id || '—'; return cell; })(), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.id; return cell; })()); const actions = document.createElement('td'); const remove = document.createElement('button'); remove.className = 'delete'; remove.type = 'button'; remove.textContent = 'Удалить'; remove.addEventListener('click', async () => { if (!window.confirm(`Удалить запись №${item.id}?`)) return; remove.disabled = true; try { const response = await fetch(`/api/admin/calculations/${encodeURIComponent(item.id)}`, {method: 'DELETE', headers: {'X-Admin-Password': password.value}}); const result = await response.json(); if (!response.ok) throw new Error(result.error || 'Не удалось удалить запись'); items = items.filter(entry => entry.id !== item.id); fillFilters(); render(); } catch (err) { error.textContent = err.message; remove.disabled = false; } }); actions.append(remove); row.append(actions); rows.append(row); }); }
|
|
async function load() { error.textContent = ''; loadButton.disabled = true; try { const query = new URLSearchParams({sort: 'escort_name', direction: 'asc', limit: '500'}); const response = await fetch(`/api/admin/calculations?${query}`, {headers: {'X-Admin-Password': password.value}}); const data = await response.json(); if (!response.ok) throw new Error(data.error || 'Не удалось загрузить историю'); items = data.items || []; fillFilters(); render(); } catch (err) { error.textContent = err.message; recordCount.textContent = 'История не загружена'; } finally { loadButton.disabled = false; } }
|
|
const applicationLabels = {feather_donation: 'Пожертвование перьев', kitten: 'Стать бельчонком', flying_squirrel: 'Стать белкой-летягой', curator: 'Стать куратором'};
|
|
function applicationFields(item) { const a = item.application || {}; const fields = [['Тип', applicationLabels[a.type] || a.type], ['Персонаж', `${a.name || '—'}${a.character_id ? ` [${a.character_id}]` : ''}`], ['Источник', item.source === 'vk' ? 'VK-бот' : 'Веб-форма']]; if (a.vk_link) fields.push(['VK', a.vk_link]); if (a.type === 'flying_squirrel') { fields.push(['Практика ранее', a.practiced_before ? 'Да' : 'Нет']); if (a.practice_review_link) fields.push(['Комментарий практики', a.practice_review_link]); } if (a.type === 'feather_donation') fields.push(['Перья', (a.feathers || []).map(x => `${x.amount} ${x.color} — ${x.source}`).join('\n')]); if (a.type === 'curator') fields.push(['Подтверждение', 'Скриншот ЛУ с дробью']); return fields; }
|
|
function renderApplications() { const list = document.querySelector('#applicationList'), detail = document.querySelector('#applicationDetail'), visible = applications.filter(item => item.status === activeApplicationStatus); document.querySelector('#applicationCount').textContent = `${visible.length} ${activeApplicationStatus === 'pending' ? 'новых' : 'принятых'} заявок`; list.replaceChildren(); if (!visible.length) { const empty=document.createElement('p'); empty.className='empty'; empty.textContent='Заявок в этой категории нет.'; list.append(empty); detail.replaceChildren(); const prompt=document.createElement('p');prompt.className='empty';prompt.textContent='Выберите заявку слева.';detail.append(prompt); return; } if (!visible.some(item => item.id === selectedApplicationId)) selectedApplicationId = visible[0].id; visible.forEach(item => { const a=item.application||{}, button=document.createElement('button'), name=document.createElement('strong'), info=document.createElement('span'); button.type='button'; button.className='application-item'; button.setAttribute('aria-selected', String(item.id === selectedApplicationId)); name.textContent=`${a.name || 'Без имени'}${a.character_id ? ` [${a.character_id}]` : ''}`; info.textContent=`${applicationLabels[a.type] || a.type} · ${item.created_at || ''}`; button.append(name,info); button.onclick=()=>{selectedApplicationId=item.id;renderApplications()}; list.append(button); }); const item=visible.find(entry=>entry.id===selectedApplicationId); const fields=applicationFields(item); detail.replaceChildren(); const title=document.createElement('h2'); title.textContent=`Заявка №${item.id}`; const dl=document.createElement('dl'); fields.forEach(([term,value])=>{const dt=document.createElement('dt'),dd=document.createElement('dd');dt.textContent=term;dd.textContent=value;dl.append(dt,dd)}); detail.append(title,dl); const photos=(item.application||{}).attachments||[]; if(photos.length){const title=document.createElement('dt');title.textContent='Скриншоты';const gallery=photoCell(photos).querySelector('.photos');detail.append(title,gallery)} if(item.status==='pending'){const accept=document.createElement('button');accept.className='accept';accept.type='button';accept.textContent='Принять';accept.onclick=async()=>{accept.disabled=true;try{const r=await fetch(`/api/admin/applications/${item.id}/accept`,{method:'PATCH',headers:{'X-Admin-Password':password.value}});const data=await r.json();if(!r.ok)throw new Error(data.error||'Не удалось принять заявку');await loadApplications()}catch(err){error.textContent=err.message;accept.disabled=false}};detail.append(accept)} }
|
|
async function loadApplications() { try { const response=await fetch('/api/admin/applications',{headers:{'X-Admin-Password':password.value}}), data=await response.json(); if(!response.ok)throw new Error(data.error||'Не удалось загрузить заявки'); applications=data.items||[];renderApplications(); } catch(err) { error.textContent=err.message; } }
|
|
async function authenticate(event) { event.preventDefault(); error.textContent = ''; authButton.disabled = true; try { const response = await fetch('/api/admin/calculations?limit=1', {headers: {'X-Admin-Password': password.value}}); const data = await response.json(); if (!response.ok) throw new Error(data.error || 'Не удалось войти'); authView.classList.add('hidden'); appView.classList.remove('hidden'); items = data.items || []; await load(); await loadApplications(); } catch (err) { const message = document.createElement('p'); message.textContent = err.message; message.className = 'error'; const old = authView.querySelector('.error'); if (old) old.remove(); authView.append(message); } finally { authButton.disabled = false; } }
|
|
function updateGallery() { const photo = galleryPhotos[galleryIndex]; galleryImage.src = photo.mirror_url || photo.url; galleryCounter.textContent = `${galleryIndex + 1} из ${galleryPhotos.length}`; }
|
|
function openGallery(photos, index) { galleryPhotos = photos.filter(photo => photo.mirror_url || photo.url); galleryIndex = Math.min(index, galleryPhotos.length - 1); updateGallery(); if (galleryDialog.showModal) galleryDialog.showModal(); else galleryDialog.setAttribute('open', ''); }
|
|
function closeGallery() { if (galleryDialog.close) galleryDialog.close(); else galleryDialog.removeAttribute('open'); }
|
|
function selectAdminView(view) { activeAdminView = view; document.querySelector('#reportsView').classList.toggle('hidden', view !== 'reports'); document.querySelector('#applicationsView').classList.toggle('hidden', view !== 'applications'); document.querySelectorAll('.admin-tab').forEach(tab => tab.setAttribute('aria-selected', String(tab.dataset.adminView === view))); }
|
|
authForm.addEventListener('submit', authenticate); loadButton.addEventListener('click', load); sort.addEventListener('change', render); direction.addEventListener('change', render); catFilter.addEventListener('change', render); kittenFilter.addEventListener('change', render); document.querySelectorAll('[data-category]').forEach(tab => tab.addEventListener('click', () => { activeCategory = tab.dataset.category; document.querySelectorAll('[data-category]').forEach(item => item.setAttribute('aria-selected', String(item === tab))); render(); })); document.querySelector('#closeGallery').addEventListener('click', closeGallery); document.querySelector('#prevPhoto').addEventListener('click', () => { galleryIndex = (galleryIndex - 1 + galleryPhotos.length) % galleryPhotos.length; updateGallery(); }); document.querySelector('#nextPhoto').addEventListener('click', () => { galleryIndex = (galleryIndex + 1) % galleryPhotos.length; updateGallery(); }); document.addEventListener('keydown', event => { if (!galleryDialog.open) return; if (event.key === 'Escape') closeGallery(); if (event.key === 'ArrowLeft') document.querySelector('#prevPhoto').click(); if (event.key === 'ArrowRight') document.querySelector('#nextPhoto').click(); });
|
|
document.querySelectorAll('.application-tab').forEach(tab => tab.addEventListener('click', () => { activeApplicationStatus = tab.dataset.status; document.querySelectorAll('.application-tab').forEach(item => item.setAttribute('aria-selected', String(item === tab))); renderApplications(); }));
|
|
document.querySelectorAll('.admin-tab').forEach(tab => tab.addEventListener('click', () => selectAdminView(tab.dataset.adminView)));
|
|
</script>
|
|
</body>
|
|
</html>
|