up
This commit is contained in:
@@ -29,7 +29,16 @@ try {
|
||||
$lugares = $pdo->query(
|
||||
'SELECT * FROM turnero_lugares ORDER BY sort_order ASC, id ASC'
|
||||
)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (\Throwable $e) { $_loadErrors[] = 'turnero_lugares: ' . $e->getMessage(); }
|
||||
// Cargar formularios de consentimiento vinculados a cada lugar
|
||||
$lugarFormIds = [];
|
||||
foreach ($lugares as $lu) {
|
||||
$stmtLcf = $pdo->prepare(
|
||||
"SELECT formulario_id FROM turnero_lugar_consentimientos WHERE lugar_id = ?"
|
||||
);
|
||||
$stmtLcf->execute([$lu['id']]);
|
||||
$lugarFormIds[(int)$lu['id']] = $stmtLcf->fetchAll(PDO::FETCH_COLUMN);
|
||||
}
|
||||
} catch (\Throwable $e) { $_loadErrors[] = 'turnero_lugares: ' . $e->getMessage(); $lugarFormIds = []; }
|
||||
|
||||
try {
|
||||
$prioridades = $pdo->query(
|
||||
@@ -321,6 +330,28 @@ $tab = $_GET['tab'] ?? 'lugares';
|
||||
<input class="form-check-input" type="checkbox" id="edit-lu-activo">
|
||||
<label class="form-check-label small" for="edit-lu-activo">Activo</label>
|
||||
</div>
|
||||
<div class="mb-2 mt-3">
|
||||
<label class="form-label small fw-semibold">
|
||||
<i class="fas fa-file-signature me-1 text-warning"></i>
|
||||
Consentimientos requeridos para este lugar
|
||||
</label>
|
||||
<div id="edit-lu-consents" class="border rounded p-2" style="max-height:160px;overflow-y:auto;background:#fffbeb">
|
||||
<?php foreach ($formulariosCons as $fc): ?>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input edit-lu-consent-chk"
|
||||
type="checkbox"
|
||||
value="<?= (int)$fc['id'] ?>"
|
||||
id="edit-lu-fc-<?= (int)$fc['id'] ?>">
|
||||
<label class="form-check-label small" for="edit-lu-fc-<?= (int)$fc['id'] ?>">
|
||||
<?= htmlspecialchars($fc['nombre']) ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($formulariosCons)): ?>
|
||||
<small class="text-muted">No hay formularios activos configurados.</small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer py-2 px-3">
|
||||
<button class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancelar</button>
|
||||
@@ -772,6 +803,9 @@ $tab = $_GET['tab'] ?? 'lugares';
|
||||
═══════════════════════════════════════════════════════════ */
|
||||
const API = '<?= BASE_URL ?>modules/turnero/api/';
|
||||
|
||||
// Mapa de formularios de consentimiento por lugar (cargado desde PHP)
|
||||
const LUGAR_FORM_IDS = <?= json_encode($lugarFormIds ?? []) ?>;
|
||||
|
||||
// ── Toast helper ────────────────────────────────────────────
|
||||
function toast(msg, type = 'success') {
|
||||
const stack = document.getElementById('toastStack');
|
||||
@@ -811,7 +845,15 @@ async function guardarLugar(tipoOrId = 'muestras', id = null) {
|
||||
|
||||
if (!nombre) { toast('El nombre es requerido', 'error'); return; }
|
||||
|
||||
const body = { nombre, tipo, descripcion: desc, sort_order: orden, activo };
|
||||
// Consentimientos: solo aplica al editar (el modal tiene los checkboxes)
|
||||
const formularioIds = [];
|
||||
if (esEdicion) {
|
||||
document.querySelectorAll('.edit-lu-consent-chk:checked').forEach(chk => {
|
||||
formularioIds.push(parseInt(chk.value));
|
||||
});
|
||||
}
|
||||
|
||||
const body = { nombre, tipo, descripcion: desc, sort_order: orden, activo, formulario_ids: formularioIds };
|
||||
if (id) body.id = id;
|
||||
|
||||
try {
|
||||
@@ -835,6 +877,13 @@ function editarLugar(id, nombre, desc, activo, orden, tipo = 'muestras') {
|
||||
document.getElementById('edit-lu-activo').checked = !!activo;
|
||||
const titulo = tipo === 'recepcion' ? 'Editar escritorio de recepción' : 'Editar estación de muestras';
|
||||
document.getElementById('modal-lugar-titulo').textContent = titulo;
|
||||
|
||||
// Marcar checkboxes de consentimientos del lugar
|
||||
const formIds = (LUGAR_FORM_IDS[id] || []).map(Number);
|
||||
document.querySelectorAll('.edit-lu-consent-chk').forEach(chk => {
|
||||
chk.checked = formIds.includes(parseInt(chk.value));
|
||||
});
|
||||
|
||||
new bootstrap.Modal(document.getElementById('modalEditarLugar')).show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user