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) {
|
function seleccionarPrioridad(btn) {
|
||||||
prioCodigo = btn.dataset.codigo;
|
prioCodigo = btn.dataset.codigo;
|
||||||
prioNombre = btn.dataset.nombre;
|
prioNombre = btn.dataset.nombre;
|
||||||
@@ -516,24 +540,12 @@ unset($p);
|
|||||||
const inpCedula = document.getElementById('inp-cedula');
|
const inpCedula = document.getElementById('inp-cedula');
|
||||||
inpCedula.focus();
|
inpCedula.focus();
|
||||||
inpCedula.value = '';
|
inpCedula.value = '';
|
||||||
|
_lastKeyAt = 0;
|
||||||
// Detector de scanner: auto-submit solo si los dígitos llegan rápido (< 80ms entre cada uno)
|
clearTimeout(_timerAutoSubmit);
|
||||||
let _timerAutoSubmit = null;
|
resetInactividad();
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function volverPrioridades() { mostrar('screen-prio'); }
|
function volverPrioridades() { clearTimeout(_timerInactividad); mostrar('screen-prio'); }
|
||||||
|
|
||||||
async function confirmarTurno() {
|
async function confirmarTurno() {
|
||||||
const cedula = document.getElementById('inp-cedula').value.trim();
|
const cedula = document.getElementById('inp-cedula').value.trim();
|
||||||
@@ -577,6 +589,7 @@ unset($p);
|
|||||||
|
|
||||||
function seleccionarOtraPrioridad() {
|
function seleccionarOtraPrioridad() {
|
||||||
clearTimeout(window._timer);
|
clearTimeout(window._timer);
|
||||||
|
clearTimeout(_timerInactividad);
|
||||||
document.getElementById('inp-cedula').value = '';
|
document.getElementById('inp-cedula').value = '';
|
||||||
document.getElementById('inp-cel').value = '';
|
document.getElementById('inp-cel').value = '';
|
||||||
prioCodigo = prioNombre = prioColor = '';
|
prioCodigo = prioNombre = prioColor = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user