Sempre modificabile nome/marca prodotto: bottone ✏️ sulla preview

This commit is contained in:
dadaloop82
2026-03-15 17:51:22 +00:00
parent 067a4acb5c
commit b90fe409d6
4 changed files with 63 additions and 37 deletions
+21
View File
@@ -2732,6 +2732,27 @@ body {
font-size: 0.95rem;
}
.btn-edit-inline {
position: absolute;
top: 8px;
right: 8px;
background: rgba(255,255,255,0.9);
border: 1px solid #ddd;
border-radius: 50%;
width: 36px;
height: 36px;
font-size: 1rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.product-preview-large {
position: relative;
}
/* ===== INVENTORY STATUS BAR ===== */
.inventory-status-bar {
background: linear-gradient(135deg, #dbeafe 0%, #c7d2fe 100%);
+40 -35
View File
@@ -2301,13 +2301,13 @@ function showProductAction() {
${currentProduct.weight_info ? `<p style="font-size:0.85rem;color:var(--text-light)">⚖️ ${escapeHtml(currentProduct.weight_info)}</p>` : ''}
${currentProduct.barcode ? `<p style="font-size:0.75rem;color:var(--text-muted)">📊 ${currentProduct.barcode}</p>` : ''}
</div>
<button type="button" class="btn-edit-inline" onclick="toggleActionEdit()" title="Modifica nome/marca">✏️</button>
`;
// Check if product needs editing (unknown name, missing info)
const isUnknown = !currentProduct.name ||
/sconosciuto|unknown|^$/i.test(currentProduct.name.trim()) ||
currentProduct.name.trim().length < 2;
const needsEdit = isUnknown || !currentProduct.brand;
// Edit product info section
let editInfoEl = document.getElementById('action-edit-info');
@@ -2318,42 +2318,38 @@ function showProductAction() {
preview.parentElement.insertBefore(editInfoEl, preview.nextSibling);
}
if (needsEdit) {
const categoryOptions = Object.entries(CATEGORY_LABELS).map(([key, label]) =>
`<option value="${key}" ${mapToLocalCategory(currentProduct.category, currentProduct.name) === key ? 'selected' : ''}>${label}</option>`
).join('');
editInfoEl.innerHTML = `
<div class="edit-unknown-card ${isUnknown ? 'highlight' : ''}">
<h4>${isUnknown ? '⚠️ Prodotto non riconosciuto' : '✏️ Completa le informazioni'}</h4>
<p class="edit-unknown-hint">${isUnknown ? 'Inserisci il nome e le informazioni del prodotto' : 'Puoi modificare o completare le info mancanti'}</p>
<div class="edit-unknown-form">
<div class="form-group">
<label>🏷️ Nome prodotto</label>
<input type="text" id="edit-action-name" class="form-input" value="${escapeHtml(isUnknown ? '' : currentProduct.name)}" placeholder="Es: Latte intero, Pasta penne..." required>
</div>
<div class="form-group">
<label>🏪 Marca</label>
<input type="text" id="edit-action-brand" class="form-input" value="${escapeHtml(currentProduct.brand || '')}" placeholder="Es: Barilla, Mulino Bianco...">
</div>
<div class="form-group">
<label>📂 Categoria</label>
<select id="edit-action-category" class="form-input">
<option value="">-- Seleziona --</option>
${categoryOptions}
</select>
</div>
<button type="button" class="btn btn-primary full-width" onclick="saveEditedProductInfo()">💾 Salva informazioni</button>
// Always build the edit form, but only show it auto-opened for unknown products
const categoryOptions = Object.entries(CATEGORY_LABELS).map(([key, label]) =>
`<option value="${key}" ${mapToLocalCategory(currentProduct.category, currentProduct.name) === key ? 'selected' : ''}>${label}</option>`
).join('');
editInfoEl.innerHTML = `
<div class="edit-unknown-card ${isUnknown ? 'highlight' : ''}">
<h4>${isUnknown ? '⚠️ Prodotto non riconosciuto' : '✏️ Modifica informazioni'}</h4>
${isUnknown ? '<p class="edit-unknown-hint">Inserisci il nome e le informazioni del prodotto</p>' : ''}
<div class="edit-unknown-form">
<div class="form-group">
<label>🏷️ Nome prodotto</label>
<input type="text" id="edit-action-name" class="form-input" value="${escapeHtml(isUnknown ? '' : currentProduct.name)}" placeholder="Es: Latte intero, Pasta penne..." required>
</div>
<div class="form-group">
<label>🏪 Marca</label>
<input type="text" id="edit-action-brand" class="form-input" value="${escapeHtml(currentProduct.brand || '')}" placeholder="Es: Barilla, Mulino Bianco...">
</div>
<div class="form-group">
<label>📂 Categoria</label>
<select id="edit-action-category" class="form-input">
<option value="">-- Seleziona --</option>
${categoryOptions}
</select>
</div>
<button type="button" class="btn btn-primary full-width" onclick="saveEditedProductInfo()">💾 Salva informazioni</button>
</div>
`;
editInfoEl.style.display = 'block';
if (isUnknown) {
setTimeout(() => document.getElementById('edit-action-name')?.focus(), 100);
}
} else {
editInfoEl.style.display = 'none';
editInfoEl.innerHTML = '';
</div>
`;
editInfoEl.style.display = isUnknown ? 'block' : 'none';
if (isUnknown) {
setTimeout(() => document.getElementById('edit-action-name')?.focus(), 100);
}
// Show extra product info section below preview
@@ -2634,6 +2630,15 @@ async function throwPartial() {
}
}
function toggleActionEdit() {
const el = document.getElementById('action-edit-info');
if (!el) return;
el.style.display = el.style.display === 'none' ? 'block' : 'none';
if (el.style.display === 'block') {
setTimeout(() => document.getElementById('edit-action-name')?.focus(), 100);
}
}
async function saveEditedProductInfo() {
const name = (document.getElementById('edit-action-name')?.value || '').trim();
if (!name) {
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -9,7 +9,7 @@
<title>Dispensa Manager</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🏠</text></svg>">
<link rel="stylesheet" href="assets/css/style.css?v=20260313.2">
<link rel="stylesheet" href="assets/css/style.css?v=20260315c">
<!-- QuaggaJS for barcode scanning -->
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
</head>
@@ -884,6 +884,6 @@
</div>
</div>
<script src="assets/js/app.js?v=20260315b"></script>
<script src="assets/js/app.js?v=20260315c"></script>
</body>
</html>