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:
@@ -18,7 +18,7 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>Modification en masse</h3>
|
<h3>Modification en masse</h3>
|
||||||
<select id="cat-mass"><option value="">-- Choisir nouvelle catégorie --</option></select>
|
<select id="cat-mass"><option value="">-- Choisir nouvelle catégorie --</option></select>
|
||||||
<button onclick="applyToSelected()">APPLIQUER AUX COCHÉS</button>
|
<button id="save-btn" onclick="applyToSelected()">APPLIQUER AUX COCHÉS</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table id="prod-table">
|
<table id="prod-table">
|
||||||
@@ -37,24 +37,28 @@
|
|||||||
let fullProductList = [];
|
let fullProductList = [];
|
||||||
let categories = {};
|
let categories = {};
|
||||||
|
|
||||||
// 1. Initialisation : Chargement des données
|
// Chargement initial
|
||||||
Promise.all([
|
function loadData() {
|
||||||
fetch('translations/fr.json').then(r => r.json()),
|
return Promise.all([
|
||||||
fetch('api/index.php?action=products_list').then(r => r.json())
|
fetch('translations/fr.json').then(r => r.json()),
|
||||||
]).then(([trans, prods]) => {
|
fetch('api/index.php?action=products_list').then(r => r.json())
|
||||||
categories = trans.categories || {};
|
]).then(([trans, prods]) => {
|
||||||
fullProductList = prods.inventory || prods.products || prods;
|
categories = trans.categories || {};
|
||||||
|
fullProductList = prods.inventory || prods.products || prods;
|
||||||
|
|
||||||
const catSel = document.getElementById('cat-mass');
|
const catSel = document.getElementById('cat-mass');
|
||||||
Object.entries(categories).forEach(([key, val]) => {
|
catSel.innerHTML = '<option value="">-- Choisir nouvelle catégorie --</option>';
|
||||||
let opt = document.createElement('option');
|
Object.entries(categories).forEach(([key, val]) => {
|
||||||
opt.value = key; opt.textContent = val;
|
let opt = document.createElement('option');
|
||||||
catSel.appendChild(opt);
|
opt.value = key; opt.textContent = val;
|
||||||
|
catSel.appendChild(opt);
|
||||||
|
});
|
||||||
|
renderTable();
|
||||||
});
|
});
|
||||||
renderTable();
|
}
|
||||||
});
|
|
||||||
|
loadData();
|
||||||
|
|
||||||
// 2. Affichage du tableau
|
|
||||||
function renderTable() {
|
function renderTable() {
|
||||||
const tbody = document.querySelector('#prod-table tbody');
|
const tbody = document.querySelector('#prod-table tbody');
|
||||||
tbody.innerHTML = "";
|
tbody.innerHTML = "";
|
||||||
@@ -72,7 +76,6 @@
|
|||||||
document.querySelectorAll('.prod-check').forEach(c => c.checked = source.checked);
|
document.querySelectorAll('.prod-check').forEach(c => c.checked = source.checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Sauvegarde en masse
|
|
||||||
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 d'abord !");
|
||||||
@@ -80,24 +83,32 @@
|
|||||||
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 !");
|
||||||
|
|
||||||
|
const btn = document.getElementById('save-btn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = "Traitement en cours...";
|
||||||
|
|
||||||
for (const checkbox of checkedBoxes) {
|
for (const checkbox of checkedBoxes) {
|
||||||
let p = fullProductList[checkbox.dataset.index];
|
let p = fullProductList[checkbox.dataset.index];
|
||||||
p.category = newCat;
|
p.category = newCat;
|
||||||
|
|
||||||
console.log("Envoi au serveur :", JSON.stringify(p)); // <--- Affiche ce qui est envoyé
|
try {
|
||||||
|
await fetch('api/index.php?action=product_save', {
|
||||||
let response = 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));
|
||||||
let result = await response.json();
|
} catch (e) {
|
||||||
console.log("Résultat serveur :", result); // <--- Affiche ce que le serveur répond
|
console.error("Erreur sur " + p.name, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alert("Traitement terminé. Regarde la console (F12) pour voir si le serveur a validé.");
|
// Rechargement total pour synchroniser l'affichage
|
||||||
renderTable(); // Recharge l'affichage
|
await loadData();
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.textContent = "APPLIQUER AUX COCHÉS";
|
||||||
|
alert("Traitement terminé.");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user