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 17:57:44 +00:00
parent ef9c26bed6
commit f7fb4e8f33
+39 -20
View File
@@ -21,11 +21,19 @@
<div class="card"> <div class="card">
<h3>Modifier le produit</h3> <h3>Modifier le produit</h3>
<input type="text" id="prod-id" placeholder="ID du produit (ex: 123)">
<label>Sélectionner un produit existant :</label>
<select id="product-selector" onchange="updateIdField()">
<option value="">-- Choisir un produit --</option>
</select>
<input type="text" id="prod-id" placeholder="ID du produit (auto-rempli)" readonly style="background:#555;">
<input type="text" id="prod-name" placeholder="Nom du produit"> <input type="text" id="prod-name" placeholder="Nom du produit">
<select id="category-selector"> <select id="category-selector">
<option value="">-- Choisir une catégorie --</option> <option value="">-- Choisir une catégorie --</option>
</select> </select>
<button onclick="saveProduct()">Enregistrer la modification</button> <button onclick="saveProduct()">Enregistrer la modification</button>
</div> </div>
@@ -39,19 +47,17 @@
const statusText = document.getElementById('status-text'); const statusText = document.getElementById('status-text');
const debugPanel = document.getElementById('debug-panel'); const debugPanel = document.getElementById('debug-panel');
// Chargement des catégories // 1. Chargement des catégories (fr.json)
fetch('translations/fr.json') fetch('translations/fr.json')
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
const tbody = document.querySelector('#cat-table tbody'); const tbody = document.querySelector('#cat-table tbody');
const selector = document.getElementById('category-selector'); const selector = document.getElementById('category-selector');
const catData = data.categories; const catData = data.categories;
if (catData) { if (catData) {
statusText.innerText = "OK - Données chargées."; statusText.innerText = "OK - Données chargées.";
debugPanel.style.borderLeftColor = "#4ade80"; debugPanel.style.borderLeftColor = "#4ade80";
statusText.className = "status-ok"; statusText.className = "status-ok";
Object.entries(catData).forEach(([key, val]) => { Object.entries(catData).forEach(([key, val]) => {
tbody.innerHTML += `<tr><td style="border:1px solid #555; padding:8px;">${key}</td><td style="border:1px solid #555; padding:8px;">${val}</td></tr>`; tbody.innerHTML += `<tr><td style="border:1px solid #555; padding:8px;">${key}</td><td style="border:1px solid #555; padding:8px;">${val}</td></tr>`;
const opt = document.createElement('option'); const opt = document.createElement('option');
@@ -60,27 +66,40 @@
selector.appendChild(opt); selector.appendChild(opt);
}); });
} }
})
.catch(err => {
statusText.innerText = "ERREUR : " + err.message;
debugPanel.style.borderLeftColor = "#f87171";
}); });
// Fonction d'enregistrement // 2. Chargement des produits pour la liste déroulante
fetch('api/index.php?action=list_products')
.then(res => res.json())
.then(data => {
const selector = document.getElementById('product-selector');
data.products.forEach(prod => {
const opt = document.createElement('option');
opt.value = prod.id;
opt.setAttribute('data-name', prod.name);
opt.textContent = prod.name;
selector.appendChild(opt);
});
});
// 3. Auto-remplissage
function updateIdField() {
const selector = document.getElementById('product-selector');
const idField = document.getElementById('prod-id');
const nameField = document.getElementById('prod-name');
idField.value = selector.value;
const selectedOption = selector.options[selector.selectedIndex];
nameField.value = selectedOption.getAttribute('data-name') || '';
}
// 4. Enregistrement
function saveProduct() { function saveProduct() {
const idEl = document.getElementById('prod-id');
const nameEl = document.getElementById('prod-name');
const catEl = document.getElementById('category-selector');
if (!idEl.value) return alert("Veuillez entrer un ID de produit.");
const data = { const data = {
id: idEl.value, id: document.getElementById('prod-id').value,
name: nameEl.value, name: document.getElementById('prod-name').value,
category: catEl.value category: document.getElementById('category-selector').value
}; };
// Remplace 'product_edit' par l'action confirmée dans ton onglet Réseau
fetch('api/index.php?action=product_edit', { fetch('api/index.php?action=product_edit', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
@@ -89,7 +108,7 @@
.then(r => r.json()) .then(r => r.json())
.then(res => { .then(res => {
console.log("Réponse API :", res); console.log("Réponse API :", res);
alert("Action effectuée. Voir la console pour les détails."); alert("Action effectuée. Vérifiez la console F12.");
}) })
.catch(e => alert("Erreur : " + e)); .catch(e => alert("Erreur : " + e));
} }