feat(web): combine reports and applications
This commit is contained in:
1 parent
f73f99068a
commit
02126d768d
3 files changed
+196
-6
No files matched your search
+193
-3
@@ -11,6 +11,8 @@
|
||||
h1 { margin: 0 0 6px; font: 500 clamp(2.25rem, 5vw, 4rem)/1 Georgia, "Times New Roman", serif; letter-spacing: -.045em; }
|
||||
h2 { font: 500 1.55rem/1.15 Georgia, "Times New Roman", serif; } .muted { color: var(--muted); line-height: 1.55; }
|
||||
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 24px 0 16px; }
|
||||
.section-tabs { margin-top: 32px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
|
||||
.section-tabs button { border-color: transparent; background: transparent; }
|
||||
button, select, input, textarea { font: inherit; }
|
||||
button { min-height:44px; cursor: pointer; border: 1px solid #bdb6ad; border-radius: 7px; padding: 9px 14px; background: var(--paper); color: var(--ink); transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out; }
|
||||
button:hover { border-color:var(--accent); background:#fff8ef; } button:focus-visible, a:focus-visible { outline:3px solid var(--focus); outline-offset:3px; }
|
||||
@@ -39,16 +41,33 @@
|
||||
.error { color: var(--error); font-weight:700; white-space: pre-wrap; }
|
||||
.auth-panel { max-width: 460px; margin: 12vh auto; }
|
||||
.auth-panel form { display: grid; gap: 12px; }
|
||||
.application-intro { max-width: 68ch; margin: 0 0 24px; }
|
||||
.application-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 20px 0; }
|
||||
.application-type { min-height: 68px; text-align: left; font-weight: 700; }
|
||||
.application-type[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: #fff8ef; }
|
||||
.upload { display: grid; justify-items: center; gap: 8px; min-height: 132px; padding: 20px; text-align: center; border: 1px dashed #b9afa4; border-radius: 7px; background: #fffaf4; color: var(--muted); cursor: pointer; }
|
||||
.upload strong { color: var(--ink); } .upload input { display: none; }
|
||||
.files { margin: 10px 0 0; padding-left: 18px; color: var(--muted); }
|
||||
.feather { display: grid; grid-template-columns: 110px 1fr 1.3fr auto; gap: 9px; align-items: end; margin-bottom: 9px; }
|
||||
.remove { color: var(--error); border-color: #d9aaa5; }
|
||||
.success { margin-top: 20px; padding: 16px; border-left: 4px solid #527739; background: #f3f8ed; color: #304a22; border-radius: 7px; }
|
||||
@media (prefers-reduced-motion: reduce) { *,*::before,*::after { transition-duration:.01ms!important; } }
|
||||
@media (max-width: 700px) { main { margin:28px auto 48px; } .panel{padding:20px}.grid { grid-template-columns: 1fr; } .wide { grid-column: auto; }.actions{flex-direction:column}.actions button{width:100%;} }
|
||||
@media (max-width: 700px) { main { margin:28px auto 48px; } .panel{padding:20px}.grid,.application-types,.feather { grid-template-columns: 1fr; } .wide { grid-column: auto; }.actions{flex-direction:column}.actions button{width:100%;} }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Беличья нора — калькулятор отчётов</h1>
|
||||
<p class="muted">Один заход — один отчёт. Скриншоты к готовому отчёту нужно приложить вручную.</p>
|
||||
<p class="muted">Отчёты и заявки — в одном месте.</p>
|
||||
|
||||
<div class="tabs" role="tablist">
|
||||
<nav class="tabs section-tabs" role="tablist" aria-label="Раздел Беличьей норы">
|
||||
<button class="active" id="reportsTab" type="button" role="tab" aria-selected="true" aria-controls="reportsSection" data-section="reports">Отчёты</button>
|
||||
<button id="applicationsTab" type="button" role="tab" aria-selected="false" aria-controls="applicationsSection" data-section="applications">Заявки</button>
|
||||
</nav>
|
||||
|
||||
<section id="reportsSection" role="tabpanel" aria-labelledby="reportsTab">
|
||||
<p class="muted">Один заход — один отчёт. Скриншоты к готовому отчёту нужно приложить вручную.</p>
|
||||
<div class="tabs" role="tablist" aria-label="Вид отчёта">
|
||||
<button class="active" data-mode="coaching">Прокачка ЛУ/ЗУ</button>
|
||||
<button data-mode="training">Тренировка</button>
|
||||
<button data-mode="inspection">Осмотры</button>
|
||||
@@ -128,6 +147,43 @@
|
||||
<div class="result hidden" id="result"><h2>Сообщение</h2><textarea id="message" readonly></textarea><p class="muted" id="summary"></p></div>
|
||||
<p class="error" id="error"></p>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="applicationsSection" class="hidden" role="tabpanel" aria-labelledby="applicationsTab">
|
||||
<div id="applicationAuth" class="panel auth-panel">
|
||||
<h2>Подача заявки</h2>
|
||||
<p class="muted">Введите пароль, чтобы отправить заявку на рассмотрение и приложить скриншоты.</p>
|
||||
<form id="applicationAuthForm">
|
||||
<label>Пароль<input id="applicationPassword" type="password" autocomplete="current-password" required></label>
|
||||
<p id="applicationAuthError" class="error" role="alert"></p>
|
||||
<button class="primary" type="submit">Войти</button>
|
||||
</form>
|
||||
</div>
|
||||
<div id="applicationWorkspace" class="hidden">
|
||||
<h2>Новая заявка</h2>
|
||||
<p class="muted application-intro">Заполните форму — администратор получит структурированную заявку для рассмотрения. Форумную отпись готовить не нужно.</p>
|
||||
<div class="application-types" role="group" aria-label="Тип заявки">
|
||||
<button class="application-type" type="button" aria-pressed="true" data-application-type="feather_donation">Пожертвовать перо отряду</button>
|
||||
<button class="application-type" type="button" aria-pressed="false" data-application-type="kitten">Хочу стать бельчонком</button>
|
||||
<button class="application-type" type="button" aria-pressed="false" data-application-type="flying_squirrel">Хочу стать белкой-летягой</button>
|
||||
<button class="application-type" type="button" aria-pressed="false" data-application-type="curator">Хочу стать куратором</button>
|
||||
</div>
|
||||
<form id="applicationForm" class="panel">
|
||||
<div class="grid">
|
||||
<label>Имя персонажа<input name="name" required></label>
|
||||
<label>ID персонажа<input name="character_id" type="number" min="1" inputmode="numeric" required></label>
|
||||
<label id="applicationVkField" class="wide hidden">Ссылка на страницу VK <span class="muted">(необязательно)</span><input name="vk_link" type="url" placeholder="https://vk.com/id…"></label>
|
||||
<section id="applicationKittenFields" class="wide hidden"><label>Скриншот активности<span class="upload"><strong>Выберите или перетащите изображение</strong><span>PNG, JPG или JPEG до 15 МБ</span><input class="application-screenshots" type="file" accept="image/png,image/jpeg" multiple></span></label><ul class="files"></ul></section>
|
||||
<section id="applicationCuratorFields" class="wide hidden"><label>Скриншот ЛУ с дробью<span class="upload"><strong>Прикрепите скриншот ЛУ с дробью</strong><span>Нужен хотя бы один файл</span><input class="application-screenshots" type="file" accept="image/png,image/jpeg" multiple></span></label><ul class="files"></ul></section>
|
||||
<section id="applicationFlyingFields" class="wide hidden"><label>Сдавали практику ранее?<select name="practiced_before"><option value="no">Нет, не сдавал(-а)</option><option value="yes">Да, сдавал(-а)</option></select></label><label id="applicationPracticeLink" class="hidden">Ссылка на комментарий с прошлой практики<input name="practice_review_link" type="url" placeholder="https://catwar.su/… или https://vk.com/…"></label></section>
|
||||
<section id="applicationFeatherFields" class="wide"><h2>Перья для казны</h2><p class="muted">Укажите количество, цвет и источник добычи.</p><div id="applicationFeathers"></div><button id="applicationAddFeather" type="button">Добавить перо</button></section>
|
||||
</div>
|
||||
<p id="applicationError" class="error" role="alert"></p>
|
||||
<div class="actions"><button class="primary" id="applicationSubmit" type="submit">Отправить заявку</button></div>
|
||||
</form>
|
||||
<div id="applicationSuccess" class="success hidden" role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
<dialog id="identityDialog">
|
||||
<p id="identityDialogText"></p>
|
||||
@@ -306,6 +362,140 @@
|
||||
} catch (err) { error.textContent = err.message; }
|
||||
});
|
||||
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); copy.textContent = 'Скопировано'; setTimeout(() => copy.textContent = 'Скопировать', 1500); });
|
||||
|
||||
const reportsSection = document.querySelector('#reportsSection');
|
||||
const applicationsSection = document.querySelector('#applicationsSection');
|
||||
const sectionTabs = [...document.querySelectorAll('[data-section]')];
|
||||
const applicationAuth = document.querySelector('#applicationAuth');
|
||||
const applicationWorkspace = document.querySelector('#applicationWorkspace');
|
||||
const applicationAuthError = document.querySelector('#applicationAuthError');
|
||||
const applicationForm = document.querySelector('#applicationForm');
|
||||
const applicationError = document.querySelector('#applicationError');
|
||||
const applicationSuccess = document.querySelector('#applicationSuccess');
|
||||
const applicationSubmit = document.querySelector('#applicationSubmit');
|
||||
const applicationFeathers = document.querySelector('#applicationFeathers');
|
||||
let applicationType = 'feather_donation';
|
||||
|
||||
function setSection(nextSection, updateUrl = true) {
|
||||
const isApplications = nextSection === 'applications';
|
||||
reportsSection.classList.toggle('hidden', isApplications);
|
||||
applicationsSection.classList.toggle('hidden', !isApplications);
|
||||
sectionTabs.forEach(tab => {
|
||||
const selected = tab.dataset.section === nextSection;
|
||||
tab.classList.toggle('active', selected);
|
||||
tab.setAttribute('aria-selected', String(selected));
|
||||
});
|
||||
if (isApplications) checkApplicationSession();
|
||||
if (updateUrl) {
|
||||
const url = new URL(window.location.href);
|
||||
if (isApplications) url.searchParams.set('section', 'applications');
|
||||
else url.searchParams.delete('section');
|
||||
window.history.pushState({}, '', url);
|
||||
}
|
||||
}
|
||||
sectionTabs.forEach(tab => tab.addEventListener('click', () => setSection(tab.dataset.section)));
|
||||
window.addEventListener('popstate', () => setSection(new URLSearchParams(window.location.search).get('section') === 'applications' ? 'applications' : 'reports', false));
|
||||
|
||||
function showApplicationWorkspace() {
|
||||
applicationAuth.classList.add('hidden');
|
||||
applicationWorkspace.classList.remove('hidden');
|
||||
}
|
||||
async function checkApplicationSession() {
|
||||
try {
|
||||
const response = await fetch('/api/web/session');
|
||||
const data = await response.json();
|
||||
if (data.authenticated) showApplicationWorkspace();
|
||||
} catch (_) { /* The login form remains available and explains any error. */ }
|
||||
}
|
||||
document.querySelector('#applicationAuthForm').addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
applicationAuthError.textContent = '';
|
||||
const response = await fetch('/api/web/auth', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({password: document.querySelector('#applicationPassword').value}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) { applicationAuthError.textContent = data.error || 'Не удалось войти'; return; }
|
||||
showApplicationWorkspace();
|
||||
});
|
||||
|
||||
function addApplicationFeather(values = {}) {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'feather';
|
||||
row.innerHTML = '<label>Количество<input data-application-field="amount" type="number" min="1" inputmode="numeric" required></label><label>Цвет<input data-application-field="color" placeholder="например, синие" required></label><label>Источник добычи<input data-application-field="source" placeholder="личные запасы, осмотр дупла…" required></label><button class="remove" type="button">Убрать</button>';
|
||||
Object.entries(values).forEach(([name, value]) => { const field = row.querySelector(`[data-application-field="${name}"]`); if (field) field.value = value; });
|
||||
row.querySelector('.remove').addEventListener('click', () => row.remove());
|
||||
applicationFeathers.append(row);
|
||||
}
|
||||
document.querySelector('#applicationAddFeather').addEventListener('click', () => addApplicationFeather());
|
||||
|
||||
function setApplicationFieldsVisible(selector, visible) {
|
||||
const section = document.querySelector(selector);
|
||||
section.classList.toggle('hidden', !visible);
|
||||
section.querySelectorAll('input, select, textarea, button').forEach(field => { field.disabled = !visible; });
|
||||
}
|
||||
function syncApplicationForm() {
|
||||
const isFeather = applicationType === 'feather_donation';
|
||||
setApplicationFieldsVisible('#applicationFeatherFields', isFeather);
|
||||
setApplicationFieldsVisible('#applicationKittenFields', applicationType === 'kitten');
|
||||
setApplicationFieldsVisible('#applicationCuratorFields', applicationType === 'curator');
|
||||
setApplicationFieldsVisible('#applicationFlyingFields', applicationType === 'flying_squirrel');
|
||||
setApplicationFieldsVisible('#applicationVkField', applicationType === 'flying_squirrel');
|
||||
document.querySelectorAll('[data-application-type]').forEach(button => button.setAttribute('aria-pressed', String(button.dataset.applicationType === applicationType)));
|
||||
applicationError.textContent = '';
|
||||
}
|
||||
document.querySelectorAll('[data-application-type]').forEach(button => button.addEventListener('click', () => { applicationType = button.dataset.applicationType; syncApplicationForm(); }));
|
||||
document.querySelector('[name="practiced_before"]').addEventListener('change', event => {
|
||||
const visible = event.target.value === 'yes' && applicationType === 'flying_squirrel';
|
||||
setApplicationFieldsVisible('#applicationPracticeLink', visible);
|
||||
});
|
||||
document.querySelectorAll('.application-screenshots').forEach(input => input.addEventListener('change', () => {
|
||||
const list = input.closest('section').querySelector('.files');
|
||||
list.replaceChildren(...[...input.files].map(file => { const item = document.createElement('li'); item.textContent = file.name; return item; }));
|
||||
}));
|
||||
async function uploadApplicationScreenshots() {
|
||||
const attachments = [];
|
||||
const files = [...document.querySelectorAll('.application-screenshots:not(:disabled)')].flatMap(input => [...input.files]);
|
||||
for (const file of files) {
|
||||
const data = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result); reader.onerror = reject; reader.readAsDataURL(file); });
|
||||
const response = await fetch('/api/web/upload', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({name: file.name, type: file.type, data})});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) throw new Error(payload.error || `Не удалось загрузить ${file.name}`);
|
||||
attachments.push({type: 'photo', url: payload.url, name: file.name});
|
||||
}
|
||||
return attachments;
|
||||
}
|
||||
applicationForm.addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
applicationError.textContent = '';
|
||||
applicationSubmit.disabled = true;
|
||||
applicationSubmit.textContent = 'Отправляем…';
|
||||
try {
|
||||
const payload = Object.fromEntries(new FormData(applicationForm).entries());
|
||||
payload.type = applicationType;
|
||||
payload.character_id = Number(payload.character_id);
|
||||
payload.attachments = await uploadApplicationScreenshots();
|
||||
if (applicationType === 'flying_squirrel') payload.practiced_before = payload.practiced_before === 'yes';
|
||||
if (applicationType === 'feather_donation') payload.feathers = [...applicationFeathers.querySelectorAll('.feather')].map(row => ({
|
||||
amount: Number(row.querySelector('[data-application-field="amount"]').value),
|
||||
color: row.querySelector('[data-application-field="color"]').value,
|
||||
source: row.querySelector('[data-application-field="source"]').value,
|
||||
}));
|
||||
const response = await fetch('/api/applications', {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload)});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Не удалось отправить заявку');
|
||||
applicationSuccess.textContent = `Заявка №${data.id} отправлена на рассмотрение.`;
|
||||
applicationSuccess.classList.remove('hidden');
|
||||
applicationForm.reset();
|
||||
applicationFeathers.replaceChildren();
|
||||
addApplicationFeather();
|
||||
syncApplicationForm();
|
||||
} catch (err) { applicationError.textContent = err.message; }
|
||||
finally { applicationSubmit.disabled = false; applicationSubmit.textContent = 'Отправить заявку'; }
|
||||
});
|
||||
addApplicationFeather();
|
||||
syncApplicationForm();
|
||||
setSection(new URLSearchParams(window.location.search).get('section') === 'applications' ? 'applications' : 'reports', false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user