diff --git a/fiches/static/fiches/css/annuaire.css b/fiches/static/fiches/css/annuaire.css index 0a050ff..46ad663 100644 --- a/fiches/static/fiches/css/annuaire.css +++ b/fiches/static/fiches/css/annuaire.css @@ -374,6 +374,9 @@ body { column-gap: 10px; margin: 0 0 10px 0; } +#content-edit-profile form .form-sub-entry.hidden { + display: none; +} #content-edit-profile form .form-sub-entry :nth-child(1) { grid-area: type-input; } @@ -393,6 +396,12 @@ body { #content-edit-profile form .form-sub-entry .remove-button:active { background-color: #973232; } +#content-edit-profile form .form-sub-entry input[type=checkbox] { + display: none; +} +#content-edit-profile form .form-sub-entry-template { + display: none; +} #content-edit-profile form .add-sub-entry-button { margin: 0 auto 0 auto; } diff --git a/fiches/static/fiches/js/forms.js b/fiches/static/fiches/js/forms.js index 6636ea2..ed5dd8e 100644 --- a/fiches/static/fiches/js/forms.js +++ b/fiches/static/fiches/js/forms.js @@ -1,80 +1,90 @@ "use strict"; -function countSubEntries(formEntryElement) { - return formEntryElement - .querySelectorAll(".form-sub-entry") - .length; -} +// function countSubEntries(formEntryElement) { +// return formEntryElement +// .querySelectorAll(".form-sub-entry") +// .length; +// } -function reindexSubEntries(formEntryElement) { - const subEntryElements = [...formEntryElement.querySelectorAll(".form-sub-entry")]; - for (let [subEntryIndex, subEntryElement] of subEntryElements.entries()) { - subEntryElement.setAttribute("data-sub-entry-index", subEntryIndex); - } -} +// function reindexSubEntries(formEntryElement) { +// const subEntryElements = [...formEntryElement.querySelectorAll(".form-sub-entry")]; +// for (let [subEntryIndex, subEntryElement] of subEntryElements.entries()) { +// subEntryElement.setAttribute("data-sub-entry-index", subEntryIndex); +// } +// } -function createAndAppendNewSubEntryButton(formEntryElement) { - const buttonElement = document.createElement("button"); - buttonElement.setAttribute("type", "button"); - buttonElement.classList.add("add-sub-entry-button"); +// function checkSubEntryDeleteCheckbox(subEntryElement) { +// const checkboxElement = [...subEntryElement.querySelectorAll('input[type="checkbox"')] +// .filter(element => element.className.endsWith("DELETE")); + +// if (checkboxElement.length >= 1) { +// checkboxElement.checked = true; +// } +// } - // TODO: handle the translation of this button - buttonElement.textContent = "New entry"; - buttonElement.addEventListener("click", event => { - // Clone one of the sub-entries, make it look like it is new, and reindex the sub-entries - // This works because there is always at least one sub-entry to clone - const someSubEntryElement = formEntryElement.querySelector(".form-sub-entry"); - const clonedSubEntryElement = someSubEntryElement.cloneNode(true); +// function createAndAppendNewSubEntryButton(formEntryElement) { +// const buttonElement = document.createElement("button"); +// buttonElement.setAttribute("type", "button"); +// buttonElement.classList.add("add-sub-entry-button"); - for (let inputElement of clonedSubEntryElement.querySelectorAll("input")) { - inputElement.value = ""; - } +// // TODO: handle the translation of this button +// buttonElement.textContent = "New entry"; - // Since the cloned removal button has lost its click event listener, - // it should be created again from scratch - clonedSubEntryElement - .querySelector(".remove-button") - .remove(); - createAndAppendSubEntryDeletionButton(clonedSubEntryElement); +// buttonElement.addEventListener("click", event => { +// // Clone one of the sub-entries, make it look like it is new, and reindex the sub-entries +// // This works because there is always at least one sub-entry to clone +// const someSubEntryElement = formEntryElement.querySelector(".form-sub-entry"); +// const clonedSubEntryElement = someSubEntryElement.cloneNode(true); - formEntryElement.insertBefore(clonedSubEntryElement, buttonElement); - reindexSubEntries(formEntryElement); - }); +// for (let inputElement of clonedSubEntryElement.querySelectorAll("input")) { +// inputElement.value = ""; +// } - formEntryElement.append(buttonElement); -} +// // Since the cloned removal button has lost its click event listener, +// // it should be created again from scratch +// clonedSubEntryElement +// .querySelector(".remove-button") +// .remove(); +// createAndAppendSubEntryDeletionButton(clonedSubEntryElement); -function createAndAppendSubEntryDeletionButton(subEntryElement) { - const buttonElement = document.createElement("button"); - buttonElement.setAttribute("type", "button"); - buttonElement.classList.add("remove-button"); +// formEntryElement.insertBefore(clonedSubEntryElement, buttonElement); +// reindexSubEntries(formEntryElement); +// }); - buttonElement.addEventListener("click", event => { - const parentFormEntryElement = subEntryElement.parentNode; +// formEntryElement.append(buttonElement); +// } - // If this sub-entry is the last one, only clear its input fields - // Otherwise, remove the node from the form entry - if (countSubEntries(parentFormEntryElement) === 1) { - subEntryElement - .querySelectorAll("input") - .value = ""; - } - else { - subEntryElement.remove(); - reindexSubEntries(parentFormEntryElement); - } - }); +// function createAndAppendSubEntryDeletionButton(subEntryElement) { +// const buttonElement = document.createElement("button"); +// buttonElement.setAttribute("type", "button"); +// buttonElement.classList.add("remove-button"); - subEntryElement.append(buttonElement); -} +// buttonElement.addEventListener("click", event => { +// const parentFormEntryElement = subEntryElement.parentNode; -function createSubEntryElement() { - const subEntryElement = document.createElement("div"); - subEntryElement.classList.add("form-sub-entry"); +// // If this sub-entry is the last one, only clear its input fields +// // Otherwise, remove the node from the form entry +// if (countSubEntries(parentFormEntryElement) === 1) { +// subEntryElement +// .querySelectorAll("input") +// .value = ""; +// } +// else { +// subEntryElement.remove(); +// reindexSubEntries(parentFormEntryElement); +// } +// }); - return subEntryElement; -} +// subEntryElement.append(buttonElement); +// } + +// function createSubEntryElement() { +// const subEntryElement = document.createElement("div"); +// subEntryElement.classList.add("form-sub-entry"); + +// return subEntryElement; +// } // ---------------------------------------------------------------------------- @@ -82,117 +92,341 @@ function createSubEntryElement() { // TODO: remove this hacky function by directly grouping all the elements of each sub-entry // directly in Django (e.g.