diff --git a/app/assets/javascripts/msip/motor.js.coffee.erb b/app/assets/javascripts/msip/motor.js.coffee.erb index 9dd65236..121d8456 100644 --- a/app/assets/javascripts/msip/motor.js.coffee.erb +++ b/app/assets/javascripts/msip/motor.js.coffee.erb @@ -842,7 +842,7 @@ if (typeof String.prototype.endsWith != 'function') ) # Pone colores de acuerdo al tema - msip_temausuario_ajax() + Msip__Motor.ponerTemaUsuarioAjax() jQuery -> $("a[rel~=popover], .has-popover").popover() $("a[rel~=tooltip], .has-tooltip").tooltip() @@ -944,9 +944,6 @@ if (typeof String.prototype.endsWith != 'function') MsipIniciar() - # Pone colores de acuerdo al tema - msip_temausuario_ajax() - jQuery -> $("a[rel~=popover], .has-popover").popover() $("a[rel~=tooltip], .has-tooltip").tooltip() diff --git a/app/assets/javascripts/msip/motor_es5.js.erb b/app/assets/javascripts/msip/motor_es5.js.erb index 4f00ee76..c32bfe3a 100644 --- a/app/assets/javascripts/msip/motor_es5.js.erb +++ b/app/assets/javascripts/msip/motor_es5.js.erb @@ -271,102 +271,6 @@ function MsipGuardarFormularioYRepintar(listaIdsRepintar, retrollamada_exito, } -function msip_pone_tema(root, tema) { - console.log("entro a msip_ pone_tema") - debugger - document.querySelectorAll('.table-striped>tbody>tr:nth-child(odd)').forEach((element) => { - element.style.backgroundColor = tema.fondo_lista; - }); - document.querySelector('.navbar').style.backgroundImage = `linear-gradient(${tema.nav_ini}, ${tema.nav_fin})`; - document.querySelectorAll('.navbar-default .navbar-nav>li>a').forEach((element) => { - element.style.color = tema.nav_fuente; - }); - document.querySelector('.navbar .navbar-brand').style.color = tema.nav_fuente; - document.querySelectorAll('.navbar-light .navbar-nav .nav-link').forEach((element) => { - element.style.color = tema.nav_fuente; - }); - document.querySelector('.navbar-light .navbar-brand').style.color = tema.nav_fuente; - document.querySelector('.dropdown-menu').style.backgroundColor = tema.nav_fin; - document.querySelectorAll('.dropdown-item').forEach((element) => { - element.style.color = tema.nav_fuente; - element.addEventListener('mouseover', () => { - element.style.color = tema.color_flota_subitem_fuente; - element.style.backgroundColor = tema.color_flota_subitem_fondo; - }); - - element.addEventListener('mouseout', () => { - element.style.color = tema.nav_fuente; - element.style.backgroundColor = tema.nav_fin; - }); - }); - document.querySelectorAll('.alert-success').forEach((element) => { - element.style.color = tema.alerta_exito_fuente; - element.style.backgroundColor = tema.alerta_exito_fondo; - }); - document.querySelectorAll('.alert-danger').forEach((element) => { - element.style.color = tema.alerta_problema_fuente; - element.style.backgroundColor = tema.alerta_problema_fondo; - }); - document.querySelectorAll('.btn').forEach((element) => { - element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_accion_fondo_ini}, ${tema.btn_accion_fondo_fin})`; - element.style.color = tema.btn_accion_fuente; - }); - document.querySelectorAll('.btn-primary').forEach((element) => { - element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_primario_fondo_ini}, ${tema.btn_primario_fondo_fin})`; - element.style.color = tema.btn_primario_fuente; - }); - document.querySelectorAll('.btn-danger').forEach((element) => { - element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_peligro_fondo_ini}, ${tema.btn_peligro_fondo_fin})`; - element.style.color = tema.btn_peligro_fuente; - }); - document.body.style.backgroundColor = tema.fondo; - document.querySelectorAll('.card').forEach((element) => { - element.style.backgroundColor = tema.fondo; - }); - document.querySelectorAll('.msip-sf-bs-input:not(.form-check-input)').forEach((element) => { - element.style.backgroundColor = tema.fondo; - element.style.color = tema.color_fuente; - }); - document.querySelectorAll('.page-link').forEach((element) => { - element.style.backgroundColor = tema.fondo; - }); - document.body.style.color = tema.color_fuente; - document.querySelectorAll('table').forEach((element) => { - element.style.color = tema.color_fuente; - }); -} - -async function msip_temausuario_ajax(){ - var root = window - var ruta = 'temausuario' - var funproc = msip_pone_tema - var datos = {} - var t = Date.now(); - var d = -1; - if (root.msip_ajax_recibe_json_t) { - if (root.msip_ajax_recibe_json_t[ruta]) { - d = (t - root.msip_ajax_recibe_json_t[ruta]) / 1000; - } - } else { - root.msip_ajax_recibe_json_t = {}; - } - root.msip_ajax_recibe_json_t[ruta] = t; - - if (d === -1 || d > 2) { - var rutac = root.puntomontaje + ruta + ".json"; - await fetch(rutac) - .then(function(response) { - if (!response.ok) { - console.error('Request failed with status:', response.status); - } - return response.json(); - }) - .then(function(data) { - return funproc(root, data); - }) - } - return true; -} function MsipIniciar() { MsipAutocompletaAjaxContactos.iniciar() diff --git a/app/javascript/controllers/motor.js b/app/javascript/controllers/motor.js index 14132c08..e5fc99e6 100644 --- a/app/javascript/controllers/motor.js +++ b/app/javascript/controllers/motor.js @@ -56,6 +56,102 @@ export default class Msip__Motor { }) } + // Pone colores del tema en elementos de la interfaz de manera dinámica + static ponerTema(root, tema) { + console.log("entro a msip_ pone_tema") + document.querySelectorAll('.table-striped>tbody>tr:nth-child(odd)').forEach((element) => { + element.style.backgroundColor = tema.fondo_lista; + }); + document.querySelector('.navbar').style.backgroundImage = `linear-gradient(${tema.nav_ini}, ${tema.nav_fin})`; + document.querySelectorAll('.navbar-default .navbar-nav>li>a').forEach((element) => { + element.style.color = tema.nav_fuente; + }); + document.querySelector('.navbar .navbar-brand').style.color = tema.nav_fuente; + document.querySelectorAll('.navbar-light .navbar-nav .nav-link').forEach((element) => { + element.style.color = tema.nav_fuente; + }); + document.querySelector('.navbar-light .navbar-brand').style.color = tema.nav_fuente; + document.querySelector('.dropdown-menu').style.backgroundColor = tema.nav_fin; + document.querySelectorAll('.dropdown-item').forEach((element) => { + element.style.color = tema.nav_fuente; + element.addEventListener('mouseover', () => { + element.style.color = tema.color_flota_subitem_fuente; + element.style.backgroundColor = tema.color_flota_subitem_fondo; + }); + + element.addEventListener('mouseout', () => { + element.style.color = tema.nav_fuente; + element.style.backgroundColor = tema.nav_fin; + }); + }); + document.querySelectorAll('.alert-success').forEach((element) => { + element.style.color = tema.alerta_exito_fuente; + element.style.backgroundColor = tema.alerta_exito_fondo; + }); + document.querySelectorAll('.alert-danger').forEach((element) => { + element.style.color = tema.alerta_problema_fuente; + element.style.backgroundColor = tema.alerta_problema_fondo; + }); + document.querySelectorAll('.btn').forEach((element) => { + element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_accion_fondo_ini}, ${tema.btn_accion_fondo_fin})`; + element.style.color = tema.btn_accion_fuente; + }); + document.querySelectorAll('.btn-primary').forEach((element) => { + element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_primario_fondo_ini}, ${tema.btn_primario_fondo_fin})`; + element.style.color = tema.btn_primario_fuente; + }); + document.querySelectorAll('.btn-danger').forEach((element) => { + element.style.backgroundImage = `linear-gradient(to bottom, ${tema.btn_peligro_fondo_ini}, ${tema.btn_peligro_fondo_fin})`; + element.style.color = tema.btn_peligro_fuente; + }); + document.body.style.backgroundColor = tema.fondo; + document.querySelectorAll('.card').forEach((element) => { + element.style.backgroundColor = tema.fondo; + }); + document.querySelectorAll('.msip-sf-bs-input:not(.form-check-input)').forEach((element) => { + element.style.backgroundColor = tema.fondo; + element.style.color = tema.color_fuente; + }); + document.querySelectorAll('.page-link').forEach((element) => { + element.style.backgroundColor = tema.fondo; + }); + document.body.style.color = tema.color_fuente; + document.querySelectorAll('table').forEach((element) => { + element.style.color = tema.color_fuente; + }); + } + + static async ponerTemaUsuarioAjax(){ + var root = window + var ruta = 'temausuario' + var datos = {} + var t = Date.now(); + var d = -1; + if (root.msip_ajax_recibe_json_t) { + if (root.msip_ajax_recibe_json_t[ruta]) { + d = (t - root.msip_ajax_recibe_json_t[ruta]) / 1000; + } + } else { + root.msip_ajax_recibe_json_t = {}; + } + root.msip_ajax_recibe_json_t[ruta] = t; + + if (d === -1 || d > 2) { + var rutac = root.puntomontaje + ruta + ".json"; + await fetch(rutac) + .then(function(response) { + if (!response.ok) { + console.error('Request failed with status:', response.status); + } + return response.json(); + }) + .then(function(data) { + return Msip__Motor.ponerTema(root, data); + }) + } + return true; + } + // Si el elemento es campos de selección tal vez antes con tom-select // pero con opciones modificadas dinamicamente, refresca static refrescarElementoTomSelect(el) { @@ -80,6 +176,9 @@ export default class Msip__Motor { // Podría ser llamada varias veces consecutivas por lo que debe detectarlo // para no ejecutar dos veces lo que no conviene. static ejecutarAlCargarPagina() { + // Pone colores de acuerdo al tema + Msip__Motor.ponerTemaUsuarioAjax() + Msip__Motor.configurarElementosTomSelect() } diff --git a/test/dummy/app/javascript/application.js b/test/dummy/app/javascript/application.js index cd2e51e1..cb6ed4a0 100644 --- a/test/dummy/app/javascript/application.js +++ b/test/dummy/app/javascript/application.js @@ -67,8 +67,9 @@ document.addEventListener('turbo:load', (e) => { console.log('Escuchador turbo:load') + + msip_ejecutarAlCargarPagina(window) // Establece root.puntomontaje Msip__Motor.ejecutarAlCargarPagina() - msip_ejecutarAlCargarPagina(window) })