fix(parent): modal vincular hijo con pestañas camara/codigo y tarjeta de verificacion previa
This commit is contained in:
+87
-21
@@ -10,7 +10,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<meta name="apple-mobile-web-app-title" content="RecreoPay">
|
<meta name="apple-mobile-web-app-title" content="RecreoPay">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<link rel="stylesheet" href="/css/styles.css?v=8.5">
|
<link rel="stylesheet" href="/css/styles.css?v=8.6">
|
||||||
<style>
|
<style>
|
||||||
/* Transiciones suaves */
|
/* Transiciones suaves */
|
||||||
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
||||||
@@ -1022,35 +1022,101 @@
|
|||||||
<span>💸</span> Enviar Dinero al Instante
|
<span>💸</span> Enviar Dinero al Instante
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<!-- MODAL: ESCANEAR QR PARA VINCULAR HIJO (PORTAL PADRES) -->
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MODAL: VINCULAR HIJO POR QR O CÓDIGO (PORTAL PADRES) -->
|
||||||
<div class="modal-qr-backdrop" id="modalScanChildQr" style="display: none;" onclick="closeScanChildQrModal(event)">
|
<div class="modal-qr-backdrop" id="modalScanChildQr" style="display: none;" onclick="closeScanChildQrModal(event)">
|
||||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 400px; text-align: center;">
|
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: center; border-radius: 20px;">
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px;">
|
|
||||||
<strong style="font-size: 1rem; color: var(--text-main);">📷 Vincular Estudiante con QR</strong>
|
<!-- CABECERA -->
|
||||||
<button type="button" onclick="closeScanChildQrModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted);">✕</button>
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 10px;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.3rem;">🎒</span>
|
||||||
|
<strong style="font-size: 1.05rem; color: var(--text-main);">Vincular Estudiante</strong>
|
||||||
|
</div>
|
||||||
|
<button type="button" onclick="closeScanChildQrModal()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="position: relative; width: 100%; height: 220px; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 10px;">
|
<!-- VISTA 1: SELECCIÓN DE MÉTODO (PESTAÑAS) -->
|
||||||
<video id="videoScanChild" playsinline autoplay muted style="width: 100%; height: 100%; object-fit: cover;"></video>
|
<div id="linkChildViewTabs">
|
||||||
|
<div style="display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 12px; margin-bottom: 14px;">
|
||||||
|
<button type="button" id="tabBtnLinkCamera" onclick="switchLinkChildTab('camera')" style="flex: 1; padding: 9px 8px; border: none; border-radius: 8px; font-weight: 800; font-size: 0.82rem; cursor: pointer; transition: all 0.2s; background: #ffffff; color: #0284c7; box-shadow: 0 2px 4px rgba(0,0,0,0.06);">
|
||||||
|
📷 Escanear con Cámara
|
||||||
|
</button>
|
||||||
|
<button type="button" id="tabBtnLinkCode" onclick="switchLinkChildTab('code')" style="flex: 1; padding: 9px 8px; border: none; border-radius: 8px; font-weight: 700; font-size: 0.82rem; cursor: pointer; transition: all 0.2s; background: transparent; color: #64748b;">
|
||||||
|
⌨️ Digitar Código
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- PANEL 1: CÁMARA QR -->
|
||||||
|
<div id="panelLinkCamera" style="display: block;">
|
||||||
|
<div style="position: relative; width: 100%; height: 220px; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 10px; border: 2px solid #0284c7;">
|
||||||
|
<video id="videoScanChild" playsinline webkit-playsinline autoplay muted style="width: 100%; height: 100%; object-fit: cover;"></video>
|
||||||
<canvas id="canvasScanChild" style="display: none;"></canvas>
|
<canvas id="canvasScanChild" style="display: none;"></canvas>
|
||||||
<div style="position: absolute; inset: 16px; border: 2px dashed #38bdf8; border-radius: 12px; pointer-events: none;"></div>
|
<div class="laser-scan-line"></div>
|
||||||
|
<div id="badgeCameraChildStatus" style="position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, 0.9); color: #38bdf8; padding: 3px 12px; border-radius: 20px; font-size: 0.72rem; font-weight: 800; border: 1px solid #0284c7; white-space: nowrap;">
|
||||||
|
📷 Apunta al código QR del carné
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: 0.78rem; color: var(--text-muted); margin: 0 0 10px 0;">
|
||||||
|
Apunta la cámara hacia el código QR impreso en el carné del estudiante.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p style="font-size: 0.78rem; color: var(--text-muted); margin-bottom: 10px;">
|
<!-- PANEL 2: DIGITAR CÓDIGO -->
|
||||||
Apunta la cámara al carné escolar del estudiante.
|
<div id="panelLinkCode" style="display: none; text-align: left;">
|
||||||
|
<label for="inputManualStudentCode" style="display: block; font-size: 0.8rem; font-weight: 800; color: var(--text-main); margin-bottom: 6px;">
|
||||||
|
Código de carné del estudiante:
|
||||||
|
</label>
|
||||||
|
<div style="display: flex; gap: 8px; margin-bottom: 6px;">
|
||||||
|
<input type="text" id="inputManualStudentCode" placeholder="Ej: EST-2026-001" onkeydown="if(event.key==='Enter'){event.preventDefault();validateStudentCodeForLink();}" style="flex: 1; padding: 11px 12px; border-radius: 10px; border: 2px solid var(--border); font-size: 0.95rem; font-weight: 800; background: var(--card-bg); color: var(--text-main); box-sizing: border-box; text-transform: uppercase;">
|
||||||
|
<button type="button" id="btnValidateStudentCode" onclick="validateStudentCodeForLink()" style="padding: 10px 16px; background: #0284c7; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.85rem; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 4px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);">
|
||||||
|
<span>🔍</span> Validar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: 0.75rem; color: var(--text-muted); margin: 0 0 10px 0;">
|
||||||
|
💡 Digita el código que aparece en el carné escolar (ej: EST-2026-001).
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MENSAJE DE ERROR -->
|
||||||
|
<div id="linkStudentErrorMsg" style="display: none; background: #fee2e2; border: 1.5px solid #ef4444; color: #991b1b; padding: 10px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: 700; margin-top: 10px; text-align: center;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- VISTA 2: TARJETA DE VERIFICACIÓN / CONFIRMACIÓN -->
|
||||||
|
<div id="linkChildViewConfirm" style="display: none; text-align: left;">
|
||||||
|
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 14px; padding: 10px 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.2rem;">✅</span>
|
||||||
|
<span style="font-size: 0.82rem; font-weight: 800; color: #166534;">Estudiante Identificado Correctamente</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- TARJETA DEL ESTUDIANTE -->
|
||||||
|
<div style="background: var(--card-bg); border: 2px solid #0284c7; border-radius: 16px; padding: 14px; margin-bottom: 14px; display: flex; align-items: center; gap: 14px; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.1);">
|
||||||
|
<img id="linkPreviewAvatar" src="" style="width: 58px; height: 58px; border-radius: 50%; border: 2.5px solid #0284c7; object-fit: cover; background: white; flex-shrink: 0;">
|
||||||
|
<div style="flex: 1; min-width: 0;">
|
||||||
|
<div style="font-size: 0.7rem; color: #64748b; font-weight: 800; text-transform: uppercase;">Alumno a vincular:</div>
|
||||||
|
<h3 id="linkPreviewName" style="font-size: 1.05rem; font-weight: 900; color: var(--text-main); margin: 2px 0; word-break: break-word; line-height: 1.2;">Nombre Alumno</h3>
|
||||||
|
<div id="linkPreviewGrade" style="font-size: 0.8rem; color: #0284c7; font-weight: 800; margin-top: 2px;">2° Grado - Sección 2-A</div>
|
||||||
|
<div id="linkPreviewCode" style="font-size: 0.72rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Carné: EST-2026-001</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p style="font-size: 0.78rem; color: var(--text-muted); margin: 0 0 14px 0; text-align: center;">
|
||||||
|
¿Confirmas que este es tu hijo/a para vincularlo a tu cuenta y gestionar sus fondos?
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div style="border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 10px; text-align: left;">
|
<!-- BOTONES DE ACCIÓN -->
|
||||||
<label for="inputManualStudentCode" style="display: block; font-size: 0.76rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">
|
<div style="display: flex; gap: 8px;">
|
||||||
O escribe el código de carné manualmente:
|
<button type="button" onclick="resetLinkChildToTabs()" style="flex: 1; padding: 11px; background: #f1f5f9; color: #475569; border: 1px solid var(--border); border-radius: 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer;">
|
||||||
</label>
|
← Cambiar
|
||||||
<div style="display: flex; gap: 6px;">
|
</button>
|
||||||
<input type="text" id="inputManualStudentCode" placeholder="Ej: EST-2026-001 o QR Token" style="flex: 1; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.85rem; font-weight: 800; background: var(--card-bg); color: var(--text-main); box-sizing: border-box;">
|
<button type="button" id="btnConfirmLinkChild" onclick="confirmLinkValidatedChild()" style="flex: 2; padding: 11px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
|
||||||
<button type="button" onclick="submitManualStudentLink()" style="padding: 8px 14px; background: #0284c7; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.8rem; cursor: pointer; white-space: nowrap;">
|
<span>✅</span> Confirmar y Vincular
|
||||||
Vincular
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1098,8 +1164,8 @@
|
|||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<script src="/js/sounds.js?v=8.5"></script>
|
<script src="/js/sounds.js?v=8.6"></script>
|
||||||
<script src="/js/jsQR.js"></script>
|
<script src="/js/jsQR.js"></script>
|
||||||
<script src="/js/app.js?v=8.5"></script>
|
<script src="/js/app.js?v=8.6"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+181
-13
@@ -1899,12 +1899,18 @@ function returnToParentDashboard() {
|
|||||||
// ESCANEO QR Y VINCULACIÓN DE ESTUDIANTES PARA PADRES
|
// ESCANEO QR Y VINCULACIÓN DE ESTUDIANTES PARA PADRES
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
|
let currentLinkChildTab = 'camera';
|
||||||
|
let currentLinkCandidateStudent = null;
|
||||||
|
|
||||||
function openScanChildQrModal() {
|
function openScanChildQrModal() {
|
||||||
const modal = document.getElementById('modalScanChildQr');
|
const modal = document.getElementById('modalScanChildQr');
|
||||||
if (modal) modal.style.display = 'flex';
|
if (modal) modal.style.display = 'flex';
|
||||||
|
|
||||||
const input = document.getElementById('inputManualStudentCode');
|
const input = document.getElementById('inputManualStudentCode');
|
||||||
if (input) input.value = '';
|
if (input) input.value = '';
|
||||||
startScanChildCamera();
|
|
||||||
|
resetLinkChildToTabs();
|
||||||
|
switchLinkChildTab('camera');
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeScanChildQrModal(event) {
|
function closeScanChildQrModal(event) {
|
||||||
@@ -1914,12 +1920,64 @@ function closeScanChildQrModal(event) {
|
|||||||
stopScanChildCamera();
|
stopScanChildCamera();
|
||||||
const modal = document.getElementById('modalScanChildQr');
|
const modal = document.getElementById('modalScanChildQr');
|
||||||
if (modal) modal.style.display = 'none';
|
if (modal) modal.style.display = 'none';
|
||||||
|
currentLinkCandidateStudent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchLinkChildTab(tab) {
|
||||||
|
currentLinkChildTab = tab;
|
||||||
|
const btnCamera = document.getElementById('tabBtnLinkCamera');
|
||||||
|
const btnCode = document.getElementById('tabBtnLinkCode');
|
||||||
|
const panelCamera = document.getElementById('panelLinkCamera');
|
||||||
|
const panelCode = document.getElementById('panelLinkCode');
|
||||||
|
const errorMsg = document.getElementById('linkStudentErrorMsg');
|
||||||
|
if (errorMsg) errorMsg.style.display = 'none';
|
||||||
|
|
||||||
|
if (tab === 'camera') {
|
||||||
|
if (btnCamera) {
|
||||||
|
btnCamera.style.background = '#ffffff';
|
||||||
|
btnCamera.style.color = '#0284c7';
|
||||||
|
btnCamera.style.boxShadow = '0 2px 4px rgba(0,0,0,0.06)';
|
||||||
|
btnCamera.style.fontWeight = '800';
|
||||||
|
}
|
||||||
|
if (btnCode) {
|
||||||
|
btnCode.style.background = 'transparent';
|
||||||
|
btnCode.style.color = '#64748b';
|
||||||
|
btnCode.style.boxShadow = 'none';
|
||||||
|
btnCode.style.fontWeight = '700';
|
||||||
|
}
|
||||||
|
if (panelCamera) panelCamera.style.display = 'block';
|
||||||
|
if (panelCode) panelCode.style.display = 'none';
|
||||||
|
startScanChildCamera();
|
||||||
|
} else {
|
||||||
|
stopScanChildCamera();
|
||||||
|
if (btnCode) {
|
||||||
|
btnCode.style.background = '#ffffff';
|
||||||
|
btnCode.style.color = '#0284c7';
|
||||||
|
btnCode.style.boxShadow = '0 2px 4px rgba(0,0,0,0.06)';
|
||||||
|
btnCode.style.fontWeight = '800';
|
||||||
|
}
|
||||||
|
if (btnCamera) {
|
||||||
|
btnCamera.style.background = 'transparent';
|
||||||
|
btnCamera.style.color = '#64748b';
|
||||||
|
btnCamera.style.boxShadow = 'none';
|
||||||
|
btnCamera.style.fontWeight = '700';
|
||||||
|
}
|
||||||
|
if (panelCamera) panelCamera.style.display = 'none';
|
||||||
|
if (panelCode) panelCode.style.display = 'block';
|
||||||
|
const input = document.getElementById('inputManualStudentCode');
|
||||||
|
if (input) {
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startScanChildCamera() {
|
async function startScanChildCamera() {
|
||||||
stopScanChildCamera();
|
stopScanChildCamera();
|
||||||
const video = document.getElementById('videoScanChild');
|
const video = document.getElementById('videoScanChild');
|
||||||
const canvas = document.getElementById('canvasScanChild');
|
const canvas = document.getElementById('canvasScanChild');
|
||||||
|
const badge = document.getElementById('badgeCameraChildStatus');
|
||||||
if (!video || !canvas) return;
|
if (!video || !canvas) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1927,9 +1985,16 @@ async function startScanChildCamera() {
|
|||||||
video: { facingMode: 'environment', width: { ideal: 640 }, height: { ideal: 480 } }
|
video: { facingMode: 'environment', width: { ideal: 640 }, height: { ideal: 480 } }
|
||||||
});
|
});
|
||||||
video.srcObject = scanChildStream;
|
video.srcObject = scanChildStream;
|
||||||
video.setAttribute('playsinline', true);
|
video.setAttribute('playsinline', 'true');
|
||||||
|
video.setAttribute('webkit-playsinline', 'true');
|
||||||
|
video.muted = true;
|
||||||
await video.play();
|
await video.play();
|
||||||
|
|
||||||
|
if (badge) {
|
||||||
|
badge.textContent = '📷 Apunta al código QR del carné';
|
||||||
|
badge.style.color = '#38bdf8';
|
||||||
|
}
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
||||||
|
|
||||||
function scanFrame() {
|
function scanFrame() {
|
||||||
@@ -1953,6 +2018,10 @@ async function startScanChildCamera() {
|
|||||||
scanChildAnimId = requestAnimationFrame(scanFrame);
|
scanChildAnimId = requestAnimationFrame(scanFrame);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Cámara no disponible para escaneo de carné:', err);
|
console.warn('Cámara no disponible para escaneo de carné:', err);
|
||||||
|
if (badge) {
|
||||||
|
badge.textContent = '⚠️ Cámara no disponible - Digita el código';
|
||||||
|
badge.style.color = '#fca5a5';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1965,29 +2034,128 @@ function stopScanChildCamera() {
|
|||||||
scanChildStream.getTracks().forEach(t => t.stop());
|
scanChildStream.getTracks().forEach(t => t.stop());
|
||||||
scanChildStream = null;
|
scanChildStream = null;
|
||||||
}
|
}
|
||||||
|
const video = document.getElementById('videoScanChild');
|
||||||
|
if (video) {
|
||||||
|
video.srcObject = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleChildQrDetected(token) {
|
async function handleChildQrDetected(token) {
|
||||||
stopScanChildCamera();
|
stopScanChildCamera();
|
||||||
if (window.sounds) window.sounds.playBeep();
|
if (window.sounds) window.sounds.playScanChirp();
|
||||||
await linkStudentToParentAccount(token);
|
await showStudentConfirmationForLink(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitManualStudentLink() {
|
async function validateStudentCodeForLink() {
|
||||||
const input = document.getElementById('inputManualStudentCode');
|
const input = document.getElementById('inputManualStudentCode');
|
||||||
const val = input ? input.value.trim() : '';
|
const val = input ? input.value.trim() : '';
|
||||||
|
const errorMsg = document.getElementById('linkStudentErrorMsg');
|
||||||
|
const btn = document.getElementById('btnValidateStudentCode');
|
||||||
|
|
||||||
if (!val) {
|
if (!val) {
|
||||||
alert('Por favor ingresa el carné o token del estudiante.');
|
if (errorMsg) {
|
||||||
|
errorMsg.textContent = '⚠️ Por favor ingresa el código del estudiante (ej: EST-2026-001).';
|
||||||
|
errorMsg.style.display = 'block';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
linkStudentToParentAccount(val);
|
|
||||||
|
if (errorMsg) errorMsg.style.display = 'none';
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = 'Buscando...';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await showStudentConfirmationForLink(val);
|
||||||
|
} finally {
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = '<span>🔍</span> Validar';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function linkStudentToParentAccount(tokenOrCode) {
|
async function showStudentConfirmationForLink(tokenOrCode) {
|
||||||
|
const errorMsg = document.getElementById('linkStudentErrorMsg');
|
||||||
|
if (errorMsg) errorMsg.style.display = 'none';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/estudiantes/qr/${encodeURIComponent(tokenOrCode.trim())}`);
|
||||||
|
const student = await res.json();
|
||||||
|
if (!res.ok) throw new Error(student.error || 'Código escolar no encontrado');
|
||||||
|
|
||||||
|
currentLinkCandidateStudent = student;
|
||||||
|
|
||||||
|
// Poblar tarjeta de confirmación
|
||||||
|
const avatar = document.getElementById('linkPreviewAvatar');
|
||||||
|
const name = document.getElementById('linkPreviewName');
|
||||||
|
const grade = document.getElementById('linkPreviewGrade');
|
||||||
|
const code = document.getElementById('linkPreviewCode');
|
||||||
|
|
||||||
|
if (avatar) avatar.src = student.foto_url || '/img/avatar_default.png';
|
||||||
|
if (name) name.textContent = student.nombre_completo;
|
||||||
|
if (grade) grade.textContent = `${student.grado} - Sección ${student.seccion}`;
|
||||||
|
if (code) code.textContent = `Carné: ${student.codigo_estudiante}`;
|
||||||
|
|
||||||
|
// Cambiar a vista de confirmación
|
||||||
|
const viewTabs = document.getElementById('linkChildViewTabs');
|
||||||
|
const viewConfirm = document.getElementById('linkChildViewConfirm');
|
||||||
|
if (viewTabs) viewTabs.style.display = 'none';
|
||||||
|
if (viewConfirm) viewConfirm.style.display = 'block';
|
||||||
|
|
||||||
|
if (window.sounds) window.sounds.playSuccess();
|
||||||
|
} catch (err) {
|
||||||
|
if (window.sounds) window.sounds.playError();
|
||||||
|
if (errorMsg) {
|
||||||
|
errorMsg.textContent = `⚠️ No se encontró ningún estudiante con el código "${tokenOrCode}". Verifica que el código esté bien escrito e intenta de nuevo.`;
|
||||||
|
errorMsg.style.display = 'block';
|
||||||
|
}
|
||||||
|
// Si estábamos en cámara, reiniciar escaneo tras 2 segundos si el usuario sigue en la pestaña cámara
|
||||||
|
if (currentLinkChildTab === 'camera') {
|
||||||
|
setTimeout(() => {
|
||||||
|
const modal = document.getElementById('modalScanChildQr');
|
||||||
|
if (modal && modal.style.display !== 'none' && currentLinkChildTab === 'camera' && !currentLinkCandidateStudent) {
|
||||||
|
startScanChildCamera();
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetLinkChildToTabs() {
|
||||||
|
currentLinkCandidateStudent = null;
|
||||||
|
const viewTabs = document.getElementById('linkChildViewTabs');
|
||||||
|
const viewConfirm = document.getElementById('linkChildViewConfirm');
|
||||||
|
const errorMsg = document.getElementById('linkStudentErrorMsg');
|
||||||
|
|
||||||
|
if (viewTabs) viewTabs.style.display = 'block';
|
||||||
|
if (viewConfirm) viewConfirm.style.display = 'none';
|
||||||
|
if (errorMsg) errorMsg.style.display = 'none';
|
||||||
|
|
||||||
|
if (currentLinkChildTab === 'camera') {
|
||||||
|
startScanChildCamera();
|
||||||
|
} else {
|
||||||
|
const input = document.getElementById('inputManualStudentCode');
|
||||||
|
if (input) input.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmLinkValidatedChild() {
|
||||||
if (!currentUser || !currentUser.id) {
|
if (!currentUser || !currentUser.id) {
|
||||||
alert('Debes iniciar sesión como padre para vincular un estudiante.');
|
alert('Debes iniciar sesión como padre para vincular un estudiante.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!currentLinkCandidateStudent) {
|
||||||
|
alert('No hay ningún estudiante seleccionado para vincular.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const btnConfirm = document.getElementById('btnConfirmLinkChild');
|
||||||
|
if (btnConfirm) {
|
||||||
|
btnConfirm.disabled = true;
|
||||||
|
btnConfirm.innerHTML = '<span>⏳</span> Vinculando...';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/padres/vincular-hijo', {
|
const res = await fetch('/api/padres/vincular-hijo', {
|
||||||
@@ -1995,7 +2163,7 @@ async function linkStudentToParentAccount(tokenOrCode) {
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
padre_usuario_id: currentUser.id,
|
padre_usuario_id: currentUser.id,
|
||||||
qr_token_o_codigo: tokenOrCode
|
qr_token_o_codigo: currentLinkCandidateStudent.codigo_estudiante || currentLinkCandidateStudent.qr_token
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -2012,10 +2180,10 @@ async function linkStudentToParentAccount(tokenOrCode) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (window.sounds) window.sounds.playError();
|
if (window.sounds) window.sounds.playError();
|
||||||
alert(`❌ ${err.message}`);
|
alert(`❌ ${err.message}`);
|
||||||
// Reiniciar cámara si el modal sigue abierto
|
} finally {
|
||||||
const modal = document.getElementById('modalScanChildQr');
|
if (btnConfirm) {
|
||||||
if (modal && modal.style.display !== 'none') {
|
btnConfirm.disabled = false;
|
||||||
startScanChildCamera();
|
btnConfirm.innerHTML = '<span>✅</span> Confirmar y Vincular';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user