- + Edu-Space diff --git a/frontend/views/partials/user_qr_modal.html b/frontend/views/partials/user_qr_modal.html index ce1c35b..465d2cc 100644 --- a/frontend/views/partials/user_qr_modal.html +++ b/frontend/views/partials/user_qr_modal.html @@ -208,7 +208,7 @@ }) .catch(function(err) { console.warn('Fallback a token local para QR modal:', err); - var fallback = "UNICABA:USR:{{ auth_user.id if auth_user else 0 }}:DNI:{{ auth_user.document_number if auth_user else 'N/A' }}"; + var fallback = "UNICABA:USR:{{ auth_user.id if auth_user else 0 }}:DNI:{{ auth_user.document_number or auth_user.dni or auth_user.id or 'N/A' }}"; ensureQrLibrary(function() { renderModalQR(fallback); }); diff --git a/frontend/views/reception/scanner.html b/frontend/views/reception/scanner.html index 404c9f9..0f6d925 100644 --- a/frontend/views/reception/scanner.html +++ b/frontend/views/reception/scanner.html @@ -52,18 +52,23 @@
- +
+ + + Lector Listo + +
-
- + -
- El lector óptico envía la lectura directamente a este campo con retorno de carro automático. + El cursor se mantiene siempre activo aquí. La pistola óptica envía la lectura y valida automáticamente.
@@ -234,14 +239,46 @@ } } + // Mantener el cursor forzado permanentemente en el input de la pistola óptica + function focusScannerInput() { + const input = document.getElementById('scannerInput'); + if (!input) return; + const active = document.activeElement; + // Evitar robar el foco solo si el usuario está activamente en el selector de sedes + if (active && active.id === 'buildingSelect') return; + if (active !== input) { + input.focus(); + } + updateFocusIndicator(true); + } + + function updateFocusIndicator(isFocused) { + const indicator = document.getElementById('scannerFocusIndicator'); + if (!indicator) return; + if (isFocused) { + indicator.className = 'small text-success fw-semibold d-flex align-items-center gap-1'; + indicator.innerHTML = ' Lector Listo'; + } else { + indicator.className = 'small text-warning fw-semibold d-flex align-items-center gap-1'; + indicator.innerHTML = ' Haz clic para activar'; + } + } + // Entrada manual o con pistola de código de barras function handleManualScan(e) { - e.preventDefault(); + if (e) e.preventDefault(); const input = document.getElementById('scannerInput'); - const val = input.value.trim(); - if (!val) return; + if (!input) return; + let val = input.value.trim(); + if (!val) { + focusScannerInput(); + return; + } + // Normalización para teclados en español / latinoamericano donde la pistola traduce : a Ñ + val = val.replace(/Ñ/g, ':').replace(/ñ/g, ':'); verifyToken(val); input.value = ''; + setTimeout(focusScannerInput, 50); } // Petición AJAX de verificación al Backend BFF @@ -268,6 +305,8 @@ message: 'Error de conexión con el validador.', todays_classes: [] }); + } finally { + setTimeout(focusScannerInput, 150); } } @@ -386,5 +425,51 @@ setTimeout(() => { osc.stop(); }, 120); } catch (e) {} } + + // Eventos globales para forzar el foco permanente en scannerInput + document.addEventListener('DOMContentLoaded', () => { + focusScannerInput(); + setInterval(focusScannerInput, 2000); + + const input = document.getElementById('scannerInput'); + if (input) { + input.addEventListener('focus', () => updateFocusIndicator(true)); + input.addEventListener('blur', () => { + setTimeout(() => { + const active = document.activeElement; + if (active && active.id !== 'buildingSelect') { + focusScannerInput(); + } else { + updateFocusIndicator(false); + } + }, 100); + }); + } + }); + + window.addEventListener('focus', focusScannerInput); + + document.addEventListener('click', (e) => { + // Si el usuario no hace clic sobre el selector de sedes o botones interactivos, regresar el cursor al input + if (!e.target.closest('select, button, a, #reader')) { + focusScannerInput(); + } + }); + + {% endblock %}