update:español por defecto

This commit is contained in:
jlimolina 2025-10-10 19:50:54 +02:00
parent da4c59a0e1
commit 046a5ff369
6 changed files with 381 additions and 119 deletions

View file

@ -10,6 +10,14 @@
<input type="hidden" name="page" id="page" value="{{ page or 1 }}">
<input type="hidden" name="per_page" id="per_page" value="{{ per_page or 20 }}">
<!-- Idioma/traducción por defecto -->
<input type="hidden" name="lang" id="lang" value="{{ (lang or 'es') }}">
{% if not use_tr %}
<input type="hidden" name="orig" id="orig" value="1">
{% else %}
<input type="hidden" name="orig" id="orig" value="">
{% endif %}
<div class="filter-main-row">
<div class="filter-search-box">
<label for="q">Buscar por palabra clave</label>
@ -60,7 +68,22 @@
</form>
</div>
<div id="noticias-container">
<!-- Barra de estado de traducción -->
<div class="card" style="margin-top: 16px; padding: 12px;">
{% if use_tr %}
<div class="alert alert-info" style="margin:0;">
Mostrando <strong>traducciones</strong> a <strong>{{ (lang or 'es')|upper }}</strong>.
<a href="#" id="toggle-orig" class="ms-2">Ver originales</a>
</div>
{% else %}
<div class="alert alert-secondary" style="margin:0;">
Mostrando <strong>texto original</strong>.
<a href="#" id="toggle-tr" class="ms-2">Usar traducciones</a>
</div>
{% endif %}
</div>
<div id="noticias-container" style="margin-top:16px;">
{# El parcial incluye la lista + la paginación #}
{% include '_noticias_list.html' %}
</div>
@ -71,6 +94,8 @@ document.addEventListener('DOMContentLoaded', function() {
const continenteSelect = document.getElementById('continente_id');
const paisSelect = document.getElementById('pais_id');
const pageInput = document.getElementById('page');
const origInput = document.getElementById('orig');
const langInput = document.getElementById('lang');
function filtrarPaises() {
const continenteId = continenteSelect.value;
@ -119,13 +144,46 @@ document.addEventListener('DOMContentLoaded', function() {
// Clic en enlaces de paginación (delegación)
document.addEventListener('click', function(e) {
const link = e.target.closest('a.page-link');
if (link && link.dataset.page) {
e.preventDefault();
pageInput.value = link.dataset.page;
cargarNoticias(true);
if (link) {
// soporta data-page o parseo del href
let nextPage = link.dataset.page;
if (!nextPage) {
try {
const u = new URL(link.href);
nextPage = u.searchParams.get('page');
} catch(_) {}
}
if (nextPage) {
e.preventDefault();
pageInput.value = nextPage;
cargarNoticias(true);
}
}
});
// Conmutar traducciones <-> originales manteniendo filtros
const toggleOrig = document.getElementById('toggle-orig');
const toggleTr = document.getElementById('toggle-tr');
if (toggleOrig) {
toggleOrig.addEventListener('click', function(e) {
e.preventDefault();
// orig=1 fuerza originales
origInput.value = '1';
cargarNoticias(false);
});
}
if (toggleTr) {
toggleTr.addEventListener('click', function(e) {
e.preventDefault();
// orig vacío => usar traducciones
origInput.value = '';
// asegúrate de tener lang (por si el back usa default)
if (!langInput.value) langInput.value = 'es';
cargarNoticias(false);
});
}
// Inicializaciones
continenteSelect.addEventListener('change', function() {
filtrarPaises();