79d1ca06c7
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
52 lines
1.9 KiB
HTML
52 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
<select id="sel" onchange="fill()">
|
|
<option value="">-- Choisir un produit --</option>
|
|
</select>
|
|
<input id="id" readonly placeholder="ID">
|
|
<input id="cat" placeholder="Catégorie">
|
|
<button onclick="save()">SAVE</button>
|
|
|
|
<script>
|
|
// Variable pour stocker les données complètes des produits
|
|
let fullProductList = [];
|
|
|
|
fetch('api/index.php?action=products_list')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
fullProductList = data.inventory || data.products || data;
|
|
const sel = document.getElementById('sel');
|
|
fullProductList.forEach((p, index) => {
|
|
let opt = document.createElement('option');
|
|
opt.value = index; // On utilise l'index du tableau
|
|
opt.textContent = p.name;
|
|
sel.appendChild(opt);
|
|
});
|
|
});
|
|
|
|
function fill() {
|
|
let s = document.getElementById('sel');
|
|
let p = fullProductList[s.value];
|
|
document.getElementById('id').value = p.id;
|
|
document.getElementById('cat').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;
|
|
|
|
fetch('api/index.php?action=product_save', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(p) // On renvoie TOUT l'objet produit
|
|
})
|
|
.then(r => r.json())
|
|
.then(res => alert("Réponse serveur : " + JSON.stringify(res)));
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |