From 75947d3468d57ec739ba08f082e096ed23d0fa9b Mon Sep 17 00:00:00 2001 From: Naiel <109038805+naielv@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:38:28 +0000 Subject: [PATCH] =?UTF-8?q?Refactor=20manejo=20de=20URL=20para=20eliminar?= =?UTF-8?q?=20par=C3=A1metros=20de=20b=C3=BAsqueda=20en=20la=20navegaci?= =?UTF-8?q?=C3=B3n=20y=20mejorar=20la=20visibilidad=20de=20personas=20en?= =?UTF-8?q?=20formularios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app_logic.js | 2 +- src/app_modules.js | 15 ++++-- src/config.js | 2 +- src/page/aulas.js | 2 +- src/page/cajas.js | 2 +- src/page/login.js | 4 +- src/page/pagos.js | 117 +++++++++++++++++++++++++++++++++++++++---- src/page/personas.js | 11 ++-- 8 files changed, 133 insertions(+), 22 deletions(-) diff --git a/src/app_logic.js b/src/app_logic.js index 9fefc42..22d0eee 100644 --- a/src/app_logic.js +++ b/src/app_logic.js @@ -52,7 +52,7 @@ function setUrlHash(hash) { } } window.onhashchange = () => { - open_page(location.hash.replace('#', '')); + open_page(location.hash.replace('#', '').split("?")[0]); }; function download(filename, text) { diff --git a/src/app_modules.js b/src/app_modules.js index 14d6bf1..07323e8 100644 --- a/src/app_modules.js +++ b/src/app_modules.js @@ -621,7 +621,8 @@ function addCategory_Personas( change_cb = () => {}, label = 'Persona', open_default = false, - default_empty_text = '- Lista Vacia -' + default_empty_text = '- Lista Vacia -', + show_hidden = false, ) { var details_0 = document.createElement('details'); // children: img_0, summary_0 //details_0.open = true; @@ -670,6 +671,7 @@ function addCategory_Personas( .map((entry) => { var key = entry['_key']; var value = entry; + if (value.Oculto == true && !show_hidden) { return; } if (lastreg != value.Region.toUpperCase()) { lastreg = value.Region.toUpperCase(); var h3_0 = document.createElement('h2'); @@ -1218,6 +1220,7 @@ function TS_IndexElement( id="${searchKeyInput}" placeholder="🔍 Buscar..." style="width: calc(100% - 18px); padding: 8px; border: 1px solid #ccc; border-radius: 4px; background-color: rebeccapurple; color: white;" + value="" /> @@ -1237,7 +1240,11 @@ function TS_IndexElement( // Add search functionality const searchKeyEl = document.getElementById(searchKeyInput); searchKeyEl.addEventListener('input', () => debounce(debounce_search, render, 200, [rows])); - + // If there is a preset search value in URL, apply it + var hashQuery = new URLSearchParams(window.location.hash.split('?')[1]); + if (hashQuery.has('search')) { + searchKeyEl.value = hashQuery.get('search'); + } function searchInData(data, searchValue, config) { if (!searchValue) return true; @@ -1846,7 +1853,7 @@ var BootIntervalID = setInterval(() => { SUB_LOGGED_IN = true; localStorage.setItem('TELESEC_BYPASS_ID', SUB_LOGGED_IN_ID); SetPages(); - open_page(location.hash.replace('#', '')); + open_page(location.hash.replace('#', '').split("?")[0]); } if (!data) { const persona = { Nombre: 'Admin (bypass)', Roles: 'ADMIN,' }; @@ -1883,7 +1890,7 @@ var BootIntervalID = setInterval(() => { } } else { SetPages(); - open_page(location.hash.replace('#', '')); + open_page(location.hash.replace('#', '').split("?")[0]); } clearInterval(BootIntervalID); } diff --git a/src/config.js b/src/config.js index ffb6604..0e8dc36 100644 --- a/src/config.js +++ b/src/config.js @@ -82,7 +82,7 @@ if (urlParams.get('couch') != null) { history.replaceState( null, '', - location.pathname + (urlParams.toString() ? '?' + urlParams.toString() : '') + location.hash + location.pathname + (urlParams.toString() ? '?' + urlParams.toString() : '') + location.hash.split("?")[0] ); console.log('CouchDB auto-configured from URL parameter'); diff --git a/src/page/aulas.js b/src/page/aulas.js index ca2e53c..1e138c0 100644 --- a/src/page/aulas.js +++ b/src/page/aulas.js @@ -456,7 +456,7 @@ Cargando... !(persona && persona.Oculto === true)) + ); + }, + + __ensureCajaCafePersona: function () { + var cajaId = PAGES.pagos.CajaCafeID; + var cajaNombre = PAGES.pagos.CajaCafeNombre; + var existing = SC_Personas[cajaId]; + + if (existing && existing.Nombre === cajaNombre && existing.Oculto === true) { + return Promise.resolve(cajaId); + } + + var data = { + Nombre: cajaNombre, + Region: 'Sistema', + Roles: '', + SC_Anilla: '', + markdown: 'Monedero interno de cafetería', + Monedero_Balance: parseFloat((existing && existing.Monedero_Balance) || 0) || 0, + Monedero_Notas: (existing && existing.Monedero_Notas) || '', + Oculto: true, + }; + + return DB.put('personas', cajaId, data) + .then(() => { + SC_Personas[cajaId] = data; + return cajaId; + }) + .catch((e) => { + console.warn('DB.put error', e); + return null; + }); + }, + + __creditCajaCafeForGasto: function (personaOrigenId, monto, callback) { + var cajaId = PAGES.pagos.CajaCafeID; + if (personaOrigenId === cajaId) { + if (callback) callback(); + return; + } + + PAGES.pagos.__ensureCajaCafePersona().then((resolvedCajaId) => { + if (!resolvedCajaId) { + if (callback) callback(); + return; + } + + var caja = SC_Personas[resolvedCajaId]; + if (!caja) { + if (callback) callback(); + return; + } + + var currentBalance = parseFloat(caja.Monedero_Balance || 0); + caja.Monedero_Balance = fixfloat(currentBalance + monto); + + DB.put('personas', resolvedCajaId, caja) + .then(() => { + if (callback) callback(); + }) + .catch((e) => { + console.warn('DB.put error', e); + if (callback) callback(); + }); + }); + }, // Datafono view for creating/processing transactions datafono: function (prefilledData = {}) { @@ -32,6 +104,8 @@ PAGES.pagos = { sessionStorage.removeItem('pagos_scanned_persona'); } + PAGES.pagos.__ensureCajaCafePersona(); + var field_tipo = safeuuid(); var field_monto = safeuuid(); var field_persona = safeuuid(); @@ -413,9 +487,10 @@ PAGES.pagos = { var container = document.querySelector('#personaSelector'); container.innerHTML = ''; document.getElementById(field_persona).value = selectedPersona; + var visiblePersonas = PAGES.pagos.__getVisiblePersonas(); addCategory_Personas( container, - SC_Personas, + visiblePersonas, selectedPersona, (personaId) => { document.getElementById(field_persona).value = personaId; @@ -431,9 +506,10 @@ PAGES.pagos = { var container = document.querySelector('#personaDestinoSelector'); container.innerHTML = ''; document.getElementById(field_persona_destino).value = selectedPersonaDestino; + var visiblePersonas = PAGES.pagos.__getVisiblePersonas(); addCategory_Personas( container, - SC_Personas, + visiblePersonas, selectedPersonaDestino, (personaId) => { document.getElementById(field_persona_destino).value = personaId; @@ -498,20 +574,30 @@ PAGES.pagos = { // Don't update balance for Efectivo Gastos (paying with cash) var shouldUpdateBalance = !(tipo === 'Gasto' && metodo === 'Efectivo'); + function finalizeTransactionSave() { + if (tipo === 'Gasto') { + PAGES.pagos.__creditCajaCafeForGasto(personaId, monto, () => { + saveTransaction(ticketId, transactionData); + }); + } else { + saveTransaction(ticketId, transactionData); + } + } + if (shouldUpdateBalance) { updateWalletBalance(personaId, tipo, monto, () => { if (tipo === 'Transferencia') { var destinoId = transactionData.PersonaDestino; updateWalletBalance(destinoId, 'Ingreso', monto, () => { - saveTransaction(ticketId, transactionData); + finalizeTransactionSave(); }); } else { - saveTransaction(ticketId, transactionData); + finalizeTransactionSave(); } }); } else { // Skip balance update for Efectivo Gastos - saveTransaction(ticketId, transactionData); + finalizeTransactionSave(); } } @@ -666,7 +752,7 @@ PAGES.pagos = { return; } var tid = ftid.split(',')[0]; - var tid2 = location.hash.split(','); + var tid2 = location.hash.split("?")[0].split(','); if (tid == 'datafono') { PAGES.pagos.datafono(); return; @@ -929,7 +1015,14 @@ PAGES.pagos = { }); } else if (tipo === 'Gasto') { revertWalletBalance(personaId, 'Ingreso', monto, () => { - deleteTransaction(tid); + var cajaId = PAGES.pagos.CajaCafeID; + if (personaId === cajaId) { + deleteTransaction(tid); + return; + } + revertWalletBalance(cajaId, 'Gasto', monto, () => { + deleteTransaction(tid); + }); }); } else if (tipo === 'Transferencia') { var destinoId = data.PersonaDestino; @@ -994,6 +1087,8 @@ PAGES.pagos = { return; } + PAGES.pagos.__ensureCajaCafePersona(); + var btn_datafono = safeuuid(); var total_ingresos = safeuuid(); var total_gastos = safeuuid(); @@ -1276,6 +1371,8 @@ PAGES.pagos = { return; } + PAGES.pagos.__ensureCajaCafePersona(); + var field_tipo = safeuuid(); var field_monto = safeuuid(); var field_persona = safeuuid(); @@ -1440,9 +1537,10 @@ PAGES.pagos = { var container = document.querySelector('#personaSelector'); container.innerHTML = ''; document.getElementById(field_persona).value = selectedPersona; + var visiblePersonas = PAGES.pagos.__getVisiblePersonas(); addCategory_Personas( container, - SC_Personas, + visiblePersonas, selectedPersona, (personaId) => { document.getElementById(field_persona).value = personaId; @@ -1458,9 +1556,10 @@ PAGES.pagos = { var container = document.querySelector('#personaDestinoSelector'); container.innerHTML = ''; document.getElementById(field_persona_destino).value = selectedPersonaDestino; + var visiblePersonas = PAGES.pagos.__getVisiblePersonas(); addCategory_Personas( container, - SC_Personas, + visiblePersonas, selectedPersonaDestino, (personaId) => { document.getElementById(field_persona_destino).value = personaId; diff --git a/src/page/personas.js b/src/page/personas.js index bd17fe0..4a6c675 100644 --- a/src/page/personas.js +++ b/src/page/personas.js @@ -17,6 +17,7 @@ PAGES.personas = { var field_notas = safeuuid(); var field_anilla = safeuuid(); var field_foto = safeuuid(); + var field_oculto = safeuuid(); var render_foto = safeuuid(); var field_monedero_balance = safeuuid(); var field_monedero_notas = safeuuid(); @@ -35,7 +36,6 @@ PAGES.personas = { Zona


-
Permisos
@@ -50,7 +50,10 @@ PAGES.personas = {

- +
💳 Tarjeta Monedero
@@ -110,6 +113,7 @@ PAGES.personas = { document.getElementById(field_nombre).value = data['Nombre'] || ''; document.getElementById(field_zona).value = data['Region'] || ''; document.getElementById(field_anilla).value = data['SC_Anilla'] || ''; + document.getElementById(field_oculto).checked = data['Oculto'] || false; // set fallback image immediately document.getElementById(render_foto).src = data['Foto'] || 'static/ico/user_generic.png'; resized = data['Foto'] || 'static/ico/user_generic.png'; @@ -166,6 +170,7 @@ PAGES.personas = { Region: document.getElementById(field_zona).value, Roles: dt.getAll('perm').join(',') + ',', SC_Anilla: document.getElementById(field_anilla).value, + Oculto: document.getElementById(field_oculto).checked, // Foto moved to PouchDB attachment named 'foto' markdown: document.getElementById(field_notas).value, Monedero_Balance: parseFloat(document.getElementById(field_monedero_balance).value) || 0, @@ -204,7 +209,7 @@ PAGES.personas = { }); }; document.getElementById(btn_ver_monedero).onclick = () => { - setUrlHash('pagos'); // Navigate to pagos and show transactions for this person + setUrlHash('pagos?search=' + encodeURIComponent(document.getElementById(field_nombre).value)); // Navigate to pagos and show transactions for this person }; document.getElementById(btn_borrar).onclick = () => { if (confirm('¿Quieres borrar esta persona?') == true) {