fc324d55f5
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
99 lines
4.2 KiB
HTML
99 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>EverShelf - Réconciliation</title>
|
|
<style>
|
|
body { font-family: sans-serif; background: #222; color: #eee; padding: 20px; }
|
|
.card { background: #444; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
|
|
input, select { padding: 10px; border-radius: 5px; border: none; margin: 5px 0; width: 100%; box-sizing: border-box; }
|
|
button { padding: 10px 20px; background: #1976d2; color: white; border: none; border-radius: 5px; cursor: pointer; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="card">
|
|
<h3>Modification de produit</h3>
|
|
<select id="product-selector" onchange="updateIdField()">
|
|
<option value="">-- Choisir un produit --</option>
|
|
</select>
|
|
<input type="text" id="prod-id" readonly placeholder="ID">
|
|
<input type="text" id="prod-name" placeholder="Nom">
|
|
<select id="category-selector">
|
|
<option value="">-- Catégorie --</option>
|
|
</select>
|
|
<button onclick="saveProduct()">ENREGISTRER</button>
|
|
</div>
|
|
|
|
<script>
|
|
// 1. Charger les catégories
|
|
fetch('translations/fr.json').then(r => r.json()).then(data => {
|
|
const sel = document.getElementById('category-selector');
|
|
Object.entries(data.categories || {}).forEach(([key, val]) => {
|
|
const opt = document.createElement('option');
|
|
opt.value = key; opt.textContent = val;
|
|
sel.appendChild(opt);
|
|
});
|
|
});
|
|
|
|
// 2. Charger les produits via l'action correcte
|
|
fetch('api/index.php?action=products_list')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const sel = document.getElementById('product-selector');
|
|
// On utilise 'data' directement si c'est un tableau, ou la clé correcte
|
|
const prods = data.products || data;
|
|
prods.forEach(p => {
|
|
const opt = document.createElement('option');
|
|
opt.value = p.id;
|
|
opt.setAttribute('data-name', p.name);
|
|
opt.setAttribute('data-cat', p.category || '');
|
|
opt.textContent = p.name;
|
|
sel.appendChild(opt);
|
|
});
|
|
});
|
|
|
|
function updateIdField() {
|
|
const sel = document.getElementById('product-selector');
|
|
const opt = sel.options[sel.selectedIndex];
|
|
document.getElementById('prod-id').value = sel.value;
|
|
document.getElementById('prod-name').value = opt.getAttribute('data-name');
|
|
document.getElementById('category-selector').value = opt.getAttribute('data-cat');
|
|
}
|
|
|
|
function saveProduct() {
|
|
const data = {
|
|
id: document.getElementById('prod-id').value,
|
|
name: document.getElementById('prod-name').value,
|
|
category: document.getElementById('category-selector').value
|
|
};
|
|
|
|
console.log("Données envoyées :", data); // Vérifie ceci dans ta console F12
|
|
|
|
fetch('api/index.php?action=product_save', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(r => r.json())
|
|
.then(res => {
|
|
// Affiche tout l'objet de réponse pour voir le message d'erreur précis
|
|
console.log("RÉPONSE COMPLÈTE DE L'API :", res);
|
|
alert("Réponse reçue (voir console F12) : " + JSON.stringify(res));
|
|
})
|
|
.catch(e => console.error("Erreur réseau :", e));
|
|
}
|
|
|
|
// On utilise l'action 'product_save' identifiée par ton grep
|
|
fetch('api/index.php?action=product_save', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(r => r.json())
|
|
.then(res => alert("Réponse API : " + JSON.stringify(res)))
|
|
.catch(e => alert("Erreur : " + e));
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |