From 57ec6af58cda7d995aa13f7e36fa43027fc3c9dd Mon Sep 17 00:00:00 2001 From: morgane Date: Wed, 17 Jun 2026 19:35:18 +0000 Subject: [PATCH] Actualiser test.html --- test.html | 89 +++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/test.html b/test.html index b722e61..112b60b 100644 --- a/test.html +++ b/test.html @@ -5,24 +5,23 @@
-

Modification de produit

- - - - +

Modification en masse

+ +
- + + +
ProduitCatégorieEmplacement
ProduitCatégorieEmplacement
@@ -30,7 +29,7 @@ let fullProductList = []; let categories = {}; - // 1. Initialisation : Chargement des catégories et des produits + // Chargement initial Promise.all([ fetch('translations/fr.json').then(r => r.json()), fetch('api/index.php?action=products_list').then(r => r.json()) @@ -38,59 +37,53 @@ categories = trans.categories || {}; fullProductList = prods.inventory || prods.products || prods; - // Remplir le select de modif - const sel = document.getElementById('sel'); - const catSel = document.getElementById('cat-sel'); - + const catSel = document.getElementById('cat-mass'); Object.entries(categories).forEach(([key, val]) => { let opt = document.createElement('option'); opt.value = key; opt.textContent = val; catSel.appendChild(opt); }); - - fullProductList.forEach((p, index) => { - let opt = document.createElement('option'); - opt.value = index; - opt.textContent = p.name; - sel.appendChild(opt); - }); - renderTable(); }); function renderTable() { const tbody = document.querySelector('#prod-table tbody'); tbody.innerHTML = ""; - fullProductList.forEach(p => { - let row = ` - ${p.name} - ${categories[p.category] || p.category} - ${p.location || 'N/A'} - `; - tbody.innerHTML += row; + fullProductList.forEach((p, index) => { + let row = document.createElement('tr'); + row.innerHTML = ` + ${p.name} + ${categories[p.category] || p.category} + ${p.location || 'N/A'}`; + tbody.appendChild(row); }); } - function fill() { - let s = document.getElementById('sel'); - let p = fullProductList[s.value]; - document.getElementById('id').value = p.id; - document.getElementById('cat-sel').value = p.category || ""; + function toggleAll(source) { + document.querySelectorAll('.prod-check').forEach(c => c.checked = source.checked); } - function save() { - let s = document.getElementById('sel'); - let p = fullProductList[s.value]; - p.category = document.getElementById('cat-sel').value; - - fetch('api/index.php?action=product_save', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(p) - }).then(() => { - renderTable(); // Rafraîchit le tableau immédiatement - alert("Modifié avec succès !"); - }); + async function applyToSelected() { + const newCat = document.getElementById('cat-mass').value; + if(!newCat) return alert("Sélectionne une catégorie !"); + + const checkedBoxes = document.querySelectorAll('.prod-check:checked'); + + // On traite chaque produit coché + for (const checkbox of checkedBoxes) { + let p = fullProductList[checkbox.dataset.index]; + p.category = newCat; + + // Envoi à l'API + await fetch('api/index.php?action=product_save', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(p) + }); + } + + alert("Traitement terminé !"); + renderTable(); }