Kiosko: fix listener acumulado, añadir reset por inactividad 90s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
da076f86eb
commit
a908d623e1
@@ -503,6 +503,30 @@ unset($p);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Scanner detector (un solo listener, fuera de seleccionarPrioridad) ──
|
||||
let _timerAutoSubmit = null;
|
||||
let _lastKeyAt = 0;
|
||||
let _timerInactividad = null;
|
||||
|
||||
document.getElementById('inp-cedula').addEventListener('input', () => {
|
||||
clearTimeout(_timerAutoSubmit);
|
||||
resetInactividad();
|
||||
const now = Date.now();
|
||||
const gap = now - _lastKeyAt;
|
||||
_lastKeyAt = now;
|
||||
const val = document.getElementById('inp-cedula').value.trim();
|
||||
if (/^\d{5,15}$/.test(val) && gap < 80) {
|
||||
_timerAutoSubmit = setTimeout(() => confirmarTurno(), 300);
|
||||
}
|
||||
});
|
||||
|
||||
function resetInactividad() {
|
||||
clearTimeout(_timerInactividad);
|
||||
_timerInactividad = setTimeout(() => {
|
||||
seleccionarOtraPrioridad();
|
||||
}, 90000); // 90 s sin actividad → vuelve al inicio
|
||||
}
|
||||
|
||||
function seleccionarPrioridad(btn) {
|
||||
prioCodigo = btn.dataset.codigo;
|
||||
prioNombre = btn.dataset.nombre;
|
||||
@@ -516,24 +540,12 @@ unset($p);
|
||||
const inpCedula = document.getElementById('inp-cedula');
|
||||
inpCedula.focus();
|
||||
inpCedula.value = '';
|
||||
|
||||
// Detector de scanner: auto-submit solo si los dígitos llegan rápido (< 80ms entre cada uno)
|
||||
let _timerAutoSubmit = null;
|
||||
let _lastKeyAt = 0;
|
||||
inpCedula.addEventListener('input', () => {
|
||||
clearTimeout(_timerAutoSubmit);
|
||||
const now = Date.now();
|
||||
const gap = now - _lastKeyAt;
|
||||
_lastKeyAt = now;
|
||||
const val = inpCedula.value.trim();
|
||||
// Scanner envía dígitos en ráfaga; teclado humano siempre > 80ms entre teclas
|
||||
if (/^\d{5,15}$/.test(val) && gap < 80) {
|
||||
_timerAutoSubmit = setTimeout(() => confirmarTurno(), 300);
|
||||
}
|
||||
});
|
||||
_lastKeyAt = 0;
|
||||
clearTimeout(_timerAutoSubmit);
|
||||
resetInactividad();
|
||||
}
|
||||
|
||||
function volverPrioridades() { mostrar('screen-prio'); }
|
||||
function volverPrioridades() { clearTimeout(_timerInactividad); mostrar('screen-prio'); }
|
||||
|
||||
async function confirmarTurno() {
|
||||
const cedula = document.getElementById('inp-cedula').value.trim();
|
||||
@@ -577,6 +589,7 @@ unset($p);
|
||||
|
||||
function seleccionarOtraPrioridad() {
|
||||
clearTimeout(window._timer);
|
||||
clearTimeout(_timerInactividad);
|
||||
document.getElementById('inp-cedula').value = '';
|
||||
document.getElementById('inp-cel').value = '';
|
||||
prioCodigo = prioNombre = prioColor = '';
|
||||
|
||||
Reference in New Issue
Block a user