/** * Archivos donde aparece una persona, en la página "Actualización de datos". * * En el HTML (PHP): *
*

Archivos donde aparece

*
Buscando…
*
* */ (function () { "use strict"; var ETIQUETAS = { cedula: "Cédula", completo: "Nombre completo", parcial: "Nombre parcial (verificar)", }; function formatearTamano(bytes) { if (bytes < 1024) return bytes + " B"; if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB"; return (bytes / 1024 / 1024).toFixed(1) + " MB"; } function crear(etiqueta, clase, texto) { var el = document.createElement(etiqueta); if (clase) el.className = clase; if (texto) el.textContent = texto; return el; } // El fragmento viene con la coincidencia entre « »: se resalta con sin usar innerHTML function fragmentoResaltado(texto) { var p = crear("p", "archivo-fragmento"); texto.split(/(«[^»]*»)/).forEach(function (parte) { if (parte.charAt(0) === "«") p.appendChild(crear("mark", null, parte.slice(1, -1))); else if (parte) p.appendChild(document.createTextNode(parte)); }); return p; } function renderizar(contenedor, datos) { contenedor.textContent = ""; if (datos.total === 0) { contenedor.textContent = "No se encontraron archivos con estos datos."; return; } if (datos.total_coincidencias > datos.total) { contenedor.appendChild(crear("p", "archivos-aviso", "Mostrando las " + datos.total + " mejores coincidencias de " + datos.total_coincidencias + ".")); } var ul = crear("ul", "archivos-lista"); datos.resultados.forEach(function (a) { var li = crear("li"); var enlace = crear("a", null, a.nombre); enlace.href = a.url_descarga; enlace.rel = "noopener"; li.appendChild(enlace); li.appendChild(crear("small", null, " — " + (a.carpeta || "(raíz)") + " · " + formatearTamano(a.tamano_bytes) + (a.modificado_en ? " · " + new Date(a.modificado_en).toLocaleDateString("es-PY") : ""))); var etiquetas = crear("div", "archivo-etiquetas"); if (a.coincide_cedula) etiquetas.appendChild(crear("span", "etiqueta etiqueta-cedula", ETIQUETAS.cedula)); if (a.coincide_nombre) { etiquetas.appendChild(crear("span", "etiqueta etiqueta-" + a.coincide_nombre, ETIQUETAS[a.coincide_nombre])); } li.appendChild(etiquetas); if (a.fragmento) li.appendChild(fragmentoResaltado(a.fragmento)); ul.appendChild(li); }); contenedor.appendChild(ul); } function cargar(seccion) { var contenedor = seccion.querySelector(".archivos-contenido"); var d = seccion.dataset; var params = new URLSearchParams(); if (d.cedula) params.set("cedula", d.cedula); if (d.nombres && d.apellidos) { params.set("nombres", d.nombres); params.set("apellidos", d.apellidos); } if (!params.toString()) { contenedor.textContent = "Faltan la cédula o el nombre de la persona."; return; } fetch(d.api.replace(/\/$/, "") + "/archivos?" + params.toString(), { headers: { Authorization: "Bearer " + d.token }, }) .then(function (resp) { if (resp.status === 401) throw new Error("La sesión venció, recargá la página."); if (resp.status === 403) throw new Error("No tenés permiso para ver estos archivos."); if (!resp.ok) throw new Error("No se pudo obtener el listado (" + resp.status + ")."); return resp.json(); }) .then(function (datos) { renderizar(contenedor, datos); }) .catch(function (err) { contenedor.textContent = err.message; }); } document.addEventListener("DOMContentLoaded", function () { var seccion = document.getElementById("archivos-persona"); if (seccion) cargar(seccion); }); })();