From f7fb4e8f33ed079ffb89acd1376c76c952904c0b Mon Sep 17 00:00:00 2001 From: morgane Date: Wed, 17 Jun 2026 17:57:44 +0000 Subject: [PATCH] Actualiser test.html --- test.html | 59 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/test.html b/test.html index e3090ef..e0f98eb 100644 --- a/test.html +++ b/test.html @@ -21,11 +21,19 @@

Modifier le produit

- + + + + + + +
@@ -39,19 +47,17 @@ const statusText = document.getElementById('status-text'); const debugPanel = document.getElementById('debug-panel'); - // Chargement des catégories + // 1. Chargement des catégories (fr.json) fetch('translations/fr.json') .then(res => res.json()) .then(data => { const tbody = document.querySelector('#cat-table tbody'); const selector = document.getElementById('category-selector'); const catData = data.categories; - if (catData) { statusText.innerText = "OK - Données chargées."; debugPanel.style.borderLeftColor = "#4ade80"; statusText.className = "status-ok"; - Object.entries(catData).forEach(([key, val]) => { tbody.innerHTML += `${key}${val}`; const opt = document.createElement('option'); @@ -60,27 +66,40 @@ selector.appendChild(opt); }); } - }) - .catch(err => { - statusText.innerText = "ERREUR : " + err.message; - debugPanel.style.borderLeftColor = "#f87171"; }); - // Fonction d'enregistrement + // 2. Chargement des produits pour la liste déroulante + fetch('api/index.php?action=list_products') + .then(res => res.json()) + .then(data => { + const selector = document.getElementById('product-selector'); + data.products.forEach(prod => { + const opt = document.createElement('option'); + opt.value = prod.id; + opt.setAttribute('data-name', prod.name); + opt.textContent = prod.name; + selector.appendChild(opt); + }); + }); + + // 3. Auto-remplissage + function updateIdField() { + const selector = document.getElementById('product-selector'); + const idField = document.getElementById('prod-id'); + const nameField = document.getElementById('prod-name'); + idField.value = selector.value; + const selectedOption = selector.options[selector.selectedIndex]; + nameField.value = selectedOption.getAttribute('data-name') || ''; + } + + // 4. Enregistrement function saveProduct() { - const idEl = document.getElementById('prod-id'); - const nameEl = document.getElementById('prod-name'); - const catEl = document.getElementById('category-selector'); - - if (!idEl.value) return alert("Veuillez entrer un ID de produit."); - const data = { - id: idEl.value, - name: nameEl.value, - category: catEl.value + id: document.getElementById('prod-id').value, + name: document.getElementById('prod-name').value, + category: document.getElementById('category-selector').value }; - // Remplace 'product_edit' par l'action confirmée dans ton onglet Réseau fetch('api/index.php?action=product_edit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -89,7 +108,7 @@ .then(r => r.json()) .then(res => { console.log("Réponse API :", res); - alert("Action effectuée. Voir la console pour les détails."); + alert("Action effectuée. Vérifiez la console F12."); }) .catch(e => alert("Erreur : " + e)); }