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:
Lizandro Guarnizo
2026-07-09 15:58:57 -05:00
co-authored by Claude Sonnet 4.6
parent d2c1b58c2e
commit 4135e74d84
2 changed files with 34 additions and 12 deletions
+29 -6
View File
@@ -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() {