Ajoute un mode competition a la configuration
This commit is contained in:
41
app.js
41
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 = `
|
||||
<strong>${MODES[mode].label}</strong>
|
||||
<span>${PRESETS[preset].description}</span>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user