V1 avec bugs
This commit is contained in:
62
public/assets/js/manage-ingredients.js
Normal file
62
public/assets/js/manage-ingredients.js
Normal 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;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user