Actualiser test.html
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled

This commit is contained in:
2026-06-17 19:46:28 +00:00
parent 6e532ebdd1
commit b8e43388b6
+17 -16
View File
@@ -37,14 +37,14 @@
let fullProductList = [];
let categories = {};
// Chargement initial
function loadData() {
return Promise.all([
fetch('translations/fr.json').then(r => r.json()),
fetch('api/index.php?action=products_list').then(r => r.json())
]).then(([trans, prods]) => {
categories = trans.categories || {};
fullProductList = prods.inventory || prods.products || prods;
async function loadData() {
try {
const [transRes, prodsRes] = await Promise.all([
fetch('translations/fr.json').then(r => r.json()),
fetch('api/index.php?action=products_list').then(r => r.json())
]);
categories = transRes.categories || {};
fullProductList = prodsRes.inventory || prodsRes.products || prodsRes;
const catSel = document.getElementById('cat-mass');
catSel.innerHTML = '<option value="">-- Choisir nouvelle catégorie --</option>';
@@ -54,7 +54,7 @@
catSel.appendChild(opt);
});
renderTable();
});
} catch (e) { console.error("Erreur chargement:", e); }
}
loadData();
@@ -78,7 +78,7 @@
async function applyToSelected() {
const newCat = document.getElementById('cat-mass').value;
if(!newCat) return alert("Sélectionne une catégorie d'abord !");
if(!newCat) return alert("Sélectionne une catégorie !");
const checkedBoxes = document.querySelectorAll('.prod-check:checked');
if(checkedBoxes.length === 0) return alert("Coche des produits !");
@@ -88,23 +88,24 @@
btn.textContent = "Traitement en cours...";
for (const checkbox of checkedBoxes) {
let p = fullProductList[checkbox.dataset.index];
// On crée une COPIE de l'objet pour ne pas modifier la référence originale par erreur
let p = { ...fullProductList[checkbox.dataset.index] };
p.category = newCat;
try {
await fetch('api/index.php?action=product_save', {
let res = await fetch('api/index.php?action=product_save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(p)
});
// Pause de 250ms pour laisser le serveur souffler
await new Promise(r => setTimeout(r, 250));
if (!res.ok) console.error("Erreur serveur sur " + p.name);
await new Promise(r => setTimeout(r, 200));
} catch (e) {
console.error("Erreur sur " + p.name, e);
console.error("Erreur réseau sur " + p.name, e);
}
}
// Rechargement total pour synchroniser l'affichage
await loadData();
btn.disabled = false;
btn.textContent = "APPLIQUER AUX COCHÉS";