From 08bb29396368eb0b11db01f5c98a2e9fa36ef5a0 Mon Sep 17 00:00:00 2001 From: morgane Date: Wed, 17 Jun 2026 21:16:52 +0000 Subject: [PATCH] Actualiser assets/js/app.js --- assets/js/app.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 00542f4..e317e8d 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1817,6 +1817,11 @@ const CATEGORY_LABELS = { 'altro': `📦 ${t('categories.altro')}` }; +const SUBCATEGORY_LABELS = { + 'vin': '🍷 Vin', 'biere': '🍺 Bière', 'spiritueux': '🥃 Spiritueux', + 'soda': '🥤 Soda', 'jus': '🧃 Jus', 'eau': '💧 Eau', 'autre': '📦 Autre' +}; + // Detect best unit/quantity from Open Food Facts quantity_info string // Returns the actual package weight/volume as default (e.g. 700g → unit:'g', quantity:700) function detectUnitAndQuantity(quantityInfo) { @@ -6671,6 +6676,9 @@ function renderInventoryItem(item) { const catIcon = CATEGORY_ICONS[catKey] || '📦'; const catLabel = t('categories.' + catKey) || catKey; const catBadge = `${catIcon} ${catLabel}`; + const subBadge = (catKey === 'bevande' && item.subcategory && SUBCATEGORY_LABELS[item.subcategory]) + ? `${SUBCATEGORY_LABELS[item.subcategory]}` + : ''; const locInfo = LOCATIONS[item.location] || { icon: '📦', label: item.location }; const days = daysUntilExpiry(item.expiry_date); const isExpired = days < 0; @@ -6702,6 +6710,7 @@ function renderInventoryItem(item) {
${locInfo.icon} ${locInfo.label} ${catBadge} + ${subBadge} ${expiryBadge} ${openedBadge} ${vacuumBadge} @@ -6776,6 +6785,8 @@ function filterInventory() { if ((CATEGORY_LABELS[itemCat] || '').toLowerCase().includes(q)) return true; // Match by inferred category: "biscotti" → queryCat="snack" → all snack items if (queryCat !== 'altro' && itemCat === queryCat) return true; + if (i.subcategory && i.subcategory.toLowerCase().includes(q)) return true; + if (i.subcategory && (SUBCATEGORY_LABELS[i.subcategory] || '').toLowerCase().includes(q)) return true; return false; }); renderInventory(filtered); @@ -8495,6 +8506,12 @@ function autoDetectCategory() { function onCategoryChange(fromAutoDetect = false) { const cat = document.getElementById('pf-category').value; + const subGroup = document.getElementById('pf-subcategory-group'); + if (subGroup) subGroup.style.display = (cat === 'bevande') ? 'block' : 'none'; + if (cat !== 'bevande') { + const subSel = document.getElementById('pf-subcategory'); + if (subSel) subSel.value = ''; + } const unitSelect = document.getElementById('pf-unit'); const qtyInput = document.getElementById('pf-defqty'); @@ -8655,14 +8672,21 @@ async function scanBarcodeForForm() { async function submitProduct(e) { e.preventDefault(); + const pfCategory = document.getElementById('pf-category').value; + const pfSubcategory = document.getElementById('pf-subcategory')?.value || ''; + if (pfCategory === 'bevande' && !pfSubcategory) { + showToast('Merci de préciser le type de boisson', 'error'); + document.getElementById('pf-subcategory').focus(); + return; + } showLoading(true); - const pfUnit = document.getElementById('pf-unit').value; const productData = { id: document.getElementById('pf-id').value || null, name: document.getElementById('pf-name').value, brand: document.getElementById('pf-brand').value, - category: document.getElementById('pf-category').value, + category: pfCategory, + subcategory: pfCategory === 'bevande' ? pfSubcategory : null, unit: pfUnit, default_quantity: pfUnit === 'conf' ? (parseFloat(document.getElementById('pf-conf-size')?.value) || 1) : (parseFloat(document.getElementById('pf-defqty').value) || 1), package_unit: pfUnit === 'conf' ? (document.getElementById('pf-conf-unit')?.value || '') : '', @@ -9051,6 +9075,12 @@ function editProductFromAction() { } document.getElementById('pf-category').disabled = false; + // Set subcategory (boisson uniquement) + const editSubGroup = document.getElementById('pf-subcategory-group'); + if (editSubGroup) editSubGroup.style.display = (cat === 'bevande') ? 'block' : 'none'; + const editSubSel = document.getElementById('pf-subcategory'); + if (editSubSel) editSubSel.value = (cat === 'bevande') ? (currentProduct.subcategory || '') : ''; + document.getElementById('pf-defqty').dataset.manuallySet = 'true'; // Image preview - not shown in edit mode