diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php index a368801..58d55b6 100644 --- a/modules/turnero/views/lugar.php +++ b/modules/turnero/views/lugar.php @@ -1538,18 +1538,39 @@ function cerrarModalConsentimiento(forzar) { if (turnoActivo) actualizarConsentimientos(turnoActivo.id); } +var _mpParentCdTimer = null; +function _mpParentNotificar(lbl) { + if ('Notification' in window && Notification.permission === 'granted') { + new Notification('⏰ Toma de muestras', { body: lbl || '¡Siguiente muestra!', icon: '/favicon.ico', requireInteraction: true }); + } +} +function _mpParentCancelCd() { + if (_mpParentCdTimer) { clearInterval(_mpParentCdTimer); _mpParentCdTimer = null; } +} + window.addEventListener('message', function(e) { if (e.data && e.data.type === 'tomaProgresivaIniciada') { _tomaProgresivaActiva = true; if ('Notification' in window && Notification.permission === 'default') Notification.requestPermission(); - } - if (e.data && e.data.type === 'tomaProgresivaAlerta') { - var lbl = (e.data.label || '¡Siguiente muestra!'); - if ('Notification' in window && Notification.permission === 'granted') { - new Notification('⏰ Toma de muestras', { body: lbl, icon: '/favicon.ico', requireInteraction: true }); + // Countdown en el padre para que sobreviva si el modal se cierra + _mpParentCancelCd(); + if (e.data.targetMs) { + var _pTarget = e.data.targetMs, _pLabel = e.data.label || ''; + _mpParentCdTimer = setInterval(function() { + if (Date.now() >= _pTarget) { + _mpParentCancelCd(); + _mpParentNotificar(_pLabel); + } + }, 5000); } } + if (e.data && e.data.type === 'tomaProgresivaAlerta') { + // El iframe ya disparó la alerta — cancelar el del padre para no duplicar + _mpParentCancelCd(); + _mpParentNotificar(e.data.label || ''); + } if (e.data && e.data.type === 'turneroFirmado') { + _mpParentCancelCd(); _tomaProgresivaActiva = false; _setBtnCerrarConsent(true); cerrarModalConsentimiento(true); diff --git a/ver_formulario_enviado.php b/ver_formulario_enviado.php index bf42f6f..872d021 100644 --- a/ver_formulario_enviado.php +++ b/ver_formulario_enviado.php @@ -2180,7 +2180,7 @@ function _mpIniciarCountdown(targetMsOrMins, nextLabel, nextFirmaId) { if (box._mpTick) clearInterval(box._mpTick); // Notificar al padre que bloquee el cierre - try { window.parent.postMessage({ type: 'tomaProgresivaIniciada' }, '*'); } catch(e) {} + try { window.parent.postMessage({ type: 'tomaProgresivaIniciada', targetMs: targetMs, label: nextLabel || '' }, '*'); } catch(e) {} var _tcCdEl = nextFirmaId ? document.getElementById('tc-cd-' + nextFirmaId) : null;