a02abce26e
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
64 lines
2.4 KiB
HTML
64 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head><meta charset="UTF-8"></head>
|
|
<body>
|
|
<select id="sel" onchange="fill()"><option value="">-- Choisir un produit --</option></select>
|
|
<input id="id" readonly placeholder="ID">
|
|
<select id="cat-sel"><option value="">-- Choisir une catégorie --</option></select>
|
|
<button onclick="save()">SAVE</button>
|
|
|
|
<script>
|
|
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 => {
|
|
fullProductList = data.inventory || data.products || data;
|
|
const sel = document.getElementById('sel');
|
|
fullProductList.forEach((p, index) => {
|
|
let opt = document.createElement('option');
|
|
opt.value = index;
|
|
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-sel').value = p.category || "";
|
|
}
|
|
|
|
function save() {
|
|
let s = document.getElementById('sel');
|
|
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)
|
|
})
|
|
.then(r => r.json())
|
|
.then(res => alert("Réponse serveur : " + JSON.stringify(res)));
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |