Actualiser assets/js/app.js
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
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:
+1
-190
@@ -8933,15 +8933,7 @@ function showProductAction() {
|
||||
👨🍳 ${t('action.create_recipe_btn') || 'Crea una ricetta'}
|
||||
</button>
|
||||
`;
|
||||
// Secondary: catalog edit link below the buttons (one instance only)
|
||||
let catalogLink = document.getElementById('catalog-edit-link');
|
||||
if (!catalogLink) {
|
||||
catalogLink = document.createElement('div');
|
||||
catalogLink.id = 'catalog-edit-link';
|
||||
catalogLink.style.cssText = 'text-align:center;margin-top:6px';
|
||||
btnsContainer.after(catalogLink);
|
||||
}
|
||||
catalogLink.innerHTML = `<button type="button" class="btn-link-small" onclick="editProductFromAction()">${t('product.edit_catalog')}</button>`;
|
||||
|
||||
} else {
|
||||
// Product NOT in inventory - show only AGGIUNGI
|
||||
statusBar.style.display = 'none';
|
||||
@@ -9034,61 +9026,6 @@ async function checkInventoryForProduct(productId, productName) {
|
||||
}
|
||||
}
|
||||
|
||||
// === EDIT PRODUCT FROM ACTION PAGE ===
|
||||
function editProductFromAction() {
|
||||
if (!currentProduct) return;
|
||||
// Pre-fill the product form with current product data
|
||||
document.getElementById('pf-id').value = currentProduct.id || '';
|
||||
document.getElementById('pf-name').value = currentProduct.name || '';
|
||||
document.getElementById('pf-brand').value = currentProduct.brand || '';
|
||||
document.getElementById('pf-barcode').value = currentProduct.barcode || '';
|
||||
document.getElementById('pf-image').value = '';
|
||||
document.getElementById('pf-notes').value = currentProduct.notes || '';
|
||||
document.getElementById('pf-unit').value = currentProduct.unit || 'pz';
|
||||
document.getElementById('pf-defqty').value = currentProduct.default_quantity || 1;
|
||||
document.getElementById('product-form-title').textContent = t('product.title_edit');
|
||||
const pfAiRow = document.getElementById('pf-ai-fill-row');
|
||||
if (pfAiRow) pfAiRow.style.display = 'none';
|
||||
// Keep barcode hint hidden in edit mode
|
||||
const pfBcHint = document.getElementById('pf-barcode-hint');
|
||||
if (pfBcHint) pfBcHint.style.display = 'none';
|
||||
|
||||
// Restore datalist for editing (was removed for new products)
|
||||
document.getElementById('pf-name').setAttribute('list', 'common-products');
|
||||
document.getElementById('pf-brand').setAttribute('list', 'common-brands');
|
||||
|
||||
// Set category
|
||||
const cat = mapToLocalCategory(currentProduct.category, currentProduct.name, currentProduct.brand);
|
||||
document.getElementById('pf-category').value = cat;
|
||||
document.getElementById('pf-category').dataset.manuallySet = 'true';
|
||||
|
||||
// Forcer l'affichage et l'activation de la catégorie en mode modification
|
||||
document.getElementById('pf-category').style.display = 'block';
|
||||
if (document.getElementById('pf-category').closest('.form-group')) {
|
||||
document.getElementById('pf-category').closest('.form-group').style.display = 'block';
|
||||
}
|
||||
document.getElementById('pf-category').disabled = false;
|
||||
document.getElementById('pf-subcategory').value = currentProduct.subcategory || '';
|
||||
document.getElementById('pf-defqty').dataset.manuallySet = 'true';
|
||||
|
||||
// Image preview - not shown in edit mode
|
||||
const preview = document.getElementById('pf-image-preview');
|
||||
preview.style.display = 'none';
|
||||
|
||||
// Conf size row
|
||||
const pfConfRow = document.getElementById('pf-conf-size-row');
|
||||
if (currentProduct.unit === 'conf' && pfConfRow) {
|
||||
pfConfRow.style.display = 'block';
|
||||
document.getElementById('pf-conf-size').value = currentProduct.default_quantity || '';
|
||||
document.getElementById('pf-conf-unit').value = currentProduct.package_unit || 'g';
|
||||
} else if (pfConfRow) {
|
||||
pfConfRow.style.display = 'none';
|
||||
}
|
||||
|
||||
showPage('product-form');
|
||||
}
|
||||
|
||||
// === EDIT INVENTORY ITEM FROM ACTION PAGE ===
|
||||
// === OPEN INVENTORY EDIT — picks item or shows location picker ===
|
||||
function openInventoryEdit() {
|
||||
const items = _actionInventoryItems;
|
||||
@@ -9511,27 +9448,6 @@ function showAddForm() {
|
||||
${currentProduct.weight_info ? `<p style="font-size:0.8rem;color:var(--text-light)">${escapeHtml(currentProduct.weight_info)}</p>` : ''}
|
||||
</div>
|
||||
`;
|
||||
|
||||
// --- PATCH : Injection du bouton "Modifier la fiche produit" ---
|
||||
// On vérifie si le bouton n'existe pas déjà pour éviter les doublons
|
||||
if (!document.getElementById('btn-edit-product-shortcut')) {
|
||||
// On cherche le bouton vert "Aggiungi" dans la page add
|
||||
const submitBtn = document.querySelector('#page-add button[type="submit"]');
|
||||
if (submitBtn) {
|
||||
const editBtn = document.createElement('button');
|
||||
editBtn.type = 'button';
|
||||
editBtn.id = 'btn-edit-product-shortcut';
|
||||
editBtn.className = 'btn btn-large';
|
||||
editBtn.innerText = '✏️ ';
|
||||
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;';
|
||||
|
||||
// On lie le clic à notre fonction de bascule
|
||||
editBtn.onclick = switchToProductEditFromStock;
|
||||
|
||||
// Insérer le bouton juste au-dessus du bouton vert "Enregistrer/Aggiungi"
|
||||
submitBtn.parentNode.insertBefore(editBtn, submitBtn);
|
||||
}
|
||||
}
|
||||
|
||||
// Set unit selector
|
||||
const unit = currentProduct.unit || 'pz';
|
||||
@@ -20020,108 +19936,3 @@ function switchToProductEditFromUse() {
|
||||
alert("Erreur : Impossible de récupérer l'identifiant du produit depuis cet écran.");
|
||||
}
|
||||
}
|
||||
|
||||
function switchToProductEditFromStock() {
|
||||
let productId = null;
|
||||
|
||||
// 1. Essayer de récupérer l'ID depuis les variables globales courantes de l'application
|
||||
if (typeof currentProduct !== 'undefined' && currentProduct) {
|
||||
productId = currentProduct.id || currentProduct._id || currentProduct.product_id;
|
||||
} else if (typeof _currentProduct !== 'undefined' && _currentProduct) {
|
||||
productId = _currentProduct.id || _currentProduct._id || _currentProduct.product_id;
|
||||
} else if (typeof currentItem !== 'undefined' && currentItem) {
|
||||
productId = currentItem.product_id || currentItem.productId;
|
||||
}
|
||||
|
||||
// 2. Si non trouvé, essayer de le lire directement depuis le champ caché du formulaire s'il existe
|
||||
if (!productId) {
|
||||
const idInput = document.getElementById('add-product-id') || document.getElementById('pf-id');
|
||||
if (idInput && idInput.value) {
|
||||
productId = idInput.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (productId) {
|
||||
// Masquer la page/modale de stock actuelle
|
||||
const addSection = document.getElementById('add-vacuum-group')?.closest('.page');
|
||||
if (addSection) {
|
||||
addSection.classList.remove('active');
|
||||
}
|
||||
|
||||
// Ouvrir la page d'édition du produit
|
||||
if (typeof editProduct === 'function') {
|
||||
editProduct(productId);
|
||||
} else {
|
||||
// Sécurité : Forcer l'affichage de la page produit
|
||||
const prodPage = document.getElementById('page-product-form');
|
||||
if (prodPage) {
|
||||
prodPage.classList.add('active');
|
||||
prodPage.style.display = 'block';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert("Erreur : Impossible de lier ce lot à un produit du catalogue.");
|
||||
}
|
||||
}
|
||||
|
||||
// --- INJECTEUR UNIVERSEL DU BOUTON MODIFICATION ---
|
||||
setInterval(() => {
|
||||
// 1. Chercher le bouton vert "Enregistrer" ou "Aggiungi" actuellement visible à l'écran
|
||||
// On cible les boutons larges avec la classe btn-success (vert)
|
||||
const successButtons = document.querySelectorAll('.btn-success.full-width, button[type="submit"].btn-success');
|
||||
|
||||
successButtons.forEach(submitBtn => {
|
||||
// Vérifier si le bouton est visible à l'écran
|
||||
if (submitBtn.offsetWidth > 0 && submitBtn.offsetHeight > 0) {
|
||||
|
||||
// Trouver le conteneur parent du bouton
|
||||
const parentForm = submitBtn.parentNode;
|
||||
|
||||
// 2. Si le bouton de raccourci n'est pas encore injecté dans ce formulaire
|
||||
if (parentForm && !parentForm.querySelector('.btn-edit-catalog-shortcut')) {
|
||||
|
||||
// Création du bouton bleu
|
||||
//const editBtn = document.createElement('button');
|
||||
//editBtn.type = 'button';
|
||||
// editBtn.className = 'btn btn-large btn-edit-catalog-shortcut';
|
||||
// editBtn.innerText = '✏️ Modifier la fiche produit (Catégorie)';
|
||||
|
||||
// Style identique à tes captures d'écran
|
||||
// editBtn.style.cssText = 'margin-bottom: 12px; background-color: #1976d2; color: white; width: 100%; border: none; border-radius: 8px; padding: 14px; font-size: 16px; font-weight: bold; cursor: pointer; display: block; text-align: center;';
|
||||
|
||||
// Logique de clic pour basculer vers le catalogue
|
||||
editBtn.onclick = function(e) {
|
||||
e.preventDefault();
|
||||
let productId = null;
|
||||
|
||||
// Récupérer l'ID du produit depuis le contexte d'EverShelf
|
||||
if (typeof currentProduct !== 'undefined' && currentProduct) productId = currentProduct.id || currentProduct._id;
|
||||
if (typeof _currentProduct !== 'undefined' && _currentProduct) productId = _currentProduct.id || _currentProduct._id;
|
||||
if (typeof currentItem !== 'undefined' && currentItem) productId = currentItem.product_id || currentItem.productId;
|
||||
|
||||
if (productId) {
|
||||
// Masquer toutes les modales/pages de stock ouvertes
|
||||
document.querySelectorAll('.page, .modal').forEach(el => {
|
||||
el.classList.remove('active');
|
||||
if (el.style.display === 'block') el.style.display = 'none';
|
||||
});
|
||||
|
||||
// Lancer l'éditeur de produit officiel
|
||||
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("Sélectionnez d'abord un produit valide.");
|
||||
}
|
||||
};
|
||||
|
||||
// Injection physique juste au-dessus du bouton vert
|
||||
parentForm.insertBefore(editBtn, submitBtn);
|
||||
console.log("=> Raccourci catalogue injecté dynamiquement au-dessus du bouton :", submitBtn.innerText);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 400); // Scan toutes les 400ms
|
||||
Reference in New Issue
Block a user