Modification produit
This commit is contained in:
@@ -197,6 +197,67 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
location.reload()
|
||||
})
|
||||
|
||||
// --------------------------- Modification produit --------------------------
|
||||
const produitModifTitles = document.querySelectorAll(".produitModifTitre");
|
||||
const modalModifProduit = new bootstrap.Modal($("modifierProduitModal"));
|
||||
produitModifTitles.forEach(title => {
|
||||
title.addEventListener("click", function () {
|
||||
const idProduit = this.dataset.idproduit;
|
||||
fetch(`/gestion-produit/detailProduit/${idProduit}/`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
$("modifIdProduit").value = data.detailId;
|
||||
$("modifLibelle").value = data.detailLibelle;
|
||||
$("modifQuantiteStock").value = data.detailQuantiteStock;
|
||||
$("modifSeuilPreRupture").value = data.detailSeuilPreRupture;
|
||||
|
||||
$("modifCondi").value = data.detailConditionnement;
|
||||
|
||||
$("modifCategorie").innerHTML = "";
|
||||
data.listeCategorie.forEach(categorie => {
|
||||
const option = document.createElement("option");
|
||||
option.value = categorie.id;
|
||||
option.text = categorie.categorie;
|
||||
if(categorie.id === data.detailCategorie){
|
||||
option.selected = true;
|
||||
}
|
||||
$("modifCategorie").appendChild(option);
|
||||
});
|
||||
|
||||
modalModifProduit.show();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("modification-produit").addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
const form = this;
|
||||
const url = this.dataset.url;
|
||||
const csrf = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers:{
|
||||
"X-Requested-With": "XMLHttpResponse",
|
||||
"X-CSRFToken": csrf
|
||||
},
|
||||
body: new FormData(form)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if(data.success){
|
||||
const messageBox = $("messageZone");
|
||||
messageBox.innerHTML = `
|
||||
<div class="alert alert-success">
|
||||
Produit modifié avec succès
|
||||
</div>
|
||||
`;
|
||||
modalModifProduit.hide();
|
||||
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// --------------------------- Gestion des categories -------------------------
|
||||
const url_liste_categorie = $("listecategorie").dataset.url;
|
||||
const tableau_categorie = new Tabulator("#listecategorie", {
|
||||
|
||||
Reference in New Issue
Block a user