refactor(lugar): embebido como botón en fila de consentimiento, no sección separada
- Eliminar sec-form-embebido como sección independiente - En modo embebido: fila de consentimiento muestra botón "Firmar" que abre modal directamente por token - En modo link: botones "Firmar presencial" + "WA" como antes - abrirModalConsentimientoPorToken(token) recibe token directo sin cache Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b399c3710e
commit
1e2cfbaa0b
@@ -321,14 +321,7 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Sección: Consentimientos ── -->
|
||||
<!-- ── Botón firma embebida (modo=embebido) ── -->
|
||||
<div class="ficha-sec d-none" id="sec-form-embebido">
|
||||
<h6><i class="fas fa-file-signature me-1"></i>Consentimiento informado</h6>
|
||||
<button class="btn btn-primary w-100" onclick="abrirModalConsentimiento()">
|
||||
<i class="fas fa-pen me-2"></i>Abrir formulario de firma
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="ficha-sec" id="sec-consent">
|
||||
<h6><i class="fas fa-file-signature me-1"></i>Consentimientos informados</h6>
|
||||
@@ -753,29 +746,40 @@ function renderConsentimientos(lista) {
|
||||
const idJs = parseInt(c.id) || 0;
|
||||
const tId = parseInt(c.turno_id) || (turnoActivo?.id) || 0;
|
||||
|
||||
// Firmar aquí: solo si no completado y hay token
|
||||
const btnFirmar = (!ya && c.token)
|
||||
? `<button class="btn btn-outline-primary" title="Firmar aquí"
|
||||
onclick="abrirFirmaPresencial('${token}', ${idJs}, ${nomJs.replace(/"/g,'"')})">
|
||||
<i class="fas fa-signature"></i> Firmar
|
||||
</button>` : '';
|
||||
// Botón ver (firmado)
|
||||
const btnVer = (ya && c.token)
|
||||
? `<a href="${BASE_WA}ver_formulario_enviado.php?token=${token}" target="_blank"
|
||||
class="btn btn-outline-secondary" title="Ver firmado">
|
||||
<i class="fas fa-eye"></i> Ver
|
||||
</a>` : '';
|
||||
|
||||
// WA / Ver: según estado
|
||||
const btnWa = ya
|
||||
? (c.token ? `<a href="${BASE_WA}ver_formulario_enviado.php?token=${token}" target="_blank"
|
||||
class="btn btn-outline-secondary" title="Ver firmado">
|
||||
<i class="fas fa-eye"></i> Ver
|
||||
</a>` : '')
|
||||
: `<button class="btn btn-outline-success" title="Reenviar por WhatsApp"
|
||||
onclick="reenviarConsentimiento(${tId})">
|
||||
<i class="fab fa-whatsapp"></i> WA
|
||||
</button>`;
|
||||
// Acción principal según modo y estado
|
||||
let btnAccion = '';
|
||||
if (!ya && c.token) {
|
||||
if (LUGAR_FORM_MODO === 'embebido') {
|
||||
// Modo embebido: abrir modal directamente
|
||||
btnAccion = `<button class="btn btn-primary" title="Abrir formulario"
|
||||
onclick="abrirModalConsentimientoPorToken('${token}')">
|
||||
<i class="fas fa-pen me-1"></i>Firmar
|
||||
</button>`;
|
||||
} else {
|
||||
// Modo link: firmar presencial o reenviar WA
|
||||
btnAccion = `<button class="btn btn-outline-primary" title="Firmar aquí"
|
||||
onclick="abrirFirmaPresencial('${token}', ${idJs}, ${nomJs.replace(/"/g,'"')})">
|
||||
<i class="fas fa-signature"></i> Firmar
|
||||
</button>
|
||||
<button class="btn btn-outline-success" title="Reenviar por WhatsApp"
|
||||
onclick="reenviarConsentimiento(${tId})">
|
||||
<i class="fab fa-whatsapp"></i> WA
|
||||
</button>`;
|
||||
}
|
||||
}
|
||||
|
||||
return `<div class="consent-row ${c.estado}" data-consent-id="${c.id}">
|
||||
<i class="fas ${ico}"></i>
|
||||
<span class="nom-form">${escHtml(c.formulario_nombre || 'Consentimiento')}</span>
|
||||
<span class="c-badge">${label}</span>
|
||||
<div class="acciones-consent">${btnFirmar}${btnWa}</div>
|
||||
<div class="acciones-consent">${btnAccion}${btnVer}</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
@@ -889,27 +893,10 @@ async function cambiarEstadoTurno(nuevoEstado) {
|
||||
// ── Embebido como modal ───────────────────────────────────────
|
||||
let _consentTokenCache = null; // { turnoId, token }
|
||||
|
||||
async function cargarFormEmbebido(turnoId) {
|
||||
const sec = document.getElementById('sec-form-embebido');
|
||||
if (sec) sec.classList.remove('d-none');
|
||||
// Pre-cargar token para que el modal abra rápido
|
||||
try {
|
||||
const res = await fetch(`${API}get_consent_token.php?turno_id=${turnoId}&lugar_id=${lugarId}`);
|
||||
const json = await res.json();
|
||||
if (json.ok && json.token) {
|
||||
_consentTokenCache = { turnoId, token: json.token };
|
||||
} else {
|
||||
_consentTokenCache = null;
|
||||
if (sec) sec.innerHTML = `<h6><i class="fas fa-file-signature me-1"></i>Consentimiento informado</h6>
|
||||
<div class="text-danger small"><i class="fas fa-exclamation-triangle me-1"></i>${json.error || 'Sin formulario configurado'}</div>`;
|
||||
}
|
||||
} catch (e) {
|
||||
_consentTokenCache = null;
|
||||
}
|
||||
}
|
||||
// cargarFormEmbebido ya no necesita hacer nada (el token viene de la fila de consentimiento)
|
||||
async function cargarFormEmbebido(turnoId) { /* token llega vía renderConsentimientos */ }
|
||||
|
||||
function abrirModalConsentimiento() {
|
||||
if (!_consentTokenCache) { mostrarError('Token de consentimiento no disponible.'); return; }
|
||||
function _abrirModalConToken(token) {
|
||||
const modal = document.getElementById('modal-consentimiento');
|
||||
const iframe = document.getElementById('modal-consent-iframe');
|
||||
const load = document.getElementById('modal-consent-loading');
|
||||
@@ -917,12 +904,20 @@ function abrirModalConsentimiento() {
|
||||
iframe.src = '';
|
||||
load.style.display = '';
|
||||
modal.style.display = 'flex';
|
||||
// Pequeño delay para que el modal sea visible antes de cargar el iframe
|
||||
setTimeout(() => {
|
||||
iframe.src = `${BASE_WA}ver_formulario_enviado.php?token=${encodeURIComponent(_consentTokenCache.token)}&embed=1`;
|
||||
iframe.src = `${BASE_WA}ver_formulario_enviado.php?token=${encodeURIComponent(token)}&embed=1`;
|
||||
}, 80);
|
||||
}
|
||||
|
||||
function abrirModalConsentimiento() {
|
||||
if (!_consentTokenCache?.token) { mostrarError('Token de consentimiento no disponible.'); return; }
|
||||
_abrirModalConToken(_consentTokenCache.token);
|
||||
}
|
||||
|
||||
function abrirModalConsentimientoPorToken(token) {
|
||||
_abrirModalConToken(token);
|
||||
}
|
||||
|
||||
function cerrarModalConsentimiento() {
|
||||
const modal = document.getElementById('modal-consentimiento');
|
||||
const iframe = document.getElementById('modal-consent-iframe');
|
||||
@@ -952,17 +947,7 @@ function resetFicha() {
|
||||
tieneConsent = false;
|
||||
hayPendientes = false;
|
||||
_consentTokenCache = null;
|
||||
|
||||
// Limpiar modal embebido
|
||||
cerrarModalConsentimiento();
|
||||
const sec = document.getElementById('sec-form-embebido');
|
||||
if (sec) {
|
||||
sec.classList.add('d-none');
|
||||
sec.innerHTML = `<h6><i class="fas fa-file-signature me-1"></i>Consentimiento informado</h6>
|
||||
<button class="btn btn-primary w-100" onclick="abrirModalConsentimiento()">
|
||||
<i class="fas fa-pen me-2"></i>Abrir formulario de firma
|
||||
</button>`;
|
||||
}
|
||||
|
||||
document.getElementById('ficha-turno').classList.add('d-none');
|
||||
document.getElementById('ficha-placeholder').classList.remove('d-none');
|
||||
|
||||
Reference in New Issue
Block a user