From 0c68dff307052ecf1ef70f6d21c02e1e40f9e443 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 3 Jul 2026 11:22:18 -0500 Subject: [PATCH] fix: mostrar canvas para todos los campos firma en modo turnero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Antes solo el primer campo (consentimiento) tenía canvas; el segundo (desistimiento) se omitía. Ahora cada campo firma tiene su propio widget usando clases CSS en vez de IDs hardcodeados. Co-Authored-By: Claude Sonnet 4.6 --- ver_formulario_enviado.php | 78 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/ver_formulario_enviado.php b/ver_formulario_enviado.php index 27a9f25..086f392 100644 --- a/ver_formulario_enviado.php +++ b/ver_formulario_enviado.php @@ -481,13 +481,13 @@ function esc2(mixed $v): string { $fLabel = htmlspecialchars($campo['label'] ?? ($isPro ? 'Firma profesional' : 'Firma paciente')); // Campo paciente sin firma: - // - En turnero pendiente: el PRIMER campo firma muestra el canvas, los demás se omiten. + // - En turnero pendiente: todos los campos firma muestran canvas (consentimiento + desistimiento). // - En vista normal: omitir campos sin firma. if (!$fSvg && !$fFoto && !$isPro) { - if ($modoTurnero && $modoEditar && !$_esquemaTieneFirmaPaciente) { - $_esquemaTieneFirmaPaciente = true; // solo el primero muestra canvas + if ($modoTurnero && $modoEditar) { + $_esquemaTieneFirmaPaciente = true; } else { - continue; // campos firma adicionales (desistimiento) sin firma → omitir + continue; // no-turnero: omitir campos sin firma } } @@ -510,20 +510,20 @@ function esc2(mixed $v): string { Foto - <?= $fLabel ?> -
+

He leído el documento. Dibuje su firma:

-
- -
-
+
@@ -736,7 +736,7 @@ function esc2(mixed $v): string { -
+
Firma del paciente / responsable
@@ -744,19 +744,19 @@ function esc2(mixed $v): string { He leído y comprendido el contenido de este documento. Por favor dibuje su firma en el recuadro:

-
- -
-
+
@@ -888,16 +888,17 @@ function esc2(mixed $v): string { }); })(); -/* ── Firma de consentimiento turnero ────────────────────────────────── */ -(function () { - var canvas = document.getElementById('turneroCv'); - var widget = document.getElementById('turneroFirmaWidget'); +/* ── Firma de consentimiento turnero (soporta múltiples campos firma) ── */ +document.querySelectorAll('.turnero-firma-item').forEach(function(widget) { + var canvas = widget.querySelector('.turnero-cv'); if (!canvas) return; + var cid = widget.dataset.cid || '__firma'; var ctx = canvas.getContext('2d'); - var btnLimp = document.getElementById('turneroLimpiar'); - var btnFirm = document.getElementById('turneroFirmar'); - var msgEl = document.getElementById('turneroMsg'); + var btnLimp = widget.querySelector('.turnero-limpiar'); + var btnFirm = widget.querySelector('.turnero-firmar'); + var msgEl = widget.querySelector('.turnero-msg'); var drawing = false; + var btnLabel = btnFirm ? btnFirm.innerHTML : ''; (function scaleCanvas() { var ratio = window.devicePixelRatio || 1; @@ -928,12 +929,12 @@ function esc2(mixed $v): string { canvas.addEventListener('touchmove', function(e){ e.preventDefault(); if(!drawing) return; var p=getPos(e); ctx.lineTo(p.x,p.y); ctx.stroke(); }, {passive:false}); canvas.addEventListener('touchend', function(){ drawing=false; }); - btnLimp.addEventListener('click', function() { + if (btnLimp) btnLimp.addEventListener('click', function() { ctx.clearRect(0, 0, canvas.width, canvas.height); msgEl.textContent = ''; }); - btnFirm.addEventListener('click', function() { + if (btnFirm) btnFirm.addEventListener('click', function() { var png = canvas.toDataURL('image/png'); if (png.length < 1500) { msgEl.innerHTML = 'Por favor dibuje su firma antes de confirmar.'; @@ -943,23 +944,20 @@ function esc2(mixed $v): string { btnFirm.innerHTML = 'Guardando...'; msgEl.textContent = ''; - // Recopilar respuestas de campos interactivos var campos = {}; document.querySelectorAll('[name]').forEach(function(el) { var rawName = el.name; var isArr = rawName.slice(-2) === '[]'; var name = isArr ? rawName.slice(0, -2) : rawName; if (el.type === 'checkbox') { - if (el.checked) { - if (!Array.isArray(campos[name])) campos[name] = []; - campos[name].push(el.value); - } + if (el.checked) { if (!Array.isArray(campos[name])) campos[name] = []; campos[name].push(el.value); } } else if (el.type === 'radio') { if (el.checked) campos[name] = el.value; } else if (el.value !== '') { campos[name] = el.value; } }); + campos[cid + '_svg'] = png; // identificar qué campo firmó fetch(window.location.href, { method: 'POST', @@ -969,26 +967,28 @@ function esc2(mixed $v): string { .then(function(r) { return r.json(); }) .then(function(data) { if (data.ok) { - widget.outerHTML = - '
' + - '' + - '
Consentimiento firmado correctamente.
' + - 'Puede cerrar esta ventana.
'; - // Notificar ventana padre si está en iframe/modal + // Ocultar todos los demás widgets de firma (ya no se puede firmar dos veces) + document.querySelectorAll('.turnero-firma-item').forEach(function(w) { + w.style.display = 'none'; + }); + var ok = document.createElement('div'); + ok.className = 'alert alert-success mt-4 d-flex align-items-center gap-2 no-print'; + ok.innerHTML = '
Firmado correctamente.
Puede cerrar esta ventana.
'; + widget.parentNode.insertBefore(ok, widget.nextSibling); try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {} } else { msgEl.innerHTML = '' + (data.error || 'Error al guardar') + ''; btnFirm.disabled = false; - btnFirm.innerHTML = 'Confirmar y firmar consentimiento'; + btnFirm.innerHTML = btnLabel; } }) .catch(function() { msgEl.innerHTML = 'Error de conexión.'; btnFirm.disabled = false; - btnFirm.innerHTML = 'Confirmar y firmar consentimiento'; + btnFirm.innerHTML = btnLabel; }); }); -})(); +});