Files
EverShelf/test.html
T
morgane 57ec6af58c
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
Actualiser test.html
2026-06-17 19:35:18 +00:00

90 lines
3.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: sans-serif; background: #222; color: #eee; padding: 20px; }
.card { background: #444; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; background: #333; }
th, td { border: 1px solid #555; padding: 8px; text-align: left; }
.selected { background: #1e3a8a; } /* Couleur pour les lignes sélectionnées */
</style>
</head>
<body>
<div class="card">
<h3>Modification en masse</h3>
<select id="cat-mass"><option value="">-- Choisir nouvelle catégorie --</option></select>
<button onclick="applyToSelected()">APPLIQUER AUX COCHÉS</button>
</div>
<table id="prod-table">
<thead>
<tr><th><input type="checkbox" onclick="toggleAll(this)"></th><th>Produit</th><th>Catégorie</th><th>Emplacement</th></tr>
</thead>
<tbody></tbody>
</table>
<script>
let fullProductList = [];
let categories = {};
// Chargement initial
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;
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);
});
renderTable();
});
function renderTable() {
const tbody = document.querySelector('#prod-table tbody');
tbody.innerHTML = "";
fullProductList.forEach((p, index) => {
let row = document.createElement('tr');
row.innerHTML = `<td><input type="checkbox" class="prod-check" data-index="${index}"></td>
<td>${p.name}</td>
<td>${categories[p.category] || p.category}</td>
<td>${p.location || 'N/A'}</td>`;
tbody.appendChild(row);
});
}
function toggleAll(source) {
document.querySelectorAll('.prod-check').forEach(c => c.checked = source.checked);
}
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();
}
</script>
</body>
</html>