From 1c71d749a1dfe98780d574b35eb76a1ef48815ce Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 13 Sep 2026 17:13:08 +0000 Subject: [PATCH] Permitir editar el texto/cantidad/precio de un articulo ya anadido (boton editar en la lista) --- presupuestos.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/presupuestos.html b/presupuestos.html index 74ac93e..63b0e44 100644 --- a/presupuestos.html +++ b/presupuestos.html @@ -262,6 +262,7 @@ let currentItems = []; let allBudgets = []; let editingId = null; // null = modo crear, con valor = modo editar + let editingItemIndex = null; // null = añadiendo nuevo articulo, con valor = editando uno existente // ------------------ INICIALIZACIÓN Y TEMA CORPORATIVO ------------------ async function applyTheme() { @@ -297,6 +298,7 @@ // ------------------ NAVEGACIÓN Y TOASTS ------------------ function showCreateView() { editingId = null; + editingItemIndex = null; document.getElementById('createViewTitle').textContent = 'Generar Nuevo'; document.getElementById('btnSave').innerHTML = ' Generar Presupuesto'; document.getElementById('viewList').classList.add('hidden'); @@ -315,6 +317,7 @@ const budget = allBudgets.find(b => b.id === id); if (!budget) return showToast("Error: Presupuesto no encontrado"); editingId = id; + editingItemIndex = null; document.getElementById('c_name').value = budget.client_name || ''; document.getElementById('c_phone').value = budget.client_phone || ''; document.getElementById('c_address').value = budget.client_address || ''; @@ -635,7 +638,12 @@ if(!concept || isNaN(qty) || isNaN(price)) { showToast("Rellena concepto y precio."); return; } - currentItems.push({ concept, qty, price, total: qty * price }); + if (editingItemIndex !== null) { + currentItems[editingItemIndex] = { concept, qty, price, total: qty * price }; + editingItemIndex = null; + } else { + currentItems.push({ concept, qty, price, total: qty * price }); + } conceptInput.value = ''; qtyInput.value = '1'; priceInput.value = ''; conceptInput.focus(); renderItems(); @@ -646,6 +654,17 @@ renderItems(); } + function editItem(idx) { + const item = currentItems[idx]; + if (!item) return; + document.getElementById('item_concept').value = item.concept; + document.getElementById('item_qty').value = item.qty; + document.getElementById('item_price').value = item.price; + editingItemIndex = idx; + document.getElementById('item_concept').focus(); + showToast("Modifica los datos y pulsa + para guardar los cambios"); + } + function renderItems() { const cont = document.getElementById('itemsContainer'); cont.innerHTML = currentItems.map((item, idx) => ` @@ -656,6 +675,7 @@
${item.total.toFixed(2)}€ +