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
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:
@@ -37,14 +37,14 @@
|
|||||||
let fullProductList = [];
|
let fullProductList = [];
|
||||||
let categories = {};
|
let categories = {};
|
||||||
|
|
||||||
// Chargement initial
|
async function loadData() {
|
||||||
function loadData() {
|
try {
|
||||||
return Promise.all([
|
const [transRes, prodsRes] = await Promise.all([
|
||||||
fetch('translations/fr.json').then(r => r.json()),
|
fetch('translations/fr.json').then(r => r.json()),
|
||||||
fetch('api/index.php?action=products_list').then(r => r.json())
|
fetch('api/index.php?action=products_list').then(r => r.json())
|
||||||
]).then(([trans, prods]) => {
|
]);
|
||||||
categories = trans.categories || {};
|
categories = transRes.categories || {};
|
||||||
fullProductList = prods.inventory || prods.products || prods;
|
fullProductList = prodsRes.inventory || prodsRes.products || prodsRes;
|
||||||
|
|
||||||
const catSel = document.getElementById('cat-mass');
|
const catSel = document.getElementById('cat-mass');
|
||||||
catSel.innerHTML = '<option value="">-- Choisir nouvelle catégorie --</option>';
|
catSel.innerHTML = '<option value="">-- Choisir nouvelle catégorie --</option>';
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
catSel.appendChild(opt);
|
catSel.appendChild(opt);
|
||||||
});
|
});
|
||||||
renderTable();
|
renderTable();
|
||||||
});
|
} catch (e) { console.error("Erreur chargement:", e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData();
|
loadData();
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
|
|
||||||
async function applyToSelected() {
|
async function applyToSelected() {
|
||||||
const newCat = document.getElementById('cat-mass').value;
|
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');
|
const checkedBoxes = document.querySelectorAll('.prod-check:checked');
|
||||||
if(checkedBoxes.length === 0) return alert("Coche des produits !");
|
if(checkedBoxes.length === 0) return alert("Coche des produits !");
|
||||||
@@ -88,23 +88,24 @@
|
|||||||
btn.textContent = "Traitement en cours...";
|
btn.textContent = "Traitement en cours...";
|
||||||
|
|
||||||
for (const checkbox of checkedBoxes) {
|
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;
|
p.category = newCat;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch('api/index.php?action=product_save', {
|
let res = await fetch('api/index.php?action=product_save', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(p)
|
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) {
|
} 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();
|
await loadData();
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.textContent = "APPLIQUER AUX COCHÉS";
|
btn.textContent = "APPLIQUER AUX COCHÉS";
|
||||||
|
|||||||
Reference in New Issue
Block a user