diff --git a/test.html b/test.html index 02c7754..ece87e1 100644 --- a/test.html +++ b/test.html @@ -82,7 +82,7 @@ document.getElementById('prod-name').value = sel.options[sel.selectedIndex].getAttribute('data-name'); } - function saveProduct() { + function Product() { const data = { id: document.getElementById('prod-id').value, name: document.getElementById('prod-name').value, @@ -94,6 +94,32 @@ body: JSON.stringify(data) }).then(r => r.json()).then(res => alert(JSON.stringify(res))); } + function saveChanges() { + const data = { + id: document.getElementById('edit-id').value, + name: document.getElementById('edit-name').value, + category: document.getElementById('edit-category').value + }; + + // On utilise l'action la plus probable pour une mise à jour d'entité + // Si 'product_edit' ne marche pas, essaie 'ha_update_product' + // ou regarde le switch dans api/index.php + fetch('api/index.php?action=product_edit', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(data) + }) + .then(r => r.json()) + .then(res => { + if(res.error) { + alert("Erreur API : " + res.error); + } else { + alert("Produit mis à jour avec succès !"); + loadInventory(); // Recharge la grille + } + }) + .catch(e => console.error("Erreur de connexion:", e)); + } \ No newline at end of file