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
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:
@@ -1,17 +1,30 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
<head><meta charset="UTF-8"></head>
|
||||||
<body>
|
<body>
|
||||||
<select id="sel" onchange="fill()">
|
<select id="sel" onchange="fill()"><option value="">-- Choisir un produit --</option></select>
|
||||||
<option value="">-- Choisir un produit --</option>
|
|
||||||
</select>
|
|
||||||
<input id="id" readonly placeholder="ID">
|
<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>
|
<button onclick="save()">SAVE</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Variable pour stocker les données complètes des produits
|
|
||||||
let fullProductList = [];
|
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')
|
fetch('api/index.php?action=products_list')
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@@ -19,7 +32,7 @@
|
|||||||
const sel = document.getElementById('sel');
|
const sel = document.getElementById('sel');
|
||||||
fullProductList.forEach((p, index) => {
|
fullProductList.forEach((p, index) => {
|
||||||
let opt = document.createElement('option');
|
let opt = document.createElement('option');
|
||||||
opt.value = index; // On utilise l'index du tableau
|
opt.value = index;
|
||||||
opt.textContent = p.name;
|
opt.textContent = p.name;
|
||||||
sel.appendChild(opt);
|
sel.appendChild(opt);
|
||||||
});
|
});
|
||||||
@@ -29,20 +42,19 @@
|
|||||||
let s = document.getElementById('sel');
|
let s = document.getElementById('sel');
|
||||||
let p = fullProductList[s.value];
|
let p = fullProductList[s.value];
|
||||||
document.getElementById('id').value = p.id;
|
document.getElementById('id').value = p.id;
|
||||||
document.getElementById('cat').value = p.category || "";
|
document.getElementById('cat-sel').value = p.category || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
let s = document.getElementById('sel');
|
let s = document.getElementById('sel');
|
||||||
let p = fullProductList[s.value]; // On récupère l'objet complet
|
let p = fullProductList[s.value];
|
||||||
|
// On met à jour avec la clé sélectionnée dans le menu déroulant
|
||||||
// On met à jour uniquement la catégorie dans l'objet original
|
p.category = document.getElementById('cat-sel').value;
|
||||||
p.category = document.getElementById('cat').value;
|
|
||||||
|
|
||||||
fetch('api/index.php?action=product_save', {
|
fetch('api/index.php?action=product_save', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(p) // On renvoie TOUT l'objet produit
|
body: JSON.stringify(p)
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(res => alert("Réponse serveur : " + JSON.stringify(res)));
|
.then(res => alert("Réponse serveur : " + JSON.stringify(res)));
|
||||||
|
|||||||
Reference in New Issue
Block a user