diff --git a/assets/js/app.js b/assets/js/app.js index 4c19c81..2bea2a0 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -20044,4 +20044,51 @@ function switchToProductEditFromStock() { } else { alert("Erreur : Impossible de lier ce lot à un produit du catalogue."); } -} \ No newline at end of file +} + +// --- FORCE INJECTION SHORTCUT BUTTON --- +setInterval(() => { + // 1. Vérifier si la page d'ajout est active et visible à l'écran + const pageAdd = document.getElementById('page-add'); + if (pageAdd && (pageAdd.classList.contains('active') || pageAdd.style.display === 'block')) { + + // 2. Vérifier si notre bouton n'est pas déjà présent + if (!document.getElementById('btn-edit-product-shortcut')) { + + // 3. Trouver le bouton submit vert (on cherche par sa classe et son type) + const submitBtn = pageAdd.querySelector('button[type="submit"]') || pageAdd.querySelector('.btn-success'); + + if (submitBtn) { + const editBtn = document.createElement('button'); + editBtn.type = 'button'; + editBtn.id = 'btn-edit-product-shortcut'; + editBtn.innerText = '✏️ Modifier la fiche produit'; + editBtn.style.cssText = 'margin-bottom: 15px; background-color: #1976d2; color: white; width: 100%; border: none; border-radius: 8px; padding: 12px; font-size: 16px; font-weight: bold; cursor: pointer; display: block;'; + + // Associer l'action de clic + editBtn.onclick = function() { + let productId = null; + if (typeof currentProduct !== 'undefined' && currentProduct) productId = currentProduct.id || currentProduct._id; + if (typeof _currentProduct !== 'undefined' && _currentProduct) productId = _currentProduct.id || _currentProduct._id; + + if (productId) { + pageAdd.classList.remove('active'); + pageAdd.style.display = 'none'; + if (typeof editProduct === 'function') { + editProduct(productId); + } else { + const prodPage = document.getElementById('page-product-form'); + if (prodPage) { prodPage.classList.add('active'); prodPage.style.display = 'block'; } + } + } else { + alert("Erreur: Impossible de récupérer le produit."); + } + }; + + // Injection physique dans le DOM + submitBtn.parentNode.insertBefore(editBtn, submitBtn); + console.log("=> Bouton de modification injecté avec succès par le gardien temporel !"); + } + } + } +}, 500); // Vérifie toutes les demi-secondes \ No newline at end of file