1(function ($) { 2 3 var cargandoListado = false; 4 5 $.fn.SagaListado = function (parametros) { 6 var that = this; 7 var thatuuid = $('.SagaListado.general[data-uuid="' + this.attr('data-uuid') + '"]'); 8 9 init(parametros, that, thatuuid); 10 11 if (parametros.AgruparPorDataNivel === 'true') { 12 AgruparPorDataNivel(parametros); 13 } 14 15 FiltrosFlotanteRestponsive(parametros); 16 17 function AgruparPorDataNivel(parametros) { 18 if (parametros.AgruparPorDataNivel === 'true') { 19 20 var contenedor_padre = $(".wrapper-aside .filtros_busqueda.con_categoria .categoria-busqueda .filtro_busqueda_grupo"); 21 22 var contenedor = $(".wrapper-aside .filtros_busqueda.con_categoria .categoria-busqueda .filtro_busqueda_grupo .contenedorFacets"); 23 24 var elementos = $(".wrapper-aside .filtros_busqueda.con_categoria .categoria-busqueda .filtro_busqueda_grupo .contenedorFacets .elementoFacet"); 25 26 27 elementos.sort(function (a, b) { 28 return $(a).data("nivel") - $(b).data("nivel"); 29 }); 30 contenedor_padre.find('.filtros_busqueda-label-contenedor').remove(); 31 contenedor.html(elementos); 32 33 $(document).ready(function () { 34 35 // Paso 2: Crear objeto contenedores_por_categoria 36 var contenedores_por_categoria = {}; 37 38 // Paso 3: Agregar elementos a sus respectivos contenedores en contenedores_por_categoria 39 elementos.each(function () { 40 var categoria = $(this).data("nivel"); 41 if (!contenedores_por_categoria[categoria]) { 42 contenedores_por_categoria[categoria] = []; 43 } 44 contenedores_por_categoria[categoria].push($(this)); 45 }); 46 47 // Paso 4: Crear nuevos contenedores y agregar elementos 48 for (var categoria in contenedores_por_categoria) { 49 var nuevos_elementos = contenedores_por_categoria[categoria]; 50 var nuevo_contenedor = $("<div>").addClass("contenedorFacets").append(nuevos_elementos); 51 contenedor_padre.append(nuevo_contenedor); 52 53 // Paso 5: Eliminar contenedor vacÃo 54 if (contenedor.is(":empty")) { 55 contenedor.remove(); 56 } 57 } 58 59 60 $('label[for]').each(function () { 61 var currentForValue = $(this).attr('for'); 62 $('label[for="' + currentForValue + '"]:not(:first)').each(function () { 63 $(this).closest('.elementoFacet').remove(); 64 $(this).remove(); 65 }); 66 }); 67 68 69 var contenedores = contenedor_padre.find('.contenedorFacets'); 70 contenedores.each(function () { 71 var contenedor_actual = $(this); 72 73 // obtiene el valor de la propiedad data-category 74 var categoria = contenedor_actual.find('.elementoFacet').first().data('category'); 75 76 // filtra los elementos por la categoria 77 var elementos_filtrados = elementos.filter('[data-category="' + categoria + '"]'); 78 79 // crea un nuevo contenedor de facet con los elementos filtrados 80 var nuevo_contenedor = $('<div class="contenedorFacets"></div>').append(elementos_filtrados); 81 82 // agrega el nuevo contenedor antes del contenedor actual 83 contenedor_actual.before(nuevo_contenedor); 84 85 // crea el elemento de etiqueta de filtro si no existe ya 86 if (!contenedor_actual.prev().hasClass('filtros_busqueda-label-contenedor')) { 87 var etiqueta_filtro = $('<div class="filtros_busqueda-label-contenedor"><div class="filtro_busqueda-label" data-nivel="' + contenedor_actual.find('.elementoFacet').first().data('nivel') + '">' + contenedor_actual.find('.elementoFacet').first().data('nivel') + '</div><div class="filtro_busqueda-toggle desplegado"><div class="filtro_busqueda-toggle-1"></div><div class="filtro_busqueda-toggle-2"></div></div></div>'); 88 contenedor_actual.before(etiqueta_filtro); 89 } 90 }); 91 92 // oculta los contenedores vacÃos 93 contenedor_padre.find('.contenedorFacets').filter(function () { 94 return $(this).children().length == 0; 95 }).addClass('oculto'); 96 97 contenedor_padre.find('.filtro_busqueda-label').filter(function () { 98 return $(this).text().toLowerCase().includes('undefined'); 99 }).parent().addClass('oculto'); 100 101 }); 102 103 } 104 } 105 106 function init(parametros, that, thatuuid) { 107 if (parametros.origen === 'nativo' || parametros.origen === 'filtros') { 108 comprobarDuplicidadIDs(parametros, that, thatuuid); 109 } 110 111 if (parametros.esOnline === false) { 112 var idElemento = that.attr('id'); 113 moverCreacion(that, idElemento, parametros.idiomaUsuarioActual, true); 114 moverSagaListadoConfig(that, idElemento, parametros.idiomaUsuarioActual, true); 115 moverSagaListadoFormatterConfig(that, idElemento, parametros.idiomaUsuarioActual, true); 116 } 117 118 if (parametros.activarZoom === 'true') { 119 $('.venobox').venobox(); 120 } 121 } 122 123 function comprobarDuplicidadIDs(parametros, that, thatuuid) { 124 var ids; 125 var idsfiltros; 126 127 $('.SagaListado[data-uuid="' + that.attr('data-uuid') + '"]:not(.filtros):not(.creacion)').each(function () { 128 ids = $('.SagaListado:not(.filtros)[data-uuid="' + $(this).attr('data-uuid') + '"]'); 129 idsfiltros = $('.SagaListado.filtros[data-uuid="' + $(this).attr('data-uuid') + '"]'); 130 }); 131 132 if (ids !== undefined && idsfiltros !== undefined) { 133 if (ids.length > 1 && idsfiltros.length > 0) { 134 if ($(this).find('.mensajeSAGA.duplicidad').length === 0) { 135 ids.empty(); 136 ids.prepend('' + 137 '<div class="mensajeSAGA error duplicidad">' + 138 ' <div class="linea1">
138Recurso duplicado</div>' + 139 ' <div class="linea2">No se puede usar el mismo listado varias veces en la misma página</div>' + 140 '</div>'); 141 } 142 } else { 143 if (typeof funcionPreInteraccion === 'function') { 144 funcionPreInteraccion(parametros, that, thatuuid); 145 } else { 146 // console.log('La función funcionPreInteraccion no está definida.'); 147 } 148 149 150 if (parametros.origen === 'nativo') { 151 interaccion(parametros, that); 152 } else if (parametros.origen === 'filtros') { 153 interaccion(parametros, that, thatuuid); 154 } 155 156 if (typeof funcionPostInteraccion === 'function') { 157 funcionPostInteraccion(parametros, that, thatuuid); 158 } else { 159 // console.log('La función funcionPostInteraccion no está definida.'); 160 } 161 } 162 } 163 } 164 165 function cargarFiltrosBusqueda(parametros, that, thatconnect) { 166 var EsReinicio = parametros.esReinicio === true; 167 168 if (!EsReinicio) { 169 var valorTerminoBusqueda; 170 var valorDesdeBusqueda; 171 var valorHastaBusqueda; 172 var CategoriasMarcadas; 173 var valorCategoriaBusqueda; 174 var valorTipoRecursoBusqueda; 175 176 if (parametros.MostrarFiltros === 'facets') { 177 valorTerminoBusqueda = that.find('.filtros_busqueda .termino_busqueda .filtro_busqueda-opciones').val(); 178 valorDesdeBusqueda = that.find('.filtros_busqueda .rangofechas .desde .filtro_busqueda-opciones').val(); 179 valorHastaBusqueda = that.find('.filtros_busqueda .rangofechas .hasta .filtro_busqueda-opciones').val(); 180 CategoriasMarcadas = that.find('.filtros_busqueda .categoria-busqueda .filtro_busqueda-opciones:checked'); 181 CategoriasMarcadas.each(function (indiceCategoriasMarcadas) { 182 if (indiceCategoriasMarcadas === 0) { 183 valorCategoriaBusqueda = $(this).val(); 184 } else { 185 valorCategoriaBusqueda = valorCategoriaBusqueda + ',' + $(this).val(); 186 } 187 }); 188 189 valorTipoRecursoBusqueda = that.find('.filtros_busqueda .tipoRecurso-busqueda .filtro_busqueda-opciones:checked').val(); 190 } else { 191 valorTerminoBusqueda = that.find('.filtros_busqueda .termino_busqueda .filtro_busqueda-opciones').val(); 192 valorDesdeBusqueda = that.find('.filtros_busqueda .rangofechas .desde .filtro_busqueda-opciones').val(); 193 valorHastaBusqueda = that.find('.filtros_busqueda .rangofechas .hasta .filtro_busqueda-opciones').val(); 194 valorCategoriaBusqueda = that.find('.filtros_busqueda .categoria-busqueda .filtro_busqueda-opciones').val(); 195 valorTipoRecursoBusqueda = that.find('.filtros_busqueda .tipoRecurso-busqueda .filtro_busqueda-opciones').val(); 196 that.find('.filtros_busqueda .categoria-busqueda .filtro_busqueda-opciones').each(function (indiceCategoriasMarcadas) { 197 if (indiceCategoriasMarcadas === 0) { 198 valorCategoriaBusqueda = $(this).val(); 199 } else { 200 valorCategoriaBusqueda = valorCategoriaBusqueda + ',' + $(this).val(); 201 } 202 }) 203 } 204 205 var queryString = window.location.search; 206 var urlParams = new URLSearchParams(queryString); 207 var parametroBusqueda = urlParams.get('busqueda'); 208 209 if (valorTerminoBusqueda === '' && parametroBusqueda != null) { 210 parametros.buscarTexto = parametroBusqueda; 211 parametros.dym = parametroBusqueda; 212 } else { 213 parametros.buscarTexto = valorTerminoBusqueda; 214 parametros.dym = valorTerminoBusqueda; 215 } 216 217 var InputDesde = valorDesdeBusqueda; 218 var ExisteInputDesde = InputDesde !== '' && InputDesde !== undefined; 219 if (ExisteInputDesde) { 220 var DateInputDesde = new Date(InputDesde + ' 00:00:00'); 221 parametros.desde = DateInputDesde.toISOString(); 222 } 223 var InputHasta = valorHastaBusqueda; 224 var ExisteInputHasta = InputHasta !== '' && InputHasta !== undefined; 225 if (ExisteInputHasta) { 226 var DateInputHasta = new Date(InputHasta + ' 23:59:59'); 227 parametros.hasta = DateInputHasta.toISOString(); 228 } 229 230 parametros.buscarCategoria = valorCategoriaBusqueda; 231 parametros.buscarTipo = valorTipoRecursoBusqueda; 232 233 234 if (!parametros.MostrarResultadosAlInicio && parametros.Prebusqueda !== '' && parametros.Prebusqueda !== undefined && parametros.Prebusqueda !== null) { 235 parametros.busquedaActiva = true; 236 } else { 237 if ((valorTerminoBusqueda !== undefined && valorTerminoBusqueda !== '') || 238 (valorDesdeBusqueda !== undefined && valorDesdeBusqueda !== '') || 239 (valorHastaBusqueda !== undefined && valorHastaBusqueda !== '') || 240 (valorCategoriaBusqueda !== undefined && valorCategoriaBusqueda !== '') || 241 (valorTipoRecursoBusqueda !== undefined && valorTipoRecursoBusqueda !== '')) { 242 243 parametros.busquedaActiva = true; 244 } else { 245 parametros.busquedaActiva = false;
246 } 247 248 that.find('.filtro_personalizado').each(function () { 249 var campoFiltro = $(this).attr('data-camposolr'); 250 var widgetFiltro = $(this).attr('data-widget'); 251 var valorFiltro; 252 var paramCat; 253 254 if (widgetFiltro === 'alfabetico') { 255 valorFiltro = $(this).find('.filtro_busqueda-opciones').val(); 256 paramCat = 'alfabetico_'; 257 } else { 258 if (parametros.MostrarFiltros === 'facets') { 259 valorFiltro = $(this).find('.filtro_busqueda-opciones:checked').val(); 260 } else { 261 valorFiltro = $(this).find('.filtro_busqueda-opciones').val(); 262 } 263 paramCat = 'personalizado_'; 264 } 265 266 if ((campoFiltro !== undefined) && (campoFiltro !== '') && (valorFiltro !== undefined) && (valorFiltro !== '')) { 267 parametros[paramCat + campoFiltro] = valorFiltro; 268 parametros.busquedaActiva = true; 269 } else { 270 delete parametros[paramCat + campoFiltro]; 271 } 272 }); 273 274 275 that.find('.rangofechas_personalizado').each(function (index, element) { 276 const $el = $(this); 277 const campoDesde = $el.find('.desde').attr('data-camposolr') || ''; 278 const valorDesde = $el.find('.desde .filtro_busqueda-opciones').val() || ''; 279 const campoHasta = $el.find('.hasta').attr('data-camposolr') || ''; 280 const valorHasta = $el.find('.hasta .filtro_busqueda-opciones').val() || ''; 281 282 // Si no hay ni desde ni hasta, borramos cualquier filtro previo 283 if (!campoDesde && !campoHasta) { 284 delete parametros[`personalizadofecha_${index}`]; 285 return; 286 } 287 288 // Construimos los Date y sus cadenas ISO solo si hay valor 289 let isoDesde = ''; 290 if (campoDesde && valorDesde) { 291 const DateFiltroDesde = new Date(valorDesde + ' 00:00:00'); 292 isoDesde = DateFiltroDesde.toISOString(); 293 } 294 295 let isoHasta = ''; 296 if (campoHasta && valorHasta) { 297 const DateFiltroHasta = new Date(valorHasta + ' 23:59:59'); 298 isoHasta = DateFiltroHasta.toISOString(); 299 } 300 301 // Concatenamos "campoDesde|isoDesde;campoHasta|isoHasta" 302 const combinado = [ 303 campoDesde, isoDesde 304 ].join('|') + ';' + [ 305 campoHasta, isoHasta 306 ].join('|'); 307 308 parametros[`personalizadofecha_${index}`] = combinado; 309 parametros.busquedaActiva = true; 310 }); 311 312 313 } 314 315 } else { 316 parametros.buscarTexto = ''; 317 parametros.buscarCategoria = ''; 318 parametros.buscarTipo = ''; 319 parametros.desde = ''; 320 parametros.hasta = ''; 321 322 that.find('.filtro_personalizado').each(function () { 323 var campoFiltro = $(this).attr('data-camposolr'); 324 var widgetFiltro = $(this).attr('data-widget'); 325 var paramCat; 326 327 if (widgetFiltro === 'alfabetico') { 328 paramCat = 'alfabetico_'; 329 } else { 330 paramCat = 'personalizado_'; 331 } 332 333 delete parametros[paramCat + campoFiltro]; 334 }); 335 336 that.find('.rangofechas_personalizado').each(function(index, element) { 337 const $el = $(this); 338 const valorDesde = $el.find('.desde .filtro_busqueda-opciones').val(); 339 const valorHasta = $el.find('.hasta .filtro_busqueda-opciones').val(); 340 341 // Si ni desde ni hasta tienen valor, borramos el parámetro y no hay búsqueda activa 342 if ((!valorDesde || valorDesde === '') && (!valorHasta || valorHasta === '')) { 343 delete parametros[`personalizadofecha_${index}`]; 344 } 345 }); 346 347 parametros.busquedaActiva = false;
348 } 349 350 parametros.that = that.attr('id'); 351 parametros.thatconnect = thatconnect.attr('id'); 352 } 353 354 function llamadaListado(parametros, that, thatconnect) { 355 var continuar = true; 356 if (typeof funcionPreLlamadaListado === 'function') { 357 continuar = funcionPreLlamadaListado(parametros, that, thatconnect); 358 } else { 359 // console.log('La función funcionPreLlamadaListado no está definida.'); 360 } 361 if (continuar) { 362 cargandoListado = true; 363 364 var cargarAnimacionCargandoEnElementos = (parametros.forma_listar === 'busqueda' || (parametros.forma_listar === 'carga' && parametros.tipo_paginacion === 'numeros')) && parametros.UbicacionCargandoNumerico === 'cadaRecurso'; 365 var cargarAnimacionEnListado = (parametros.forma_listar === 'busqueda' || (parametros.forma_listar === 'carga' && parametros.tipo_paginacion === 'numeros')) && parametros.UbicacionCargandoNumerico === 'centradoListado'; 366 367 if (cargarAnimacionCargandoEnElementos) { 368 interaccionCargandoElementos(thatconnect, 'mostrar'); 369 } else if (cargarAnimacionEnListado) { 370 interaccionCargandoListado(thatconnect, 'mostrar'); 371 } else { 372 thatconnect.find('.cargandoListado').removeClass('oculto'); 373 } 374 375 that.find('.CargandoFiltros').removeClass('oculto'); 376 that.find('.filtro_busqueda.rangofechas input').prop('disabled', true); 377 that.find('.filtro_busqueda.termino_busqueda input').prop('disabled', true); 378 379 380 // Selector de orden personalizado en el front 381 if (that.find('.ordenacionResultados .selectOrdenacion').length > 0) { 382 var ordenSeleccionado = that.find('.ordenacionResultados .selectOrdenacion .ordenSeleccionado').attr('data-orden-actual'); 383 384 if (ordenSeleccionado !== 'defecto') { 385 parametros.OrdenacionQueryFront = ordenSeleccionado; 386 parametros.ForzarOrdenacionBusqueda = true; 387 } else { 388 parametros.OrdenacionQueryFront = ''; 389 if (parametros.EstadoInicialForzarOrdenacionBusqueda === true) { 390 parametros.ForzarOrdenacionBusqueda = true; 391 } else { 392 parametros.ForzarOrdenacionBusqueda = false; 393 } 394 } 395 } 396 // ------------------------------------------------ 397 398 cargarFiltrosBusqueda(parametros, that, thatconnect); 399 400 var dataTypeAjax; 401 if (parametros.formatterOrigen === 'JSON') { 402 dataTypeAjax = 'json' 403 } else { 404 dataTypeAjax = 'HTML' 405 } 406 407 $.ajax({ 408 type: 'POST', 409 url: parametros.urlAjax, 410 data: parametros, 411 dataType: dataTypeAjax, 412 413 success: function (paginaCargada) { 414 415 if (parametros.MostrarFiltros === 'facets' && parametros.forma_listar !== 'carga') { 416 that.find('.contenedorFacets .filtro_busqueda-opciones:not(:checked)').parents('.elementoFacet').remove(); 417 } 418 419 if (parametros.TipoFormatter === 'slider') { 420 apagarSlider(thatconnect) 421 } 422 423 if (parametros.tipo_paginacion === 'infinite' && parametros.forma_listar !== 'busqueda') { 424 thatconnect.find('.resultados_listado').append(paginaCargada); 425 } else { 426 thatconnect.find('.resultados_listado').html(paginaCargada); 427 } 428 429 if (parametros.UbicacionCargandoNumerico === 'cadaRecurso') { 430 aniadirCargandoAElementos(thatconnect, parametros.rutaCargandoElemento); 431 } else { 432 aniadirCargandoAListado(thatconnect, parametros.rutaCargandoElemento); 433 } 434 435 // $.list_backgroundizator(that.find('.resultados_listado .imagen_elemento img')); 436 437 438 that.find('.CargandoFiltros').addClass('oculto'); 439 that.find('.filtro_busqueda.rangofechas input').prop('disabled', false); 440 that.find('.filtro_busqueda.termino_busqueda input').prop('disabled', false); 441 442 if (cargarAnimacionCargandoEnElementos) { 443 interaccionCargandoElementos(thatconnect, 'ocultar'); 444 } else if (cargarAnimacionEnListado) { 445 interaccionCargandoListado(thatconnect, 'ocultar'); 446 } else { 447 thatconnect.find('.cargandoListado').addClass('oculto'); 448 } 449 450 if (parametros.activarZoom === 'true') { 451 $('.venobox').venobox(); 452 } 453 454 if (parametros.forma_listar === 'busqueda' && parametros.esReinicio !== true && parametros.busquedaActiva === true) { 455 that.find('.reiniciarBusqueda').removeClass('oculto'); 456 that.find('.botones-accion-wrapper').attr('data-reinicio-activo', 'true'); 457 } else if (parametros.esReinicio !== true && parametros.busquedaActiva === true) { 458 that.find('.reiniciarBusqueda').removeClass('oculto'); 459 that.find('.botones-accion-wrapper').attr('data-reinicio-activo', 'true'); 460 } else { 461 that.find('.reiniciarBusqueda').addClass('oculto'); 462 that.find('.botones-accion-wrapper').attr('data-reinicio-activo', 'false'); 463 } 464 465 if (parametros.esReinicio === true) { 466 that.find('.filtro_busqueda-opciones').prop('checked', false); 467 that.find('.reiniciarBusqueda').addClass('oculto'); 468 that.find('.botones-accion-wrapper').attr('data-reinicio-activo', 'false'); 469 } 470 471 if (parametros.AgruparPorDataNivel === 'true') { 472 AgruparPorDataNivel(parametros); 473 } 474 475 if (parametros.TipoFormatter === 'slider') { 476 iniciarSlider(parametros, thatconnect) 477 } 478 479 cargandoListado = false;
480 parametros.esReinicio = false; 481 482 if (!parametros.MostrarResultadosAlInicio) { 483 parametros.Prebusqueda = ''; 484 } 485 } 486 }); 487 } else { 488 } 489 } 490 491 function interaccion(parametros, that, thatconnect) { 492 if (thatconnect === undefined) { 493 thatconnect = that; 494 } 495 496 var keypressFecha = false; 497 var valorAnteriorFecha; 498 499 // Filtrar cualquier cosa que no sea la fecha 500 $(document).on('change', "#" + that.attr('id') + " .filtro_busqueda-opciones", function (e) { 501 var realizarLlamada = true; 502 503 if ($(this).closest('.filtro_busqueda').hasClass('rangofechas') && keypressFecha === true) { 504 realizarLlamada = false; 505 } 506 507 if (cargandoListado === false && realizarLlamada) { 508 parametros.forma_listar = 'busqueda'; 509 parametros.page = 1; 510 511 llamadaListado(parametros, that, thatconnect); 512 } 513 }); 514 515 // Sistema de filtro por fecha 516 $(document).on('focus', "#" + that.attr('id') + " .filtro_busqueda.rangofechas .filtro_busqueda-opciones", function (e) { 517 valorAnteriorFecha = $(this).val(); 518 }); 519 520 $(document).on('keypress', "#" + that.attr('id') + " .filtro_busqueda.rangofechas .filtro_busqueda-opciones", function (e) { 521 var realizarLlamada = true; 522 keypressFecha = true; 523 524 // Comprobamos si se ha pulsado "intro" 525 if (e.which === 13) { 526 var valorInputFecha = $(this).val(); 527 528 if (valorInputFecha) { 529 var date = new Date(valorInputFecha); 530 if (!isNaN(date.getTime())) { // Verifica si la fecha es válida 531 if (date.getTime() < -30610223116000 || date.getTime() > 253370761200000) { // Task 12879: Comprueba una fecha mÃnima y máxima antes de realizar la búsqueda 532 realizarLlamada = false; 533 } else { 534 realizarLlamada = true; 535 } 536 } else { 537 realizarLlamada = false; 538 } 539 540 if (cargandoListado === false && realizarLlamada && valorAnteriorFecha !== $(this).val()) { 541 parametros.forma_listar = 'busqueda'; 542 parametros.page = 1; 543 544 llamadaListado(parametros, that, thatconnect); 545 } 546 } 547 548 keypressFecha = false; 549 } 550 }); 551 552 $(document).on('blur', "#" + that.attr('id') + " .filtro_busqueda.rangofechas .filtro_busqueda-opciones", function (e) { 553 var realizarLlamada = true; 554 555 // Comprobamos si se ha pulsado "intro" o si se ha hecho clic fuera del input 556 var valorInputFecha = $(this).val(); 557 558 if (valorInputFecha) { 559 var date = new Date(valorInputFecha); 560 if (!isNaN(date.getTime())) { // Verifica si la fecha es válida 561 if (date.getTime() < -30610223116000 || date.getTime() > 253370761200000) { // Task 12879: Comprueba una fecha mÃnima y máxima antes de realizar la búsqueda 562 realizarLlamada = false; 563 } else { 564 realizarLlamada = true; 565 } 566 } else { 567 realizarLlamada = false; 568 } 569 570 if (cargandoListado === false && realizarLlamada && valorAnteriorFecha !== $(this).val()) { 571 parametros.forma_listar = 'busqueda'; 572 parametros.page = 1; 573 574 llamadaListado(parametros, that, thatconnect); 575 576 keypressFecha = false;
577 } 578 } 579 }); 580 // FIN Sistema de filtro por fecha ----------------------------------------------- 581 582 // Ordenación 583 $(document).on('change', "#" + that.attr('id') + " .ordenacionResultados .selectOrdenacion", function (e) { 584 var realizarLlamada = true; 585 586 if (cargandoListado === false && realizarLlamada) { 587 parametros.forma_listar = 'busqueda'; 588 parametros.page = 1; 589 590 llamadaListado(parametros, that, thatconnect); 591 } 592 }); 593 594 $(document).on('click', "#" + that.attr('id') + " .elementoAlfabeto", function (e) { 595 596 if ($(this).hasClass('marcado')) { 597 $(this).removeClass('marcado'); 598 $(this).closest('.filtro_busqueda').find('.filtro_busqueda-opciones').val(''); 599 } else { 600 $("#" + that.attr('id') + " .elementoAlfabeto").removeClass('marcado'); 601 $(this).addClass('marcado'); 602 $(this).closest('.filtro_busqueda').find('.filtro_busqueda-opciones').val($(this).text()); 603 } 604 605 if (cargandoListado === false) { 606 parametros.forma_listar = 'busqueda'; 607 parametros.page = 1; 608 609 llamadaListado(parametros, that, thatconnect); 610 } 611 }); 612 613 $(document).on('click', '.RealizarBusqueda.oculto', function (e) { 614 if (cargandoListado === false) { 615 parametros.forma_listar = 'busqueda'; 616 parametros.page = 1; 617 618 llamadaListado(parametros, that, thatconnect); 619 } 620 }); 621 622 $(document).on('click', '.reiniciarBusqueda', function () { 623 624 parametros.forma_listar = 'busqueda'; 625 parametros.esReinicio = true; 626 parametros.page = 1; 627 628 removeQueryParam('busqueda'); 629 630 $("#" + that.attr('id') + " .elementoAlfabeto").removeClass('marcado'); 631 632 vaciarFiltros(parametros, that, thatconnect); 633 }); 634 635 if (parametros.PlegadoFiltros !== 'nunca') { 636 $(document).on('click', "#" + that.attr('id') + " .filtros_busqueda-accionador", function (e) { 637 $(this).toggleClass('desplegado'); 638 $(this).siblings('.filtros_busqueda').slideToggle("fast", function () { 639 if ($(this).css('display') != 'none') { 640 $(this).css('display', 'flex'); 641 } 642 }); 643 }) 644 } 645 646 if (parametros.tipo_paginacion === 'numeros') { 647 $(document).on('click', "#" + that.attr('id') + " .paginacion_contenedor .paginacion_pagina", function (e) { 648 e.preventDefault(); 649 parametros.page = parseInt($(this).text()); 650 parametros.forma_listar = 'carga'; 651 llamadaListado(parametros, that, thatconnect); 652 }); 653 654 $(document).on('click', "#" + that.attr('id') + " .paginacion_contenedor .paginacion_siguiente", function (e) { 655 e.preventDefault(); 656 parametros.page = parseInt($("#" + that.attr('id') + " .zona_inferior").attr('data-npagina')) + 1; 657 parametros.forma_listar = 'carga'; 658 llamadaListado(parametros, that, thatconnect); 659 }); 660 661 $(document).on('click', "#" + that.attr('id') + " .paginacion_contenedor .paginacion_anterior", function (e) { 662 e.preventDefault(); 663 parametros.page = parseInt($("#" + that.attr('id') + " .zona_inferior").attr('data-npagina')) - 1; 664 parametros.forma_listar = 'carga'; 665 llamadaListado(parametros, that, thatconnect); 666 }); 667 668 $(document).on('click', "#" + that.attr('id') + " .paginacion_contenedor .paginacion_primera", function (e) { 669 e.preventDefault(); 670 parametros.page = 1; 671 parametros.forma_listar = 'carga'; 672 llamadaListado(parametros, that, thatconnect); 673 }); 674 675 $(document).on('click', "#" + that.attr('id') + " .paginacion_contenedor .paginacion_ultima", function (e) { 676 e.preventDefault(); 677 parametros.page = parseInt($("#" + that.attr('id') + " .totalPages").val()); 678 parametros.forma_listar = 'carga'; 679 llamadaListado(parametros, that, thatconnect); 680 }); 681 682 $(document).on('click', "#" + that.attr('id') + " .resultados_listado ul li a", function (e) { 683 e.preventDefault(); 684 var TargetValue = $(this).attr("target"); 685 var PaginaDestino = $(this).attr('href'); 686 687 if (TargetValue === '_blank') { 688 window.open(PaginaDestino, '_blank'); 689 } else { 690 var UrlActual = window.location.href; 691 var PaginaActual = parseInt($("#" + that.attr('id') + " .zona_inferior").attr('data-npagina')); 692 693 var urlParts = UrlActual.split('?'); 694 var baseUrl = urlParts[0]; 695 var searchParams = urlParts[1] ? urlParts[1].split('&') : []; 696 var newSearchParams = []; 697 698 for (var i = 0; i < searchParams.length; i++) { 699 var paramParts = searchParams[i].split('='); 700 var paramName = paramParts[0]; 701 if (paramName !== 'page' && paramName !== 'BusquedaInicial') { 702 newSearchParams.push(searchParams[i]); 703 } 704 } 705 706 if (PaginaActual !== 1) { 707 newSearchParams.push('page=' + PaginaActual); 708 } 709 710 var JSONfiltrosVolver = {}; 711 712 JSONfiltrosVolver = gestionJsonPrefiltros('texto', JSONfiltrosVolver, that.find('.filtros_busqueda .termino_busqueda')); 713 JSONfiltrosVolver = gestionJsonPrefiltros('desde', JSONfiltrosVolver, that.find('.filtros_busqueda .desde')); 714 JSONfiltrosVolver = gestionJsonPrefiltros('hasta', JSONfiltrosVolver, that.find('.filtros_busqueda .hasta')); 715 JSONfiltrosVolver = gestionJsonPrefiltros('type', JSONfiltrosVolver, that.find('.filtros_busqueda .tipoRecurso-busqueda')); 716 JSONfiltrosVolver = gestionJsonPrefiltros('category_exact', JSONfiltrosVolver, that.find('.filtros_busqueda .categoria-busqueda')); 717 718 that.find('.filtro_personalizado').each(function () { 719 JSONfiltrosVolver = gestionJsonPrefiltros($(this).attr('data-camposolr'), JSONfiltrosVolver, $(this)); 720 }); 721 722 var parametro = ''; 723 for (var campo in JSONfiltrosVolver) { 724 parametro += campo + ':' + JSONfiltrosVolver[campo] + '|'; 725 } 726 727 parametro = parametro.slice(0, -1); 728 729 if (!$.isEmptyObject(JSONfiltrosVolver)) { 730 newSearchParams.push('BusquedaInicial=' + encodeURIComponent(parametro)); 731 } 732 733 var newUrl = baseUrl; 734 735 if (newSearchParams && Array.isArray(newSearchParams) && newSearchParams.length > 0) { 736 newUrl += '?' + newSearchParams.join('&'); 737 } 738 739 740 window.history.pushState("Página de donde vengo", "TÃtulo", newUrl); 741 742 window.location.href = PaginaDestino; 743 } 744 745 }); 746 747 }
747 else if (parametros.tipo_paginacion === 'infinite') { 748 $(window).scroll(function () { 749 if ($(window).scrollTop() + $(window).height() >= that.height()) { 750 751 parametros.page = parseInt($("#" + that.attr('id') + " .paginaActualFormatter").val()) + 1; 752 parametros.forma_listar = 'carga'; 753 754 if (parametros.page <= $("#" + that.attr('id') + " .totalPages").val()) { 755 if (cargandoListado === false) { 756 llamadaListado(parametros, that, thatconnect); 757 } 758 } 759 } 760 }); 761 } 762 763 if (parametros.UbicacionCargandoNumerico === 'cadaRecurso') { 764 aniadirCargandoAElementos(thatconnect, parametros.rutaCargandoElemento); 765 } else { 766 aniadirCargandoAListado(thatconnect, parametros.rutaCargandoElemento); 767 } 768 769 if (parametros.TipoFormatter === 'slider') { 770 iniciarSlider(parametros, thatconnect) 771 } 772 773 $(document).on('click', '#' + that.attr('id') + ' .filtro_busqueda-toggle', function () { 774 var estadoActual; 775 if ($(this).hasClass('desplegado')) { 776 estadoActual = 'desplegado'; 777 } else { 778 estadoActual = 'replegado'; 779 } 780 var contenedorFiltro = $(this).closest('.filtro_busqueda'); 781 var elementoActual = $(this).closest('.filtros_busqueda-label-contenedor'); 782 var elementoActualContenido = elementoActual.siblings('.contenedorFacets'); 783 784 if (estadoActual === 'desplegado') { 785 $(this).removeClass('desplegado'); 786 $(this).addClass('replegado'); 787 contenedorFiltro.removeClass('desplegado'); 788 contenedorFiltro.addClass('replegado'); 789 elementoActual.removeClass('desplegado'); 790 elementoActual.addClass('replegado'); 791 792 elementoActualContenido.slideUp("fast"); 793 } else { 794 $(this).removeClass('replegado'); 795 $(this).addClass('desplegado'); 796 contenedorFiltro.removeClass('replegado'); 797 contenedorFiltro.addClass('desplegado'); 798 elementoActual.removeClass('replegado'); 799 elementoActual.addClass('desplegado'); 800 801 elementoActualContenido.slideDown("fast"); 802 } 803 }); 804 805 if (parametros.activarReiniciarFiltros) { 806 that.find('.reiniciarBusqueda').removeClass('oculto'); 807 } 808 809 // Selector de orden personalizado en el front 810 if (that.find('.ordenacionResultados .selectOrdenacion').length > 0) { 811 812 var ordenSeleccionado = that.find('.ordenacionResultados .selectOrdenacion .ordenSeleccionado').attr('data-orden-actual'); 813 814 if (ordenSeleccionado !== 'defecto') { 815 parametros.OrdenacionQueryFront = ordenSeleccionado; 816 } else { 817 parametros.OrdenacionQueryFront = ''; 818 } 819 820 $(document).on('click', "#" + that.attr('id') + " .ordenacionResultados .selectOrdenacion .ordenSeleccionado", function (e) { 821 var contenedorPadre = $(this).closest('.selectOrdenacion'); 822 var contenedorEtiqueta = $(this).closest('.ordenSeleccionado'); 823 var contenedorListado = $(this).siblings('.listaOrdenes'); 824 825 if (contenedorPadre.hasClass('desplegado')) { 826 contenedorPadre.removeClass('desplegado'); 827 contenedorEtiqueta.removeClass('desplegado'); 828 contenedorPadre.addClass('plegado'); 829 contenedorEtiqueta.addClass('plegado'); 830 } else { 831 contenedorPadre.removeClass('plegado'); 832 contenedorEtiqueta.removeClass('plegado'); 833 contenedorPadre.addClass('desplegado'); 834 contenedorEtiqueta.addClass('desplegado'); 835 } 836 837 contenedorListado.slideToggle(100); 838 }); 839 840 $(document).on('click', "#" + that.attr('id') + " .ordenacionResultados .selectOrdenacion .elementoOrde
840nacion", function (e) { 841 var contenedorPadre = $(this).closest('.selectOrdenacion'); 842 var contenedorSelector = contenedorPadre.find('.ordenSeleccionado'); 843 var contenedorEtiqueta = contenedorPadre.find('.etiquetaOrden'); 844 var contenedorListado = contenedorPadre.find('.listaOrdenes'); 845 846 var solrOrdenacionSeleccionada = $(this).attr('data-orden'); 847 var etiquetaOrdenacionSeleccionada = $(this).text(); 848 849 contenedorEtiqueta.html(etiquetaOrdenacionSeleccionada); 850 851 if (solrOrdenacionSeleccionada === '' || solrOrdenacionSeleccionada === undefined) { 852 solrOrdenacionSeleccionada = 'defecto'; 853 } 854 contenedorSelector.attr('data-orden-actual', solrOrdenacionSeleccionada); 855 856 parametros.forma_listar = 'busqueda'; 857 parametros.page = 1; 858 859 llamadaListado(parametros, that, thatconnect); 860 861 contenedorSelector.removeClass('desplegado'); 862 contenedorPadre.removeClass('desplegado'); 863 contenedorSelector.addClass('plegado'); 864 contenedorPadre.addClass('plegado'); 865 866 contenedorListado.slideUp(100); 867 }); 868 869 // CLICK FUERA DEL SELECTOR DE ORDEN 870 $(document).on('click', function (event) { 871 var $target = $(event.target); 872 if (!$target.closest('.selectOrdenacion ').length && $target.parents('.selectOrdenacion ').length === 0) { 873 var contenedorPadre = $("#" + that.attr('id') + " .ordenacionResultados .selectOrdenacion"); 874 var contenedorSelector = contenedorPadre.find('.ordenSeleccionado'); 875 var contenedorListado = contenedorPadre.find('.listaOrdenes'); 876 877 contenedorSelector.removeClass('desplegado'); 878 contenedorPadre.removeClass('desplegado'); 879 contenedorSelector.addClass('plegado'); 880 contenedorPadre.addClass('plegado'); 881 882 contenedorListado.slideUp(100); 883 } 884 }); 885 } else { 886 parametros.OrdenacionQueryFront = ''; 887 } 888 // ------------------------------------------------ 889 890 // Selector de exportación en el front 891 if (that.find('.exportacionResultados .selectExportacion').length > 0) { 892 893 // DESPLIEGA LAS OPCIONES DE EXPORTACIÃN 894 $(document).on('click', "#" + that.attr('id') + " .exportacionResultados .selectExportacion .labelExportacion", function (e) { 895 var contenedorPadre = $(this).closest('.selectExportacion'); 896 var contenedorEtiqueta = $(this).closest('.labelExportacion'); 897 var contenedorListado = $(this).siblings('.listaExportacion'); 898 899 if (contenedorPadre.hasClass('desplegado')) { 900 contenedorPadre.removeClass('desplegado'); 901 contenedorEtiqueta.removeClass('desplegado'); 902 contenedorPadre.addClass('plegado'); 903 contenedorEtiqueta.addClass('plegado'); 904 } else { 905 contenedorPadre.removeClass('plegado'); 906 contenedorEtiqueta.removeClass('plegado'); 907 contenedorPadre.addClass('desplegado'); 908 contenedorEtiqueta.addClass('desplegado'); 909 } 910 911 contenedorListado.slideToggle(100); 912 }); 913 914 // CLICK FUERA DEL SELECTOR DE EXPORTACIÃN 915 $(document).on('click', function (event) { 916 var $target = $(event.target); 917 if (!$target.closest('.selectExportacion ').length && $target.parents('.selectExportacion ').length === 0) { 918 var contenedorPadre = $("#" + that.attr('id') + " .exportacionResultados .selectExportacion"); 919 var contenedorSelector = contenedorPadre.find('.labelExportacion'); 920 var contenedorListado = contenedorPadre.find('.listaExportacion'); 921 922 contenedorSelector.removeClass('desplegado'); 923 contenedorPadre.removeClass('desplegado'); 924 contenedorSelector.addClass('plegado'); 925 contenedorPadre.addClass('plegado'); 926 927 contenedorListado.slideUp(100); 928 } 929 }); 930 931 // CLICK EN UNA OPCIÃN DE EXPORTACIÃN 932 $(document).on('click', "#" + that.attr('id') + " .exportacionResultados .selectExportacion .elementoExportacion", function (e) { 933 const paramsModal = { 934 accion: 'configurarExportacion', 935 tipoExportacion: $(this).attr('data-tipo') 936 } 937 llamarModalSagaListado(paramsModal); 938 }); 939 940 // CLICK EN EL BOTÃN DE EXPORTAR DEL MODAL 941 $(document).on('click', ".accionesConfiguracionExportacion .exportarFormulario", function (e) { 942 switch ($(this).attr('data-accion')) { 943 case 'PDF': 944 exportarSagaListadoPDF(); 945 break; 946 case 'XLSX':
947 exportarSagaListadoExcel(); 948 break; 949 } 950 }); 951 952 // CLICK FUERA DEL MODAL PARA CERRARLO 953 $(document).on('click', ':not(.ExportacionSagaListadoVuelo)', function (event) { 954 var $target = $(event.target); 955 if (!$target.closest('.modalSagaListadoWrapper ').length && $target.parents('.modalSagaListadoWrapper ').length === 0 && $target.closest('.ExportacionSagaListadoVuelo').length === 0) { 956 if (!$('.modalSagaListadoContenido').hasClass('cargandoExportacion')) { 957 $('.modalSagaListado').fadeOut(function () { 958 $(this).remove(); 959 }); 960 } 961 } 962 }); 963 } 964 // ------------------------------------------------ 965 966 $(document).on('click', "#" + that.attr('id') + " .SugerenciasListado-Collated", function () { 967 $('.filtro_busqueda.termino_busqueda .filtro_busqueda-opciones').val($(this).text()); 968 llamadaListado(parametros, that, thatconnect); 969 }); 970 } 971 972 function removeQueryParam(parametro) { 973 // Obtener la URL actual 974 var currentUrl = window.location.href; 975 976 // Buscar el Ãndice del parámetro especificado 977 var paramIndex = currentUrl.indexOf(parametro + '='); 978 979 // Si se encuentra el parámetro 980 if (paramIndex !== -1) { 981 // Obtener el Ãndice del siguiente carácter "&" o el final de la URL 982 var nextCharIndex = currentUrl.indexOf('&', paramIndex); 983 984 // Si no se encuentra el carácter "&" 985 if (nextCharIndex === -1) { 986 // Quitar el parámetro y su valor de la URL 987 currentUrl = currentUrl.substring(0, paramIndex - 1); 988 } else { 989 // Quitar el parámetro y su valor de la URL 990 currentUrl = currentUrl.substring(0, paramIndex) + currentUrl.substring(nextCharIndex + 1); 991 } 992 993 // Actualizar la URL en el historial del navegador sin redirigir 994 window.history.replaceState(null, null, currentUrl); 995 } 996 } 997 998 function getRandomInt(min, max) { 999 return Math.floor(Math.random() * (max - min)) + min; 1000 } 1001 1002 function vaciarFiltros(parametros, that, thatconnect) { 1003 that.find('.filtro_busqueda input[type="text"],.filtro_busqueda input[type="date"],.filtro_busqueda select,.filtro_busqueda-opciones').val(''); 1004 that.find('.filtro_busqueda input[type="checkbox"]').prop('checked', false); 1005 parametros.dym = ''; 1006 1007 llamadaListado(parametros, that, thatconnect); 1008 } 1009 1010 $(document).on('focus', '.rangofechas input[type="text"], .rangofechas_personalizado input[type="text"]', function () { 1011 var tipoInput = $(this).attr('type'); 1012 1013 if (tipoInput == 'text') { 1014 $(this).attr('type', 'date'); 1015 } 1016 }); 1017 1018 // Boton de acción en responsive, flotante. 1019 function FiltrosFlotanteRestponsive(parametros) { 1020 var idListado = ".SagaListado[data-css-id=" + parametros.that + "]"; 1021 var MostrarFiltrosSuperior = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .MostrarFiltros-wrapper .MostrarFiltros.superior'; 1022 var CerrarFiltrosSuperior = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .CerrarFiltros-wrapper .CerrarFiltros.superior'; 1023 var AplicarFiltrosInferior = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .AplicarFiltros-wrapper .AplicarFiltros.inferior'; 1024 var reiniciarBusquedaInferior = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .reiniciarBusqueda-wrapper .reiniciarBusqueda.inferior'; 1025 var MostrarFiltros = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .MostrarFiltros-wrapper .MostrarFiltros';
1026 var CerrarFiltros = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .CerrarFiltros-wrapper .CerrarFiltros'; 1027 var AplicarFiltros = idListado + ' .wrapper-aside .filtros_busqueda .botones-accion-wrapper .AplicarFiltros-wrapper .AplicarFiltros'; 1028 1029 $(document).ready(function () { 1030 function actualizarClase() { 1031 if ($(window).width() > parametros.CorteFiltrosFlotanteRestponsive) { 1032 $(MostrarFiltrosSuperior).addClass('oculto'); 1033 } else { 1034 $(MostrarFiltrosSuperior).removeClass('oculto'); 1035 } 1036 } 1037 1038 actualizarClase(); 1039 $(window).resize(actualizarClase); 1040 $(document).ajaxComplete(actualizarClase); 1041 }); 1042 1043 1044 $(document).on('click', MostrarFiltros, function () { 1045 var $wrapperAside = $(this).closest('.SagaListado .wrapper-aside'); 1046 if ($wrapperAside.hasClass('flotante')) { 1047 $wrapperAside.addClass('cerrando'); 1048 setTimeout(function () { 1049 $wrapperAside.removeClass('cerrando'); 1050 $wrapperAside.removeClass('flotante'); 1051 $(CerrarFiltrosSuperior).toggleClass('oculto'); 1052 $(AplicarFiltrosInferior).toggleClass('oculto'); 1053 $(reiniciarBusquedaInferior).toggleClass('ocultisimo'); 1054 }, 500); 1055 1056 } else { 1057 $wrapperAside.addClass('flotante'); 1058 $(CerrarFiltrosSuperior).toggleClass('oculto'); 1059 $(AplicarFiltrosInferior).toggleClass('oculto'); 1060 $(reiniciarBusquedaInferior).toggleClass('ocultisimo'); 1061 } 1062 }); 1063 1064 1065 $(document).on('click', AplicarFiltros, function () { 1066 var $wrapperAside = $('.SagaListado .wrapper-aside'); 1067 if ($wrapperAside.hasClass('flotante')) { 1068 $wrapperAside.addClass('cerrando'); 1069 setTimeout(function () { 1070 $wrapperAside.removeClass('cerrando'); 1071 $wrapperAside.removeClass('flotante'); 1072 $(CerrarFiltrosSuperior).toggleClass('oculto'); 1073 $(AplicarFiltrosInferior).toggleClass('oculto'); 1074 $(reiniciarBusquedaInferior).toggleClass('ocultisimo'); 1075 }, 500); 1076 1077 } 1078 }); 1079 $(document).on('click', CerrarFiltros, function () { 1080 var $wrapperAside = $('.SagaListado .wrapper-aside'); 1081 if ($wrapperAside.hasClass('flotante')) { 1082 $wrapperAside.addClass('cerrando'); 1083 setTimeout(function () { 1084 $wrapperAside.removeClass('cerrando'); 1085 $wrapperAside.removeClass('flotante'); 1086 $(CerrarFiltrosSuperior).toggleClass('oculto'); 1087 $(reiniciarBusquedaInferior).toggleClass('ocultisimo'); 1088 $(AplicarFiltrosInferior).toggleClass('oculto'); 1089 }, 500); 1090 1091 } 1092 }); 1093 } 1094 1095 1096 function moverCreacion(that, idElemento, idiomaUsuarioActual, ejecutarDende) { 1097 var titleCmsState; 1098 if (idiomaUsuarioActual === 'en') { 1099 titleCmsState = 'New'; 1100 } else { 1101 titleCmsState = 'Nuevo' 1102 } 1103 1104 var intervalID = setInterval(function () { 1105 if ($('#' + idElemento).find('.ListadoBotones .cmsState[title="' + titleCmsState + '"]').length > 0) { 1106 clearInterval(intervalID); 1107 1108 if (ejecutarDende === true) { 1109 DendeScript(idElemento, function () { 1110 moverCreacion(that, idElemento, idiomaUsuarioActual, false); 1111 }); 1112 } 1113 1114 $('#' + idElemento).find('.ListadoBotones .BotonCreacion').each(function (index) { 1115 var elementoMover = $('#' + idElemento).find('.org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons').eq(index).find('.cmsState[title=' + titleCmsState + ']').detach(); 1116 /*console.log(elementoMover); 1117 console.log(idiomaUsuarioActual); 1118 console.log(titleCmsState);*/ 1119 elementoMover.appendTo($(this)).data($('#' + idElemento).find('.org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons .cmsState[title=' + titleCmsState + ']').eq(index).data("events")); 1120 }); 1121 } 1122 }, 500); 1123 } 1124 1125 function moverSagaListadoConfig(that, idElemento, idiomaUsuarioActual, ejecutarDende) { 1126 var titleCmsState; 1127 if (idiomaUsuarioActual === 'en') { 1128 titleCmsState = 'Edit'; 1129 } else { 1130 titleCmsState = 'Editar' 1131 } 1132 1133 var intervalID = setInterval(function () { 1134 if ($('#' + idElemento).find('.editarSagaListadoConfig .cmsState[title="' + titleCmsState + '"]').length > 0) { 1135 clearInterval(intervalID); 1136 1137 if (ejecutarDende === true) { 1138 DendeScript(idElemento, function () { 1139 moverSagaListadoConfig(that, idElemento, idiomaUsuarioActual, false); 1140 }); 1141 } 1142 1143 var elementoMover = $('#' + idElemento).find('.editarSagaListadoConfig .org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons').find('.cmsState[title=' + titleCmsState + ']').detach(); 1144 /*console.log(elementoMover); 1145 console.log(idiomaUsuarioActual); 1146 console.log(titleCmsState);*/ 1147 elementoMover.appendTo($('#' + idElemento).find('.editarSagaListadoConfig')).data($('#' + idElemento).find('.editarSagaListadoConfig .org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons .cmsState[title=' + titleCmsState + ']').data("events")); 1148 } 1149 }, 500); 1150 } 1151 1152 function moverSagaListadoFormatterConfig(that, idElemento, idiomaUsuarioActual, ejecutarDende) { 1153 var titleCmsState; 1154 if (idiomaUsuarioActual === 'en') { 1155 titleCmsState = 'Edit'; 1156 } else { 1157 titleCmsState = 'Editar' 1158 } 1159 1160 var intervalID = setInterval(function () { 1161 if ($('#' + idElemento).find('.editarSagaListadoFormatterConfig .cmsState[title="' + titleCmsState + '"]').length > 0) { 1162 clearInterval(intervalID); 1163 1164 if (ejecutarDende === true) { 1165 DendeScript(idElemento, function () { 1166 moverSagaListadoFormatterConfig(that, idElemento, idiomaUsuarioActual, false); 1167 }); 1168 } 1169 1170 var elementoMover = $('#' + idElemento).find('.editarSagaListadoFormatterConfig .org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons').find('.cmsState[title=' + titleCmsState + ']').detach(); 1171 /*console.log(elementoMover); 1172 console.log(idiomaUsuarioActual); 1173 console.log(titleCmsState);*/ 1174 elementoMover.appendTo($('#' + idElemento).find('.editarSagaListadoFormatterConfig')).data($('#' + idElemento).find('.editarSagaListadoFormatterConfig .org-opencms-gwt-client-ui-css-I_CmsDirectEditCss-directEditButtons .cmsState[title=' + titleCmsState + ']').data("events")); 1175 } 1176 }, 500); 1177 } 1178 1179 function aniadirCargandoAElementos(thatconnect, rutaCargandoElemento) { 1180 1181 thatconnect.find('.resultados_listado .listado li').each(function () { 1182 if ($(this).find('.cargando_elemento').length === 0) { 1183 $(this).append('<div class="cargando_elemento oculto"><lottie-player class="" src="' + rutaCargandoElemento + '" background="transparent" loop autoplay></lottie-player></div>'); 1184 } 1185 }); 1186 } 1187 1188 function interaccionCargandoElementos(thatconnect, accion) { 1189 1190 if (accion === 'mostrar') { 1191 thatconnect.find('.resultados_listado .listado li').each(function () { 1192 $(this).addClass('animando'); 1193 }); 1194 thatconnect.find('.cargando_elemento').removeClass('oculto'); 1195 } else { 1196 thatconnect.find('.resultados_listado .listado li').each(function () { 1197 $(this).removeClass('animando'); 1198 }); 1199 thatconnect.find('.cargando_elemento').addClass('oculto'); 1200 } 1201 } 1202 1203 function aniadirCargandoAListado(thatconnect, rutaCargandoElemento) { 1204 1205 thatconnect.find('.resultados_contenedor').each(function () { 1206 if ($(this).find('.cargando_listado').length === 0) { 1207 $(this).append('<div class="cargando_listado oculto"><lottie-player class="" src="' + rutaCargandoElemento + '" background="transparent" loop autoplay></lottie-player></div>'); 1208 } 1209 }); 1210 } 1211 1212 function interaccionCargandoListado(thatconnect, accion) { 1213 1214 if (accion === 'mostrar') { 1215 thatconnect.find('.cargando_listado').removeClass('oculto'); 1216 } else { 1217 thatconnect.find('.cargando_listado').addClass('oculto'); 1218 } 1219 } 1220 1221 // CONVERTIMOS IMÃGENES EN BACKGROUNDS PARA FAVORECER AL RESPONSIVE 1222 $.list_backgroundizator = function (element) { 1223 $(element).each(function (index) { 1224 var class_a_crear = 'background_dinamico_' + getRandomInt(0, 1000000); 1225 var url_imagen = $(this).attr('src'); 1226 var estilo_a_aplicar = '.' + class_a_crear + '{background-image: url("' + url_imagen + '");}'; 1227 1228 let style = document.createElement('style'); 1229 style.type = 'text/css'; 1230 document.head.appendChild(style); 1231 style.innerHTML = estilo_a_aplicar; 1232 1233 $('<div class="background_dinamico ' + class_a_crear + '"></div>').insertBefore($(this)); 1234 1235 $(this).parents('.imagen_elemento').addClass('background_dinamico-fixed'); 1236 1237 $(this).remove(); 1238 }); 1239 }; 1240 1241 function iniciarSlider(parametros, thatconnect) { 1242 // FORMATTER DE SLIDER 1243 var slickConfig = { 1244 pauseOnFocus: false, 1245 pauseOnHover: false, 1246 lazyLoad: "progressive",
1247 cssEase: "cubic-bezier(0.87, 0.03, 0.41, 0.9)", 1248 responsive: [ 1249 { 1250 breakpoint: 768, 1251 settings: { 1252 arrows: true, 1253 slidesToShow: 2, 1254 slidesToScroll: 2 1255 } 1256 }, 1257 { 1258 breakpoint: 480, 1259 settings: { 1260 arrows: true, 1261 slidesToShow: 1, 1262 slidesToScroll: 1 1263 } 1264 } 1265 ] 1266 }; 1267 1268 slickConfig.dots = parametros.SliderResultadosDots; 1269 slickConfig.arrows = parametros.SliderResultadosArrows; 1270 slickConfig.infinite = parametros.SliderResultadosInfinite; 1271 slickConfig.autoplay = parametros.SliderResultadosAutoplay; 1272 slickConfig.slidesToShow = parametros.SliderResultadosNSlides; 1273 slickConfig.slidesToScroll = parametros.SliderResultadosNDesplazados; 1274 1275 thatconnect.find('.resultados_listado .listado').on('init', function (event, slick) { 1276 thatconnect.addClass('slickInicializado'); 1277 }); 1278 1279 thatconnect.find('.resultados_listado .listado').slick(slickConfig); 1280 } 1281 1282 function apagarSlider(thatconnect) { 1283 thatconnect.find('.resultados_listado .listado').slick('unslick'); 1284 } 1285 1286 function gestionJsonPrefiltros(campoObjetivo, json, that) { 1287 var valorFiltro; 1288 1289 if (parametros.MostrarFiltros === 'facets' && campoObjetivo !== 'texto' && campoObjetivo !== 'desde' && campoObjetivo !== 'hasta') { 1290 valorFiltro = that.find('.filtro_busqueda-opciones:checked').val(); 1291 } else { 1292 valorFiltro = that.find('.filtro_busqueda-opciones').val(); 1293 } 1294 1295 if ((campoObjetivo !== undefined) && (campoObjetivo !== '') && (valorFiltro !== undefined) && (valorFiltro !== '')) { 1296 json[campoObjetivo] = valorFiltro; 1297 } 1298 1299 return json; 1300 } 1301 1302 1303 /* 1304 SISTEMA DE EXPORTACIÃN 1305 */ 1306 1307 // MODAL DE EXPORTACIÃN 1308 function llamarModalSagaListado(data, callback) { 1309 1310 if (data.accion) { 1311 const parametrosLlamada = { 1312 accionModal: data.accion, 1313 tipoExportacion: data.tipoExportacion, 1314 localeActual: parametros.localeActual 1315 } 1316 1317 $.ajax({ 1318 type: "POST", 1319 url: parametros.rutaModal, 1320 dataType: 'HTML', 1321 data: parametrosLlamada, 1322 success: function (responseModal) { 1323 let wrapperModal = $(".modalSagaListadoWrapper"); 1324 switch (data.accion) { 1325 case 'configurarExportacion': 1326 $("body").append(responseModal); 1327 $('.modalSagaListado').fadeIn(); 1328 break; 1329 case 'errorExportacion': 1330 case 'cargarExportacion': 1331 case 'cargarExportacionOK': 1332 wrapperModal.html(responseModal); 1333 break; 1334 default: 1335 console.warn("Acción no reconocida:", data.accion); 1336 break; 1337 } 1338 1339 // Callback se ejecutará después del switch sin ser afectado por los breaks 1340 if (typeof callback === "function") { 1341 callback(null, responseModal); 1342 } 1343 }, 1344 error: function () { 1345 llamarModalSagaListado({accion: 'errorExportacion'}); 1346 } 1347 }); 1348 } else { 1349 console.log('Acción no definida'); 1350 } 1351 1352 } 1353 1354 // REALIZAR EXPORTACIÃN EN PDF 1355 function exportarSagaListadoPDF() { 1356 let nombreArchivoExportacion = $('#nombreExportacionSagaListado').val(); 1357 if (nombreArchivoExportacion === '' || nombreArchivoExportacion === null || nombreArchivoExportacion === undefined) { 1358 nombreArchivoExportacion = 'file' 1359 } 1360 1361 const paramsLlamada = { 1362 ...parametros, 1363 formatterOrigen: 'PDF', 1364 GenerarPdfApaisado: parametros.OrientacionExportacionPDF === 'horizontal', 1365 tituloContenidoArchivoExportacion: $('#tituloExportacionSagaListado').val() 1366 }; 1367 1368 llamarModalSagaListado({accion: 'cargarExportacion'}, function () { 1369 $.ajax({ 1370 type: "POST", 1371 url: parametros.rutaElementPDF, 1372 data: paramsLlamada, 1373 xhrFields: { 1374 responseType: 'blob' // Esto asegura que el response sea tratado como un Blob 1375 }, 1376 success: function (blob) { 1377 // Comprobar si el blob es válido 1378 const reader = new FileReader(); 1379 reader.onload = function () { 1380 const a = document.createElement('a'); 1381 a.href = reader.result; 1382 a.download = nombreArchivoExportacion + ".pdf"; 1383 a.className = "ExportacionSagaListadoVuelo"; 1384 document.body.appendChild(a); 1385 a.click(); 1386 a.remove(); 1387 };
1388 reader.readAsDataURL(blob); // Convierte el blob a una URL de datos 1389 1390 llamarModalSagaListado({accion: 'cargarExportacionOK'}); 1391 }, 1392 error: function (jqXHR, textStatus, errorThrown) { 1393 llamarModalSagaListado({accion: 'errorExportacion'}); 1394 } 1395 }); 1396 }); 1397 } 1398 1399 // REALIZAR EXPORTACIÃN EN EXCEL 1400 function exportarSagaListadoExcel() { 1401 let nombreArchivoExportacion = $('#nombreExportacionSagaListado').val(); 1402 if (nombreArchivoExportacion === '' || nombreArchivoExportacion === null || nombreArchivoExportacion === undefined) { 1403 nombreArchivoExportacion = 'file' 1404 } 1405 1406 const paramsLlamada = { 1407 ...parametros, 1408 formatterOrigen: 'JSON', 1409 esExportacionExcel: true 1410 }; 1411 1412 llamarModalSagaListado({accion: 'cargarExportacion'}, function () { 1413 $.ajax({ 1414 type: "POST", 1415 url: parametros.urlAjax, 1416 data: paramsLlamada, 1417 dataType: 'json', 1418 success: async function (response) { 1419 const datos = response; 1420 1421 // 1) Crear workbook y worksheet 1422 const workbook = new ExcelJS.Workbook(); 1423 const ws = workbook.addWorksheet('SagaListado'); 1424 1425 // 2) Definir columnas según las claves posibles 1426 let arrayColumnas = [] 1427 datos.columnas.forEach(item => { 1428 arrayColumnas.push({ 1429 header: item.texto, key: item.nodo, width: item.ancho 1430 }); 1431 }); 1432 1433 ws.columns = arrayColumnas; 1434 1435 // 3) Agregar cada elemento del array como fila (con zebra stripes y wrapText) 1436 datos.elementosSagaListado.forEach(item => { 1437 const valores = datos.columnas.map(col => item[col.nodo] || ''); 1438 1439 const row = ws.addRow(valores); 1440 1441 row.eachCell(cell => { 1442 cell.alignment = { 1443 wrapText: true, 1444 vertical: 'top' 1445 }; 1446 }); 1447 }); 1448 1449 // 4) Generar buffer y disparar descarga 1450 const buffer = await workbook.xlsx.writeBuffer(); 1451 const blob = new Blob([buffer], { 1452 type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 1453 }); 1454 saveAs(blob, nombreArchivoExportacion + '.xlsx'); 1455 1456 llamarModalSagaListado({accion: 'cargarExportacionOK'}); 1457 1458 }, 1459 error: function (jqXHR, textStatus, errorThrown) { 1460 llamarModalSagaListado({accion: 'errorExportacion'}); 1461 console.log('ERROR:' + errorThrown); 1462 } 1463 }); 1464 }); 1465 } 1466 1467 /* 1468 FIN SISTEMA DE EXPORTACIÃN 1469 */ 1470 }; 1471})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.