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:25:55 +00:00
parent 0ca4df0d27
commit d1ba63d9a0
+21 -69
View File
@@ -1,87 +1,39 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html>
<head>
<meta charset="UTF-8">
<title>EverShelf - Réconciliation</title>
<style>
body { font-family: sans-serif; background: #222; color: #eee; padding: 20px; }
.card { background: #444; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
input, select { padding: 10px; border-radius: 5px; border: none; margin: 5px 0; width: 100%; box-sizing: border-box; }
button { padding: 10px 20px; background: #1976d2; color: white; border: none; border-radius: 5px; cursor: pointer; }
</style>
</head>
<body> <body>
<select id="sel" onchange="fill()"></select>
<div class="card"> <input id="id" readonly>
<h3>Modification de produit</h3> <input id="cat" placeholder="Catégorie (ex: fruits)">
<select id="product-selector" onchange="updateIdField()"> <button onclick="save()">SAVE</button>
<option value="">-- Choisir un produit --</option>
</select>
<input type="text" id="prod-id" readonly placeholder="ID">
<input type="text" id="prod-name" placeholder="Nom">
<select id="category-selector">
<option value="">-- Catégorie --</option>
</select>
<button onclick="saveProduct()">ENREGISTRER</button>
</div>
<script> <script>
// 1. Charger les catégories // Charger la liste
fetch('translations/fr.json').then(r => r.json()).then(data => {
const sel = document.getElementById('category-selector');
Object.entries(data.categories || {}).forEach(([key, val]) => {
const opt = document.createElement('option');
opt.value = key; opt.textContent = val;
sel.appendChild(opt);
});
});
// 2. Charger les produits
fetch('api/index.php?action=products_list') fetch('api/index.php?action=products_list')
.then(r => r.json()) .then(r => r.json())
.then(data => { .then(data => {
console.log("DEBUG PRODUITS :", data); // Ouvre la console F12 pour voir ça ! const list = data.inventory || data.products || data;
const sel = document.getElementById('product-selector'); list.forEach(p => {
const prods = data.products || data; let opt = document.createElement('option');
if(Array.isArray(prods)) { opt.value = p.id; opt.textContent = p.name;
prods.forEach(p => { opt.dataset.cat = p.category;
const opt = document.createElement('option'); document.getElementById('sel').appendChild(opt);
opt.value = p.id;
opt.setAttribute('data-name', p.name);
opt.setAttribute('data-cat', p.category || '');
opt.textContent = p.name;
sel.appendChild(opt);
}); });
}
}); });
function updateIdField() { function fill() {
const sel = document.getElementById('product-selector'); let s = document.getElementById('sel');
const opt = sel.options[sel.selectedIndex]; document.getElementById('id').value = s.value;
document.getElementById('prod-id').value = sel.value; document.getElementById('cat').value = s.options[s.selectedIndex].dataset.cat;
document.getElementById('prod-name').value = opt.getAttribute('data-name');
document.getElementById('category-selector').value = opt.getAttribute('data-cat');
} }
// 3. Fonction unique de sauvegarde function save() {
function saveProduct() {
const data = {
id: document.getElementById('prod-id').value,
name: document.getElementById('prod-name').value,
category: document.getElementById('category-selector').value
};
fetch('api/index.php?action=product_save', { fetch('api/index.php?action=product_save', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, body: JSON.stringify({
body: JSON.stringify(data) id: document.getElementById('id').value,
category: document.getElementById('cat').value
}) })
.then(r => r.json()) }).then(r => r.json()).then(res => alert(JSON.stringify(res)));
.then(res => {
console.log("RÉPONSE API :", res);
alert("Réponse reçue. Regarde la console (F12) pour le détail.");
})
.catch(e => console.error("Erreur :", e));
} }
</script> </script>
</body> </body>