feat: borrador de comentario en toma de muestras (localStorage)
Al escribir en el textarea de comentarios se guarda automáticamente en localStorage con clave toma_draft_<turno_id>. Al abrir la ficha del mismo turno el texto se restaura con borde amarillo de aviso. Al guardar exitosamente o al hacer resetFicha se borra el draft. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3062cd7e95
commit
5109db4a4b
@@ -645,7 +645,8 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
||||
<div style="display:flex;gap:8px;margin-bottom:10px">
|
||||
<textarea id="inp-comentario" class="form-control form-control-sm"
|
||||
rows="2" placeholder="Añade un comentario sobre este turno…"
|
||||
maxlength="500" style="resize:vertical"></textarea>
|
||||
maxlength="500" style="resize:vertical"
|
||||
oninput="draftGuardar()"></textarea>
|
||||
<button class="btn btn-sm btn-primary" onclick="guardarComentario()"
|
||||
style="height:fit-content;align-self:flex-end">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
@@ -1089,6 +1090,7 @@ async function cargarFichaSolicitud(turnoId) {
|
||||
renderConsentimientos(consts);
|
||||
renderMuestras(json.muestras || []);
|
||||
cargarComentarios(turnoId);
|
||||
draftRestaurar(turnoId);
|
||||
|
||||
} catch (_) {}
|
||||
}
|
||||
@@ -1446,6 +1448,9 @@ function resetFicha() {
|
||||
const warn = document.getElementById('accion-consent-warn');
|
||||
if (warn) warn.classList.add('d-none');
|
||||
|
||||
const inpCom = document.getElementById('inp-comentario');
|
||||
if (inpCom) { inpCom.value = ''; inpCom.style.borderColor = ''; inpCom.title = ''; }
|
||||
|
||||
document.getElementById('btn-iniciar').classList.remove('d-none');
|
||||
document.getElementById('btn-iniciar').disabled = false;
|
||||
document.getElementById('btn-finalizar').classList.add('d-none');
|
||||
@@ -1555,6 +1560,7 @@ async function guardarComentario() {
|
||||
const json = await res.json();
|
||||
if (!json.ok) { mostrarError(json.error || 'Error al guardar'); return; }
|
||||
inp.value = '';
|
||||
draftBorrar();
|
||||
await cargarComentarios(turnoActivo.id);
|
||||
mostrarToast('Comentario guardado', 'success', 2000);
|
||||
} catch (err) {
|
||||
@@ -1562,6 +1568,40 @@ async function guardarComentario() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Borrador de comentario (localStorage) ─────────────────────
|
||||
function _draftKey() { return turnoActivo ? 'toma_draft_' + turnoActivo.id : null; }
|
||||
|
||||
function draftGuardar() {
|
||||
const key = _draftKey();
|
||||
if (!key) return;
|
||||
const val = (document.getElementById('inp-comentario')?.value || '').trim();
|
||||
if (val) localStorage.setItem(key, val);
|
||||
else localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
function draftRestaurar(turnoId) {
|
||||
const key = 'toma_draft_' + turnoId;
|
||||
const val = localStorage.getItem(key);
|
||||
const inp = document.getElementById('inp-comentario');
|
||||
if (!inp) return;
|
||||
if (val) {
|
||||
inp.value = val;
|
||||
inp.style.borderColor = '#f59e0b';
|
||||
inp.title = 'Borrador restaurado — no guardado aún';
|
||||
} else {
|
||||
inp.value = '';
|
||||
inp.style.borderColor = '';
|
||||
inp.title = '';
|
||||
}
|
||||
}
|
||||
|
||||
function draftBorrar() {
|
||||
const key = _draftKey();
|
||||
if (key) localStorage.removeItem(key);
|
||||
const inp = document.getElementById('inp-comentario');
|
||||
if (inp) { inp.style.borderColor = ''; inp.title = ''; }
|
||||
}
|
||||
|
||||
// ── Modal paciente ────────────────────────────────────────────
|
||||
function abrirModalPaciente() {
|
||||
if (!_pacienteActivo) return;
|
||||
|
||||
Reference in New Issue
Block a user