d1ba63d9a0
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
40 lines
1.4 KiB
HTML
40 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
<select id="sel" onchange="fill()"></select>
|
|
<input id="id" readonly>
|
|
<input id="cat" placeholder="Catégorie (ex: fruits)">
|
|
<button onclick="save()">SAVE</button>
|
|
|
|
<script>
|
|
// Charger la liste
|
|
fetch('api/index.php?action=products_list')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const list = data.inventory || data.products || data;
|
|
list.forEach(p => {
|
|
let opt = document.createElement('option');
|
|
opt.value = p.id; opt.textContent = p.name;
|
|
opt.dataset.cat = p.category;
|
|
document.getElementById('sel').appendChild(opt);
|
|
});
|
|
});
|
|
|
|
function fill() {
|
|
let s = document.getElementById('sel');
|
|
document.getElementById('id').value = s.value;
|
|
document.getElementById('cat').value = s.options[s.selectedIndex].dataset.cat;
|
|
}
|
|
|
|
function save() {
|
|
fetch('api/index.php?action=product_save', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
id: document.getElementById('id').value,
|
|
category: document.getElementById('cat').value
|
|
})
|
|
}).then(r => r.json()).then(res => alert(JSON.stringify(res)));
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |