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

This commit is contained in:
2026-06-17 17:25:31 +00:00
parent 257fa4797d
commit 450095376c
+61 -58
View File
@@ -2,77 +2,80 @@
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>⚡ Sandbox - Test Récupération ID</title> <title>⚡ Sandbox - Récupération Dynamique</title>
<style> <style>
body { font-family: sans-serif; background: #333; color: #fff; padding: 50px; } body { font-family: sans-serif; background: #333; padding: 50px; color: white; }
.modal-preview { background: #fff; color: #000; padding: 20px; border-radius: 12px; width: 500px; margin: 0 auto; box-shadow: 0 4px 15px rgba(0,0,0,0.5); } .modal { background: white; padding: 20px; border-radius: 12px; width: 400px; margin: 0 auto; color: black; box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
.button-container { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; gap: 8px; } .debug-panel { margin-top: 20px; padding: 15px; background: #222; border-radius: 8px; border: 1px solid #444; font-size: 12px; }
.btn { padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; margin: 5px; font-weight: bold; }
.btn { padding: 12px; border-radius: 8px; border: none; font-weight: bold; cursor: pointer; flex: 1; text-align: center; text-decoration: none; } .btn-blue { background: #1976d2; color: white; }
.btn-success { background-color: #2e7d32; color: white; }
.btn-danger { background-color: #d32f2f; color: white; }
.btn-purple { background-color: #7b1fa2; color: white; }
.btn-catalog-shortcut { background-color: #1976d2; color: white; font-size: 11px; }
</style> </style>
</head> </head>
<body> <body>
<h2 style="text-align: center;">Test de Capture d'attribut HTML</h2> <div class="modal" id="app-container">
<h3>Produit : Jus Ananas</h3>
<p>Catégorie actuelle : <b>Boissons</b></p>
<button class="btn btn-blue" onclick="initForm()">✏️ Modifier la catégorie</button>
</div>
<div class="modal-preview"> <div class="debug-panel">
<h3>Jus ananas</h3> <strong>Debug - État :</strong>
<p>Emplacement : 🍷 Cave</p> <pre id="debug-log">Prêt à charger les données...</pre>
<div class="button-container">
<button class="btn btn-danger">Utiliser</button>
<button class="btn btn-success" data-id="145">Modifier</button>
<button class="btn btn-purple">Recette</button>
</div>
</div> </div>
<script> <script>
// 1. Fonction qui affiche le formulaire let GLOBAL_CATEGORY_LABELS = {};
function mockEditProduct(id) {
// 1. On va chercher les catégories directement dans la mémoire de l'appli. // 1. Récupération dynamique depuis le fichier source de l'app
// Si 'categories' n'est pas définie, on prévoit une liste de secours. async function fetchCategories() {
const appCategories = (typeof categories !== 'undefined') ? categories : ["Fruits", "Légumes", "Boissons", "Épicerie", "Surgelés"]; try {
const response = await fetch('/assets/js/app.js');
// 2. On construit les options dynamiquement const text = await response.text();
let optionsHTML = appCategories.map(cat => `<option value="${cat}">${cat}</option>`).join('');
// Extrait le bloc CATEGORY_LABELS du fichier app.js
const container = document.querySelector('.modal-preview'); const match = text.match(/const CATEGORY_LABELS = ({[\s\S]*?});/);
if (match) {
// Nettoyage et conversion en objet JS
const jsonStr = match[1].replace(/(\w+):/g, '"$1":'); // Ajoute des guillemets aux clés
GLOBAL_CATEGORY_LABELS = JSON.parse(jsonStr);
document.getElementById('debug-log').innerText = "Succès : " + Object.keys(GLOBAL_CATEGORY_LABELS).length + " catégories chargées.";
return true;
}
} catch (e) {
document.getElementById('debug-log').innerText = "Erreur : Impossible de lire app.js (" + e.message + ")";
}
return false;
}
// 2. Initialisation du formulaire
async function initForm() {
const loaded = await fetchCategories();
if (!loaded) return;
const container = document.getElementById('app-container');
const entries = Object.entries(GLOBAL_CATEGORY_LABELS);
container.innerHTML = ` container.innerHTML = `
<h3>Modification du produit #${id}</h3> <h3>Changer la catégorie</h3>
<form onsubmit="event.preventDefault(); alert('Catégorie ' + document.getElementById('cat-select').value + ' appliquée !'); location.reload();"> <select id="cat-select" style="width:100%; padding:10px; margin: 10px 0;">
<label>Catégories EverShelf :</label><br> ${entries.map(([key, label]) => `<option value="${key}">${label}</option>`).join('')}
<select id="cat-select" style="width:100%; padding:8px; margin: 10px 0;"> </select>
${optionsHTML} <br>
</select> <button class="btn btn-blue" onclick="save()">Enregistrer</button>
<br> <button class="btn" onclick="location.reload()">Annuler</button>
<button type="submit" class="btn btn-success">Enregistrer</button>
<button type="button" class="btn btn-danger" onclick="location.reload()">Annuler</button>
</form>
`; `;
} }
// 2. Injecteur qui ajoute le bouton bleu // 3. Sauvegarde
setInterval(() => { function save() {
const greenBtn = document.querySelector('.btn-success'); const selectedKey = document.getElementById('cat-select').value;
if (greenBtn && !document.querySelector('.btn-catalog-shortcut')) { const selectedLabel = GLOBAL_CATEGORY_LABELS[selectedKey];
const container = greenBtn.parentNode; alert("Réconciliation réussie : Envoi de la clé '" + selectedKey + "' vers EverShelf.");
let pId = greenBtn.getAttribute('data-id'); console.log("Donnée API :", { category: selectedKey });
location.reload();
const blueBtn = document.createElement('button'); }
blueBtn.type = 'button';
blueBtn.className = 'btn btn-catalog-shortcut';
blueBtn.innerText = '✏️ Modifier la fiche';
// Au clic, on appelle notre fonction de test
blueBtn.onclick = () => mockEditProduct(pId);
container.insertBefore(blueBtn, greenBtn);
}
}, 500);
</script> </script>
</body> </body>
</html> </html>