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

This commit is contained in:
2026-06-17 12:54:33 +00:00
parent df0a47e336
commit df9624ad75
+23
View File
@@ -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 `<button type="button" class="loc-btn ${isActive}" onclick="${onClickFnName}(this, '${key}')">${info.icon} <span>${escapeHtml(info.label)}</span></button>`;
}).join('');
}
const CATEGORY_ICONS = {
'latticini': '🥛', 'carne': '🥩', 'pesce': '🐟', 'frutta': '🍎',
'verdura': '🥬', 'pasta': '🍝', 'pane': '🍞', 'surgelati': '🧊',
@@ -9345,6 +9363,11 @@ function showAddForm() {
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';