304 lines
14 KiB
HTML
304 lines
14 KiB
HTML
<style>
|
|
/* Asegurar aislamiento modal total e impedir scroll o clics detrás */
|
|
#userQrCredentialModal {
|
|
z-index: 1080 !important;
|
|
overscroll-behavior: contain;
|
|
}
|
|
.modal-backdrop.show {
|
|
z-index: 1075 !important;
|
|
opacity: 0.65 !important;
|
|
}
|
|
html.modal-open,
|
|
body.modal-open {
|
|
overflow: hidden !important;
|
|
height: 100% !important;
|
|
touch-action: none;
|
|
overscroll-behavior: none;
|
|
}
|
|
</style>
|
|
|
|
<!-- Modal Global de Credencial Digital QR del Usuario (UniCABA) -->
|
|
<div class="modal fade" id="userQrCredentialModal" tabindex="-1" aria-labelledby="userQrCredentialModalLabel" aria-hidden="true" data-bs-backdrop="true" data-bs-keyboard="true">
|
|
<div class="modal-dialog modal-dialog-centered" style="max-width: 440px;">
|
|
<div class="modal-content border-0 shadow-lg overflow-hidden" style="border-radius: 18px;">
|
|
<!-- Encabezado con estética de Carnet Universitario -->
|
|
<div class="p-4 text-white position-relative" style="background: linear-gradient(135deg, #1E1B4B 0%, #4338CA 50%, #B43E8E 100%);">
|
|
<button type="button" class="btn-close btn-close-white position-absolute top-0 end-0 m-3" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
|
<div class="d-flex align-items-center gap-2 mb-2">
|
|
<img src="/img/logo_unicaba_mini.png" alt="UniCABA" height="26" class="bg-white rounded-circle p-1 shadow-sm">
|
|
<span class="fw-bold tracking-wider fs-6 text-uppercase">UniCABA · Identidad Digital</span>
|
|
</div>
|
|
<div class="d-flex align-items-center justify-content-between mt-2">
|
|
<div>
|
|
<h5 class="modal-title fw-bold text-white mb-0" id="userQrCredentialModalLabel">
|
|
Credencial Universitaria
|
|
</h5>
|
|
<p class="text-white-50 small mb-0 mt-1">Acceso a sedes y convenios de beneficios</p>
|
|
</div>
|
|
<span class="badge bg-success-subtle text-success border border-success-subtle rounded-pill px-2 py-1 small fw-bold">
|
|
● ACTIVO
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Cuerpo del Modal -->
|
|
<div class="modal-body p-4 text-center">
|
|
<!-- Datos del Usuario -->
|
|
<div class="mb-3">
|
|
<h5 class="fw-bold mb-1 text-body" id="modalQrUserName">
|
|
{{ auth_user.name if (auth_user and auth_user.name) else (user.name if user else 'Usuario') }}
|
|
</h5>
|
|
<div class="d-flex align-items-center justify-content-center gap-2 flex-wrap mb-2">
|
|
<span class="badge bg-primary-subtle text-primary border border-primary-subtle font-monospace text-uppercase" style="font-size: 0.74rem;">
|
|
{{ auth_user.role_badge_display.label if (auth_user and auth_user.role_badge_display) else (auth_user.role|upper if auth_user else 'ALUMNO') }}
|
|
</span>
|
|
{% if auth_user and (auth_user.document_number or auth_user.dni) %}
|
|
<span class="badge bg-body-tertiary text-body-secondary border font-monospace" style="font-size: 0.74rem;">
|
|
DNI: {{ auth_user.document_number or auth_user.dni }}
|
|
</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="text-muted small font-monospace" style="font-size: 0.78rem;">
|
|
{{ auth_user.email if auth_user else '' }}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Contenedor del Código QR Dinámico -->
|
|
<div class="p-3 bg-body-tertiary border rounded-4 d-inline-block shadow-sm my-2 position-relative" style="background-color: var(--bs-body-bg) !important;">
|
|
<div id="globalQrModalContainer" class="d-flex align-items-center justify-content-center" style="min-width: 190px; min-height: 190px;">
|
|
<div class="spinner-border text-primary" role="status" id="globalQrSpinner">
|
|
<span class="visually-hidden">Generando credencial QR...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Barra de Progreso y Cuenta Regresiva de Renovación Dinámica -->
|
|
<div class="mt-2 mb-2 px-3" style="max-width: 260px; margin: 0 auto;">
|
|
<div class="progress" style="height: 4px; background-color: rgba(180, 62, 142, 0.15); border-radius: 4px;">
|
|
<div id="modalQrProgressBar" class="progress-bar" role="progressbar" style="width: 100%; background: linear-gradient(90deg, #4338CA, #B43E8E); transition: width 0.1s linear;"></div>
|
|
</div>
|
|
<div class="d-flex justify-content-between align-items-center mt-1 text-muted small" style="font-size: 0.72rem;">
|
|
<span class="d-flex align-items-center gap-1">
|
|
<span class="spinner-grow spinner-grow-sm text-success" style="width: 6px; height: 6px;" role="status"></span>
|
|
<span class="text-success fw-semibold">Anti-captura activo</span>
|
|
</span>
|
|
<span>Renueva en <strong id="modalQrCountdown" class="font-monospace text-primary">3s</strong></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Información de Validez y Seguridad -->
|
|
<div class="mt-2 mb-3">
|
|
<div class="d-inline-flex align-items-center gap-1 text-success small fw-semibold">
|
|
<i class="bi bi-shield-check"></i>
|
|
<span>Firma Criptográfica Verificada</span>
|
|
</div>
|
|
<div class="text-muted small mt-1" style="font-size: 0.73rem;" id="modalQrValidityText">
|
|
<i class="bi bi-arrow-repeat me-1"></i>Código dinámico con rotación cada 3 seg
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Botón de Acción -->
|
|
<div class="d-grid">
|
|
<a href="/credential/my-card" id="modalBtnVerCarnet" class="btn btn-primary py-2 rounded-3 shadow-xs d-flex align-items-center justify-content-center">
|
|
<i class="bi bi-person-badge me-2"></i>Ver Carnet Completo
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Footer Informativo -->
|
|
<div class="modal-footer bg-body-tertiary py-2 px-3 border-top d-flex justify-content-between align-items-center">
|
|
<small class="text-muted" style="font-size: 0.72rem;">
|
|
<i class="bi bi-info-circle me-1"></i>Escanea en recepción para ingresar
|
|
</small>
|
|
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">
|
|
Cerrar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
(function() {
|
|
let qrModalInstance = null;
|
|
let timerId = null;
|
|
let renewalInterval = 3;
|
|
let elapsedMs = 0;
|
|
const tickIntervalMs = 100;
|
|
let isFetching = false;
|
|
|
|
// Detectar si la página activa es /credential/my-card
|
|
const isCarnetPage = window.location.pathname.includes('/credential/my-card') ||
|
|
window.location.pathname.endsWith('/credential') ||
|
|
window.location.pathname.includes('/mi-credencial');
|
|
|
|
function renderModalQR(token) {
|
|
const container = document.getElementById('globalQrModalContainer');
|
|
if (!container) return;
|
|
|
|
try {
|
|
if (qrModalInstance && typeof qrModalInstance.makeCode === 'function') {
|
|
qrModalInstance.makeCode(token);
|
|
} else {
|
|
container.innerHTML = '';
|
|
if (typeof QRCode !== 'undefined') {
|
|
qrModalInstance = new QRCode(container, {
|
|
text: token,
|
|
width: 180,
|
|
height: 180,
|
|
colorDark: "#0F172A",
|
|
colorLight: "#FFFFFF",
|
|
correctLevel: QRCode.CorrectLevel.M
|
|
});
|
|
} else {
|
|
container.innerHTML = '<div class="alert alert-warning p-2 small">Código disponible: ' + token.substring(0, 16) + '...</div>';
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error('Error generando QR en modal:', err);
|
|
container.innerHTML = '<div class="alert alert-secondary p-2 small font-monospace">Credencial institucional activa</div>';
|
|
}
|
|
}
|
|
|
|
function updateProgressUi() {
|
|
const progressBar = document.getElementById('modalQrProgressBar');
|
|
const countdownEl = document.getElementById('modalQrCountdown');
|
|
const totalMs = renewalInterval * 1000;
|
|
const remainingMs = Math.max(0, totalMs - elapsedMs);
|
|
const pct = Math.max(0, Math.min(100, (remainingMs / totalMs) * 100));
|
|
|
|
if (progressBar) {
|
|
progressBar.style.width = pct + '%';
|
|
}
|
|
if (countdownEl) {
|
|
countdownEl.textContent = (remainingMs / 1000).toFixed(1) + 's';
|
|
}
|
|
}
|
|
|
|
function fetchAndRenderToken() {
|
|
if (isFetching) return;
|
|
isFetching = true;
|
|
|
|
fetch('/credential/token')
|
|
.then(function(res) {
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
return res.json();
|
|
})
|
|
.then(function(data) {
|
|
if (data && data.qr_token) {
|
|
if (data.renewal_interval_seconds && data.renewal_interval_seconds > 0) {
|
|
renewalInterval = data.renewal_interval_seconds;
|
|
}
|
|
renderModalQR(data.qr_token);
|
|
const valText = document.getElementById('modalQrValidityText');
|
|
if (valText) {
|
|
valText.innerHTML = '<i class="bi bi-arrow-repeat me-1"></i>Código dinámico con rotación cada ' + renewalInterval + ' seg';
|
|
}
|
|
} else {
|
|
throw new Error('Token no disponible');
|
|
}
|
|
})
|
|
.catch(function(err) {
|
|
console.warn('Fallback a token local para QR modal:', err);
|
|
const 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' }}";
|
|
renderModalQR(fallback);
|
|
})
|
|
.finally(function() {
|
|
isFetching = false;
|
|
elapsedMs = 0;
|
|
updateProgressUi();
|
|
});
|
|
}
|
|
|
|
function startAutoRefreshLoop() {
|
|
stopAutoRefreshLoop();
|
|
elapsedMs = 0;
|
|
updateProgressUi();
|
|
fetchAndRenderToken();
|
|
|
|
timerId = setInterval(function() {
|
|
elapsedMs += tickIntervalMs;
|
|
updateProgressUi();
|
|
|
|
if (elapsedMs >= renewalInterval * 1000) {
|
|
elapsedMs = 0;
|
|
fetchAndRenderToken();
|
|
}
|
|
}, tickIntervalMs);
|
|
}
|
|
|
|
function stopAutoRefreshLoop() {
|
|
if (timerId) {
|
|
clearInterval(timerId);
|
|
timerId = null;
|
|
}
|
|
qrModalInstance = null;
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const modalEl = document.getElementById('userQrCredentialModal');
|
|
if (!modalEl) return;
|
|
|
|
// Desacople total si estamos en la vista de carnet completo:
|
|
if (isCarnetPage) {
|
|
// El usuario ya está viendo su credencial en pantalla completa:
|
|
// Interceptamos los botones de barra y menú para evitar solapamientos y bloqueos
|
|
document.querySelectorAll('[data-bs-target="#userQrCredentialModal"]').forEach(function(btn) {
|
|
btn.removeAttribute('data-bs-toggle');
|
|
btn.removeAttribute('data-bs-target');
|
|
btn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
// Scroll suave y destello elegante en la credencial ya visible
|
|
const card = document.querySelector('.card[style*="linear-gradient"]');
|
|
if (card) {
|
|
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
card.style.transform = 'scale(1.02)';
|
|
card.style.transition = 'transform 0.25s ease, box-shadow 0.25s ease';
|
|
card.style.boxShadow = '0 0 25px rgba(180, 62, 142, 0.6)';
|
|
setTimeout(function() {
|
|
card.style.transform = '';
|
|
card.style.boxShadow = '';
|
|
}, 600);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Si por algún enlace previo o history el modal estuviese abierto, cerrarlo inmediatamente
|
|
const existingModal = bootstrap.Modal.getInstance(modalEl);
|
|
if (existingModal) {
|
|
existingModal.hide();
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Si estamos en cualquier otra página del sistema:
|
|
const btnVerCarnet = document.getElementById('modalBtnVerCarnet');
|
|
if (btnVerCarnet) {
|
|
btnVerCarnet.addEventListener('click', function() {
|
|
const inst = bootstrap.Modal.getInstance(modalEl);
|
|
if (inst) inst.hide();
|
|
});
|
|
}
|
|
|
|
// Utilizar shown.bs.modal (cuando la animación fade terminó y el modal es 100% visible)
|
|
modalEl.addEventListener('shown.bs.modal', function() {
|
|
document.documentElement.classList.add('modal-open');
|
|
document.body.classList.add('modal-open');
|
|
startAutoRefreshLoop();
|
|
});
|
|
|
|
// Limpieza innegociable al ocultar el modal:
|
|
modalEl.addEventListener('hidden.bs.modal', function() {
|
|
stopAutoRefreshLoop();
|
|
document.documentElement.classList.remove('modal-open');
|
|
document.body.classList.remove('modal-open');
|
|
document.documentElement.style.overflow = '';
|
|
document.body.style.overflow = '';
|
|
document.querySelectorAll('.modal-backdrop').forEach(function(b) {
|
|
b.remove();
|
|
});
|
|
});
|
|
});
|
|
})();
|
|
</script>
|