From df9624ad75d17200a3bd28d1d2f2d6501d43abd7 Mon Sep 17 00:00:00 2001 From: morgane Date: Wed, 17 Jun 2026 12:54:33 +0000 Subject: [PATCH] Actualiser assets/js/app.js --- assets/js/app.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/assets/js/app.js b/assets/js/app.js index 4829030..016cd4c 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1352,6 +1352,24 @@ async function loadCustomLocations() { console.warn('[EverShelf] Could not load custom locations:', e); } } + +/** + * Render location selector buttons dynamically into a container. + * @param {string} containerId - DOM id of the container holding the buttons + * @param {string} activeKey - currently selected location key + * @param {string} onClickFnName - name of the click handler function (e.g. 'selectLocation') + */ +function renderLocationButtons(containerId, activeKey, onClickFnName) { + const container = document.getElementById(containerId); + if (!container) return; + const keys = Object.keys(LOCATIONS); + container.innerHTML = keys.map(key => { + const info = LOCATIONS[key]; + const isActive = key === activeKey ? 'active' : ''; + return ``; + }).join(''); +} + const CATEGORY_ICONS = { 'latticini': '🥛', 'carne': '🥩', 'pesce': '🐟', 'frutta': '🍎', 'verdura': '🥬', 'pasta': '🍝', 'pane': '🍞', 'surgelati': '🧊', @@ -9344,6 +9362,11 @@ function showAddForm() { const unit = currentProduct.unit || 'pz'; const unitSelect = document.getElementById('add-unit'); unitSelect.value = unit; + + function showAddForm() { + renderLocationButtons('location-selector', document.getElementById('add-location')?.value || 'dispensa', 'selectLocation'); + const catIcon = CATEGORY_ICONS[mapToLocalCategory(currentProduct.category, currentProduct.name)] || '📦'; + document.getElementById('add-quantity').value = unit === 'conf' ? (currentProduct._confCount || currentProduct.last_qty || 1) : (currentProduct.default_quantity || 1); document.getElementById('add-quantity').dataset.manuallySet = 'false';