docs: explain calculator form helpers

This commit is contained in:
nyan404 committed 2026-08-25 04:22:57 +03:00
1 parent 3989cdc4e3
commit 6118b20448
1 file changed
+12
+12
View File
@@ -219,6 +219,7 @@
let mode = 'coaching';
const extraKittens = document.querySelector('#extraKittens');
const statusHelp = document.querySelector('#statusHelp');
// Adds one repeatable kitten row and optionally fills it from saved values.
function addExtraKitten(values = {}) {
const row = document.createElement('div'); row.className = 'extra-kitten';
row.innerHTML = `<input data-extra="name" placeholder="Имя котёнка" required>
@@ -233,7 +234,9 @@
extraKittens.append(row);
}
document.querySelector('#addKitten').addEventListener('click', () => addExtraKitten());
// Returns all independence controls participating in the current coaching form.
function statusFields() { return [document.querySelector('#coaching [name="kitten_independence"]'), ...extraKittens.querySelectorAll('[data-extra="independence"]')]; }
// Enables or locks independence controls according to the selected skill.
function updateStatusRules(event) {
const fields = statusFields();
const isZu = document.querySelector('#coaching [name="skill"]').value === 'ЗУ';
@@ -245,6 +248,7 @@
statusHelp.textContent = 'Для ЛУ можно указать не более одного несамостоятельного котёнка.';
}
}
// Returns a user-facing validation error when kitten statuses conflict.
function validateStatusRules() {
const fields = statusFields();
const skill = document.querySelector('#coaching [name="skill"]').value;
@@ -252,6 +256,7 @@
if (skill === 'ЛУ' && fields.filter(field => field.value === 'несамостоятельно').length > 1) return 'Для ЛУ допускается только один несамостоятельный котёнок.';
return '';
}
// Switches the visible calculator panel and disables fields in hidden panels.
function selectMode(nextMode) {
mode = nextMode;
document.querySelectorAll('[data-mode]').forEach(item => item.classList.toggle('active', item.dataset.mode === mode));
@@ -267,6 +272,7 @@
document.querySelectorAll('[data-mode]').forEach(button => button.addEventListener('click', () => selectMode(button.dataset.mode)));
document.querySelector('#coaching [name="skill"]').addEventListener('change', updateStatusRules);
document.querySelector('#coaching [name="kitten_independence"]').addEventListener('change', updateStatusRules);
// Writes a value into a named field inside a calculator panel.
function setField(panel, name, value) {
const field = document.querySelector(`#${panel} [name="${name}"]`);
if (field && value !== undefined && value !== null) field.value = value;
@@ -328,6 +334,7 @@
identityDialog.close(); identityStatus.textContent = 'Связка добавлена в текущий процесс.';
});
document.querySelector('#closeIdentityDialog').addEventListener('click', () => identityDialog.close());
// Serializes the active calculator form into the API payload shape.
function payload() {
const data = {};
document.querySelectorAll(`#${mode} [name]`).forEach(field => { data[field.name] = field.value; });
@@ -349,6 +356,7 @@
}
return data;
}
// Uploads selected screenshots and returns attachment descriptors for the API.
async function uploadScreenshots() {
const files = [...(screenshots.files || [])];
const uploaded = [];
@@ -392,6 +400,7 @@
const applicationFeathers = document.querySelector('#applicationFeathers');
let applicationType = 'feather_donation';
// Changes between reports and applications while optionally updating the URL.
function setSection(nextSection, updateUrl = true) {
const isApplications = nextSection === 'applications';
reportsSection.classList.toggle('hidden', isApplications);
@@ -411,6 +420,7 @@
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));
// Adds and initializes one feather row in the application form.
function addApplicationFeather(values = {}) {
const row = document.createElement('div');
row.className = 'feather';
@@ -421,11 +431,13 @@
}
document.querySelector('#applicationAddFeather').addEventListener('click', () => addApplicationFeather());
// Toggles visibility and disabled state for an application subsection.
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; });
}
// Synchronizes application subsection visibility with the selected type.
function syncApplicationForm() {
const isFeather = applicationType === 'feather_donation';
setApplicationFieldsVisible('#applicationFeatherFields', isFeather);