V1 avec bugs

This commit is contained in:
2026-04-03 15:27:51 +02:00
parent 9ae8dd93de
commit ec78173e05
10 changed files with 387 additions and 9 deletions

View File

@@ -0,0 +1,62 @@
document.addEventListener("DOMContentLoaded", function(){
let modifier_button = document.getElementsByClassName("ingr-modifier");
console.log(modifier_button);
for (const element of modifier_button) {
element.addEventListener('click', function ( e ) {
let modif = element.parentElement.previousSibling.previousSibling;
let data = e.target.getAttribute("data-id");
let form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "/ingredients/edit/" + data);
form.setAttribute("class","liste-ingr-elem-text")
let input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("class", "form-control");
input.setAttribute("name","modif_ingr");
input.setAttribute("placeholder", "modificiation");
let hidden = document.createElement("input");
hidden.setAttribute("type","hidden");
hidden.setAttribute("name","id");
hidden.setAttribute("value", data);
let button = document.createElement("button");
button.setAttribute("type", "submit");
button.setAttribute("class", "btn btn-primary");
button.innerText = "Submit Modification";
form.append(input)
form.append(hidden)
form.append(button)
modif.replaceWith(form);
});
};
let suppr = document.getElementsByClassName("ingr-suppr");
for (const element of suppr) {
element.addEventListener('click', function ( e ) {
let confirm = window.confirm("Voulez vous supprimez ?");
let data = e.target.getAttribute("data-id");
if (confirm) {
window.location.href = "/ingredients/delete/" + data;
}
})
}
});