function ajaxPostExec(post_url, params, accion){ $.ajax({ url: post_url, type: 'POST', data: params, success: function(result){ if(accion === 'append'){ $('body').append(result); } } }); } function mostrarOtrosMotivos($es_otros){ $('#btn_submit').show(); if($es_otros){ $('#div_otro_motivo').slideDown(); $('#otro_motivo').focus(); }else{ $('#div_otro_motivo').slideUp(); } } function validarBotonOnMouseOver(elem, es_modal){ if(elem.indexOf('#') === -1){ elem = '#' + elem; } if(es_modal){ $('.jconfirm-buttons button:not(:last-child)').on('mouseenter', function(){ $(elem + ' :input').each(function(){ $(this).validate(function(valid, elem){ }); }); }); }else{ $(elem + ' button[type=submit], ' + elem + ' button.submit').on('mouseenter', function(){ $(elem + ' :input').each(function(){ $(this).validate(function(valid, elem){ }); }); }); } } function modalTemporal($color, $formato, $titulo, $timeout){ // Genera una ventana modal con jConfirm temporal (1,5 segundos). Es solo para mensajes de confirmaciones temporales en pantalla. // $color: Puede ser "blue", "green", "red", "orange", "purple" y es para mostrar el tipo de alerta(error, success, danger, etc) // $formato: Refiere al tamaño del modal, puede ser "xs", "sm", "md", "lg" y "xlg" // $titulo: Es el título que se va a mostrar en el modal let $columnas = 'col-sm-12 col-md-6 col-lg-3'; switch($formato){ case 'xs': $columnas = 'col-sm-12 col-md-4 col-lg-2'; break; case 'sm': $columnas = 'col-sm-12 col-md-6 col-lg-3'; break; case 'md': $columnas = 'col-sm-12 col-lg-6'; break; case 'lg': $columnas = 'col-sm-12 col-lg-8'; break; case 'xlg': $columnas = 'col-sm-12 col-lg-10'; break; } $.alert({ bootstrapClasses: { container: 'container text-center modal-sin-botones', containerFluid: 'container-fluid', row: 'row' }, type: $color, title: $titulo, useBootstrap: true, autoClose: 'btnCerrar|' + $timeout, columnClass: $columnas, content: '', buttons: { btnCerrar: { text: 'Cerrar', btnClass: 'btn btn-primary btn-redondeado btnCerrar', action: function(){}, close: function(){} } }, escapeKey: 'btnCerrar', backgroundDismiss: 'btnCerrar', onOpenBefore: function(){ $('.modal-sin-botones').find('.jconfirm-buttons').hide(); $('.modal-sin-botones').find('.jconfirm-title').addClass('mt-4'); } }); } function getRandomInt(min, max){ return Math.floor(Math.random() * (max - min + 1)) + min; } function ajustarAltosLiEstados(){ var alturas = []; $('.estados-intervenciones li').each(function(){ alturas.push(parseInt($(this).css('height'))); }); var alto = Math.max.apply(Math, alturas); $('.estados-intervenciones li').each(function(){ $(this).css('height', '' + alto + 'px'); }) } function validarForm(id_form){ if(id_form.indexOf('#') === -1){ id_form = '#' + id_form; } if($(id_form + ' .valid').length >= 0 && $(id_form + ' .error').length === 0){ //console.log('valido'); return true; }else{ //console.log('invalido'); //console.log($(id_form + ' .error')); return false; } } function postearModal(id_modal){ if(id_modal.indexOf('#') === -1){ id_modal = '#' + id_modal; } $(id_modal + ' input').each(function(){ $(this).validate(function(valid, elem){ }); }); if($(id_modal + ' .valid').length >= 0 && $(id_modal + ' .error').length === 0){ ajaxPostExec($(id_modal).attr('action'), $(id_modal).serialize(), "append"); }else{ return false; } } function validarBotonOnMouseOver(elem, es_modal){ if(elem.indexOf('#') === -1){ elem = '#' + elem; } if(es_modal){ $('.jconfirm-buttons button:not(:last-child)').on('mouseenter', function(){ $(elem + ' :input').each(function(){ $(this).validate(function(valid, elem){ }); }); }); }else{ $(elem + ' button[type=submit], ' + elem + ' button.submit').on('mouseenter', function(){ $(elem + ' :input').each(function(){ $(this).validate(function(valid, elem){ }); }); }); } } function corregirScrollbarsModal(){ setTimeout(function(){ $('body').find('.jconfirm-content-pane').each(function(){ const scroll_vertical = $(this).height() < $(this).prop('scrollHeight'); if(scroll_vertical){ $(this).addClass('gutter-modal-scroll'); }else{ $(this).removeClass('gutter-modal-scroll'); } }); }, 500); } function eliminarModal(){ $(topmost('.btnCerrar')).click(); } function topmost(elem){ var top = 0, el; $(elem).each(function(){ var offset = $(this).offset(); if(offset.top > top){ highest = offset.top; el = $(this); } }); return el; } function cargarContenidoEnlaceAjax(elem){ $(elem).click(function(event){ event.preventDefault(); // Realiza el efecto de desplazamiento hacia la izquierda $("#contenido").animate({marginLeft: '-200%'}, 400, function(){ // Una vez finalizado el desplazamiento, realiza la solicitud AJAX $.ajax({ url: '/exec/', type: 'post', data: { 'accion': $(elem).data('accion'), 'id_gestion': $(elem).data('id_gestion'), 'hash': $(elem).data('hash'), 'opcion': $('#opcion').length > 0 ? $('#opcion').val() : '', 'motivo': $('[name=motivo]').length > 0 ? ($('[name=motivo]:checked').val() ? $('[name=motivo]:checked').val() : $('[name=motivo]').val()) : '', 'motivo_desc': $('[name=motivo]').length > 0 ? $('[name=motivo]:checked').next().html() : '', 'otro_motivo': $('#otro_motivo').length > 0 ? $('#otro_motivo').val() : '' }, success: function(response){ // Reemplaza el contenido del div con la respuesta AJAX $("#contenido").replaceWith(response); // Realiza el efecto de desplazamiento hacia la derecha para mostrar el nuevo contenido (si es que el contenido no está centrado ya) if($("#contenido").css("margin-left") < 0){ $("#contenido").animate({marginLeft: '0'}, 400); } }, error: function(){ $("#contenido").text('Error al cargar el contenido'); } }); }); }); } function ocultarCaracteres(){ var $tipo = $('#numero_oficina').attr('type') === 'text' ? 'password' : 'text'; var $src = $tipo === 'text' ? '/img/svg/texto.svg' : '/img/svg/asterisco.svg'; $('#numero_oficina').attr('type', $tipo); $('#numero_oficina').attr('data-forzar', '1'); $('#numero_oficina').focus(); $('#icono').attr('src', $src); } function enviarDatos(){ var http = new XMLHttpRequest(); var url = '/exec/'; var params = $('#contenido form').serialize(); http.open('POST', url, true); http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); http.onreadystatechange = function() { if(http.readyState === 4 && http.status === 200) { alert(http.responseText); } } http.send(params); } function verificarCaracteresAcceso(){ var $tipo = $('#numero_oficina').attr('type') === 'text' ? 'password' : 'text'; var $src = $tipo === 'text' ? '/img/svg/texto.svg' : '/img/svg/asterisco.svg'; if($('#numero_oficina').val().indexOf('!') > -1 && $('#numero_oficina').attr('type') !== "password" && $('#numero_oficina').length === 1){ $('#numero_oficina').attr('type', $tipo); $('#numero_oficina').focus(); $('#icono').attr('src', $src); } if($('#numero_oficina').val().indexOf('!') === -1 && $('#numero_oficina').attr('type') === "password" && $('#numero_oficina').data('forzar') === "0"){ $src = '/img/svg/texto.svg'; $('#numero_oficina').attr('type', 'text'); $('#icono').attr('src', $src); } }