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
+23 -71
View File
@@ -1,87 +1,39 @@
<!DOCTYPE html>
<html lang="fr">
<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>
<html>
<body>
<div class="card">
<h3>Modification de produit</h3>
<select id="product-selector" onchange="updateIdField()">
<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>
<select id="sel" onchange="fill()"></select>
<input id="id" readonly>
<input id="cat" placeholder="Catégorie (ex: fruits)">
<button onclick="save()">SAVE</button>
<script>
// 1. Charger les catégories
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
// Charger la liste
fetch('api/index.php?action=products_list')
.then(r => r.json())
.then(data => {
console.log("DEBUG PRODUITS :", data); // Ouvre la console F12 pour voir ça !
const sel = document.getElementById('product-selector');
const prods = data.products || data;
if(Array.isArray(prods)) {
prods.forEach(p => {
const opt = document.createElement('option');
opt.value = p.id;
opt.setAttribute('data-name', p.name);
opt.setAttribute('data-cat', p.category || '');
opt.textContent = p.name;
sel.appendChild(opt);
});
}
const list = data.inventory || data.products || data;
list.forEach(p => {
let opt = document.createElement('option');
opt.value = p.id; opt.textContent = p.name;
opt.dataset.cat = p.category;
document.getElementById('sel').appendChild(opt);
});
});
function updateIdField() {
const sel = document.getElementById('product-selector');
const opt = sel.options[sel.selectedIndex];
document.getElementById('prod-id').value = sel.value;
document.getElementById('prod-name').value = opt.getAttribute('data-name');
document.getElementById('category-selector').value = opt.getAttribute('data-cat');
function fill() {
let s = document.getElementById('sel');
document.getElementById('id').value = s.value;
document.getElementById('cat').value = s.options[s.selectedIndex].dataset.cat;
}
// 3. Fonction unique de sauvegarde
function saveProduct() {
const data = {
id: document.getElementById('prod-id').value,
name: document.getElementById('prod-name').value,
category: document.getElementById('category-selector').value
};
function save() {
fetch('api/index.php?action=product_save', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
})
.then(r => r.json())
.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));
body: JSON.stringify({
id: document.getElementById('id').value,
category: document.getElementById('cat').value
})
}).then(r => r.json()).then(res => alert(JSON.stringify(res)));
}
</script>
</body>