diff --git a/app.js b/app.js index 59f2ce7..da4a0ef 100644 --- a/app.js +++ b/app.js @@ -114,6 +114,8 @@ function initSetupPage() { const summary = document.querySelector("#setupSummary"); const loadDemoButton = document.querySelector("#loadDemoButton"); const resumeCard = document.querySelector("#resumeCard"); + const competitionModeInput = document.querySelector("#competitionMode"); + const competitionFields = Array.from(document.querySelectorAll("[data-competition-field]")); const moveSecondsField = document.querySelector("#moveSecondsField"); const timeInitialField = document.querySelector("#timeInitialField"); const blockSecondsLabel = document.querySelector("#blockSecondsLabel"); @@ -124,6 +126,29 @@ function initSetupPage() { return; } + const syncCompetitionFields = () => { + const competitionMode = competitionModeInput instanceof HTMLInputElement && competitionModeInput.checked; + + competitionFields.forEach((field) => { + if (!(field instanceof HTMLElement)) { + return; + } + + field.hidden = !competitionMode; + field + .querySelectorAll("input, textarea, select") + .forEach((input) => { + if ( + input instanceof HTMLInputElement || + input instanceof HTMLTextAreaElement || + input instanceof HTMLSelectElement + ) { + input.disabled = !competitionMode; + } + }); + }); + }; + const renderSummary = () => { const mode = getRadioValue(form, "mode") || "twice"; const preset = getRadioValue(form, "preset") || "fast"; @@ -167,6 +192,8 @@ function initSetupPage() { blockLabel === "Block" ? "Temps du Block (secondes)" : "Temps partie (secondes)"; } + syncCompetitionFields(); + summary.innerHTML = ` ${MODES[mode].label} ${PRESETS[preset].description} @@ -223,6 +250,7 @@ function initSetupPage() { const data = new FormData(form); const config = { matchLabel: sanitizeText(data.get("matchLabel")) || "Rencontre ChessCubing", + competitionMode: isCheckboxChecked(form, "competitionMode"), mode: getRadioValue(form, "mode") || "twice", preset: getRadioValue(form, "preset") || "fast", blockDurationMs: getDurationInputMs(form, "blockSeconds", DEFAULT_BLOCK_DURATION_MS), @@ -1782,6 +1810,7 @@ function toggleModal(element, open) { } function loadDemo(form, onRender) { + setCheckboxValue(form, "competitionMode", true); setInputValue(form, "matchLabel", "Demo officielle ChessCubing"); setRadioValue(form, "mode", "twice"); setRadioValue(form, "preset", "freeze"); @@ -1815,6 +1844,18 @@ function setRadioValue(form, name, value) { } } +function setCheckboxValue(form, name, checked) { + const input = form.querySelector(`input[name="${name}"]`); + if (input instanceof HTMLInputElement) { + input.checked = checked; + } +} + +function isCheckboxChecked(form, name) { + const input = form.querySelector(`input[name="${name}"]`); + return input instanceof HTMLInputElement ? input.checked : false; +} + function getDurationInputMs(form, name, fallbackMs) { const input = form.querySelector(`[name="${name}"]`); const seconds = Number.parseInt(String(input?.value || ""), 10); diff --git a/application.html b/application.html index 767579d..0b19b97 100644 --- a/application.html +++ b/application.html @@ -65,7 +65,16 @@