fix: contador y countdown de tomas prolongadas en lugar.php
- _guardarFirmaMP ahora llama guardar_toma.php en vez del draft POST, guardando la firma con clave campoId (sin _svg) que es la que lee get_consentimientos para el contador X/13. guardar_toma.php también actualiza estado→en_progreso y siguiente_toma_at, lo que activa el countdown en lugar.php via polling SSE. - Al completar la última toma envía postMessage turneroFirmado para cerrar el modal automáticamente. - Botón cerrar del modal siempre habilitado (el operador puede cerrar en cualquier momento durante el proceso). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d2c1b58c2e
commit
4135e74d84
@@ -1391,7 +1391,7 @@ function abrirTomaProgresiva(token, turnoId, formularioId) {
|
||||
load.style.display = '';
|
||||
modal.style.display = 'flex';
|
||||
_tomaProgresivaActiva = true;
|
||||
_setBtnCerrarConsent(false);
|
||||
_setBtnCerrarConsent(true);
|
||||
setTimeout(() => {
|
||||
iframe.src = `${BASE_WA}ver_formulario_enviado.php?token=${encodeURIComponent(token)}&embed=1&compact=1&modo=toma_progresiva`;
|
||||
}, 80);
|
||||
@@ -1400,13 +1400,12 @@ function abrirTomaProgresiva(token, turnoId, formularioId) {
|
||||
function _setBtnCerrarConsent(habilitado) {
|
||||
const btn = document.getElementById('btn-cerrar-modal-consent');
|
||||
if (!btn) return;
|
||||
btn.disabled = !habilitado;
|
||||
btn.disabled = !habilitado;
|
||||
btn.style.opacity = habilitado ? '' : '.25';
|
||||
btn.title = habilitado ? 'Cerrar' : 'No puede cerrar durante una toma en progreso';
|
||||
btn.title = habilitado ? 'Cerrar' : 'Cerrando...';
|
||||
}
|
||||
|
||||
function cerrarModalConsentimiento(forzar) {
|
||||
if (!forzar && _tomaProgresivaActiva) return; // bloqueado hasta finalizar toma
|
||||
_tomaProgresivaActiva = false;
|
||||
_setBtnCerrarConsent(true);
|
||||
const modal = document.getElementById('modal-consentimiento');
|
||||
@@ -1421,13 +1420,13 @@ function cerrarModalConsentimiento(forzar) {
|
||||
window.addEventListener('message', function(e) {
|
||||
if (e.data && e.data.type === 'tomaProgresivaIniciada') {
|
||||
_tomaProgresivaActiva = true;
|
||||
_setBtnCerrarConsent(false);
|
||||
// Botón cerrar permanece habilitado; el operador puede cerrar en cualquier momento
|
||||
}
|
||||
if (e.data && e.data.type === 'turneroFirmado') {
|
||||
_tomaProgresivaActiva = false;
|
||||
_setBtnCerrarConsent(true);
|
||||
cerrarModalConsentimiento(true);
|
||||
mostrarToast('Consentimiento firmado ✓', 'success', 3000);
|
||||
mostrarToast('Tomas completadas ✓', 'success', 3000);
|
||||
if (turnoActivo) actualizarConsentimientos(turnoActivo.id);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1144,12 +1144,23 @@ function _guardarFirmaMP(widget, svg, msgEl, entry, campoId) {
|
||||
else if (el.value!=='') dr[n]=el.value;
|
||||
});
|
||||
Object.assign(dr, window._mpSavedFirmas || {});
|
||||
dr[campoId + '_svg'] = svg;
|
||||
(window._mpSavedFirmas = window._mpSavedFirmas||{})[campoId + '_svg'] = svg;
|
||||
// Guardar con campoId directo (sin _svg) para que get_consentimientos lo cuente
|
||||
dr[campoId] = svg;
|
||||
(window._mpSavedFirmas = window._mpSavedFirmas||{})[campoId] = svg;
|
||||
|
||||
fetch(window.location.href, {
|
||||
var turnoId = parseInt(widget.dataset.turno, 10);
|
||||
var formularioId = parseInt(widget.dataset.formulario, 10);
|
||||
var base = window.location.href.split('/ver_formulario_enviado.php')[0];
|
||||
|
||||
fetch(base + '/modules/turnero/api/guardar_toma.php', {
|
||||
method:'POST', headers:{'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ datos_respuestas: dr })
|
||||
body: JSON.stringify({
|
||||
turno_id: turnoId,
|
||||
formulario_id: formularioId,
|
||||
campo_id: campoId,
|
||||
svg: svg,
|
||||
datos_respuestas: dr
|
||||
})
|
||||
})
|
||||
.then(function(r){ return r.json(); })
|
||||
.then(function(data) {
|
||||
@@ -1168,13 +1179,25 @@ function _guardarFirmaMP(widget, svg, msgEl, entry, campoId) {
|
||||
box.appendChild(img);
|
||||
widget.replaceWith(box);
|
||||
|
||||
if (!entry.is_last && entry.esperar_min > 0) {
|
||||
_mpIniciarCountdown(entry.esperar_min, entry.next_label, entry.next_firma_id);
|
||||
if (data.completado) {
|
||||
_mpMostrarFinalizar(entry.exam_type);
|
||||
// Cerrar modal en lugar.php y refrescar la lista
|
||||
setTimeout(function() {
|
||||
try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {}
|
||||
}, 1200);
|
||||
} else if (data.siguiente_toma_at) {
|
||||
// Countdown usando tiempo absoluto del servidor
|
||||
var targetMs = new Date(data.siguiente_toma_at.replace(' ', 'T')).getTime();
|
||||
var minsLeft = Math.max(1, Math.round((targetMs - Date.now()) / 60000));
|
||||
_mpIniciarCountdown(minsLeft, entry.next_label, entry.next_firma_id);
|
||||
} else if (!entry.is_last) {
|
||||
var nw = entry.next_firma_id ? document.getElementById('fpw-' + entry.next_firma_id) : document.querySelector('.firma-pro-widget');
|
||||
if (nw) nw.scrollIntoView({ behavior:'smooth', block:'center' });
|
||||
} else {
|
||||
_mpMostrarFinalizar(entry.exam_type);
|
||||
setTimeout(function() {
|
||||
try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {}
|
||||
}, 1200);
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
|
||||
Reference in New Issue
Block a user