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:28:50 +00:00
parent 79d1ca06c7
commit a02abce26e
+24 -12
View File
@@ -1,17 +1,30 @@
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"></head>
<body>
<select id="sel" onchange="fill()">
<option value="">-- Choisir un produit --</option>
</select>
<select id="sel" onchange="fill()"><option value="">-- Choisir un produit --</option></select>
<input id="id" readonly placeholder="ID">
<input id="cat" placeholder="Catégorie">
<select id="cat-sel"><option value="">-- Choisir une catégorie --</option></select>
<button onclick="save()">SAVE</button>
<script>
// Variable pour stocker les données complètes des produits
let fullProductList = [];
let categories = {};
// 1. Charger les catégories en français
fetch('translations/fr.json')
.then(r => r.json())
.then(data => {
categories = data.categories || {};
const catSel = document.getElementById('cat-sel');
Object.entries(categories).forEach(([key, val]) => {
let opt = document.createElement('option');
opt.value = key; opt.textContent = val;
catSel.appendChild(opt);
});
});
// 2. Charger les produits
fetch('api/index.php?action=products_list')
.then(r => r.json())
.then(data => {
@@ -19,7 +32,7 @@
const sel = document.getElementById('sel');
fullProductList.forEach((p, index) => {
let opt = document.createElement('option');
opt.value = index; // On utilise l'index du tableau
opt.value = index;
opt.textContent = p.name;
sel.appendChild(opt);
});
@@ -29,20 +42,19 @@
let s = document.getElementById('sel');
let p = fullProductList[s.value];
document.getElementById('id').value = p.id;
document.getElementById('cat').value = p.category || "";
document.getElementById('cat-sel').value = p.category || "";
}
function save() {
let s = document.getElementById('sel');
let p = fullProductList[s.value]; // On récupère l'objet complet
// On met à jour uniquement la catégorie dans l'objet original
p.category = document.getElementById('cat').value;
let p = fullProductList[s.value];
// On met à jour avec la clé sélectionnée dans le menu déroulant
p.category = document.getElementById('cat-sel').value;
fetch('api/index.php?action=product_save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(p) // On renvoie TOUT l'objet produit
body: JSON.stringify(p)
})
.then(r => r.json())
.then(res => alert("Réponse serveur : " + JSON.stringify(res)));