Fix: editar consulta no hacía nada — comillas dobles en onclick rompían el HTML

Cambio tojson en atributos onclick por data-* con |e.
dataset decodifica automáticamente " → " sin riesgo de romper el atributo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-18 13:16:48 -05:00
co-authored by Claude Sonnet 4.6
parent eb6bcebff8
commit 122d21df09
+16 -7
View File
@@ -50,7 +50,12 @@
<div class="overflow-y-auto flex-1">
{% for q in queries %}
<div class="group flex items-center px-3 py-1.5 hover:bg-gray-50 cursor-pointer border-b border-gray-100 last:border-0"
onclick="cargarConsulta({{ q.query_text | tojson }}, {{ q.name | tojson }}, {{ q.query_type | tojson }})">
data-sql="{{ q.query_text | e }}"
data-name="{{ q.name | e }}"
data-type="{{ q.query_type }}"
data-id="{{ q.id }}"
data-desc="{{ (q.description or '') | e }}"
onclick="cargarConsultaEl(this)">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-1.5">
<span class="text-xs px-1 rounded {% if q.query_type == 'terceros' %}bg-blue-100 text-blue-600{% else %}bg-purple-100 text-purple-600{% endif %}">
@@ -60,7 +65,7 @@
</div>
</div>
<div class="hidden group-hover:flex items-center gap-1 ml-1 flex-shrink-0">
<button onclick="event.stopPropagation();editarConsulta({{ q.id }}, {{ q.name | tojson }}, {{ q.query_type | tojson }}, {{ q.query_text | tojson }}, {{ (q.description or '') | tojson }})"
<button onclick="event.stopPropagation();editarConsultaEl(this.closest('[data-id]'))"
class="text-blue-400 hover:text-blue-600 p-0.5"><i class="fas fa-edit text-xs"></i></button>
<form method="POST" action="/queries/delete/{{ q.id }}" onsubmit="return confirm('¿Eliminar consulta?')" class="inline">
<button type="submit" class="text-red-400 hover:text-red-600 p-0.5"><i class="fas fa-trash text-xs"></i></button>
@@ -404,12 +409,16 @@ function cargarConsulta(sql, name, type) {
editor && editor.focus();
}
function editarConsulta(id, name, type, sql, desc) {
editandoId = id;
cargarConsulta(sql, name, type);
document.getElementById('form-desc').value = desc;
function cargarConsultaEl(el) {
cargarConsulta(el.dataset.sql, el.dataset.name, el.dataset.type);
}
function editarConsultaEl(el) {
editandoId = parseInt(el.dataset.id);
cargarConsulta(el.dataset.sql, el.dataset.name, el.dataset.type);
document.getElementById('form-desc').value = el.dataset.desc || '';
document.getElementById('btn-cancel').classList.replace('hidden', 'flex');
document.getElementById('editing-label').textContent = `Editando: ${name}`;
document.getElementById('editing-label').textContent = `Editando: ${el.dataset.name}`;
document.getElementById('editing-label').classList.remove('hidden');
}