/* * Codificación UTF-8 * * FUNCIONES LLAMADAS A OPERACIONES: * buscar( objElemento ) * guardar( objElemento ) * cancelar( objElemento ) * insert( objElemento ) * deleted( objElemento ) * update( objElemento ) * cancelarVS( objElemento ) * okWS() * aceptarVS( objElemento ) * * FUNCIONES LLAMADAS A NEGOCIO: * callControllerJS( objElemento ) * loading( modo, message ) * * FUNCIONES MENSAJES: * showMessage( langCod, type, msg ) * showConfirm( id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO ) * * FUNCIONES CONTROL EVENTOS: * semaforoChange( funcion, objElemento ) * * getUrlParameter(sParam) * * REVIEW: * getRulesFilter(idFilter, claseM, panel) * createTree(idTree, node, multiple, url, claseM, destino, actualizaA, idForm) * select2.defaults(width, allowClear, closeOnSelect, placeholder, containerCssClass, dropdownCssClass) * validateDate(id, fecha, separador, mascara) * showLinkTree(id,linkRama) * popupwindow() */ var gvh = gvh || {}; +function($) { 'use strict'; /********************************************* / * FUNCIONES LLAMADAS A OPERACIONES /*********************************************/ /** * buscar: buscar del panel filtro * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'buscar' * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * -> data-gvhNewWindow * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.buscar = function( objElemento ) { var idForm = objElemento.closest( 'form' ).attr( 'id' ); var panel = objElemento.attr( 'data-gvhPanelOn' ); var destino = objElemento.closest( 'form' ).attr( 'action' ); var claseM = objElemento.attr( 'data-gvhClaseManejadora' ); var id = objElemento.attr( 'id' ); var destinoLength = objElemento.attr( 'data-gvhDestino' ).length; if( destinoLength > 0 ) { destino = objElemento.attr( 'data-gvhDestino' ); } if( objElemento.attr( 'data-gvhConfirm' ) ) { var confirm = objElemento.attr( 'data-gvhConfirm' ); var vConfirm = confirm.split( '___' ); //showConfirm() - PARAMS: id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO gvh.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , panel , claseM ); } else { var idDiv = $( 'div' ).filter(' [data-gvhCWSource=CWFilter] ').attr( 'id' ); if( idDiv != undefined ) { gvh.getRulesFilter($('#'+idDiv)); } gvh.callControllerJS( objElemento ); } } /** * guardar: Enviar a negocio los datos del panel para ser guardados * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'guardar' * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.guardar = function( objElemento ) { gvh.showConsoleMsg('log',' *** gvh_functions.js - gvh.guardar() '); gvh.showConsoleMsg('log',objElemento); var accionActivaP = 'accionActivaP_'+objElemento.closest( 'form' ).attr( 'id' ); var panel = objElemento.attr( 'data-gvhPanelOn' ); var idGuardar = objElemento.attr( 'id' ); var claseManejadora = objElemento.attr( 'data-gvhClaseManejadora' ); //var estadoPanel = $( '#P_'+panel+'[data-gvhClaseManejadora='+claseManejadora+']' ).attr( 'data-gvhestadopanel' ); var destino = objElemento.closest( 'form' ).attr( 'action' ); var destinoLength = objElemento.attr( 'data-gvhDestino' ).length; if( destinoLength > 0 ) { destino = objElemento.attr( 'data-gvhDestino' ); } var fields = gvh.fieldsRequired(objElemento); if( fields != '' ) { gvh.showMessage( 'gvhlang_msj901', 'alert', fields ); return; } // TODO : FALTA data-gvhConfirm con JSON var confirm = objElemento.attr( 'data-gvhConfirm' ); if( (confirm != '') && (confirm != undefined) ) { var vConfirm = confirm.split( '___' ); var destinoNO = objElemento.attr( 'data-gvhConfirmCancel' ); //showConfirm() - PARAMS: id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO gvh.showConfirm( idGuardar , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , panel , claseManejadora , destinoNO ); } else { gvh.callControllerJS( objElemento ); } } /** * cancelar: Cancelar la acción que se haya indicado realizar en el panel * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'guardar' * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * -> data-gvhNewWindow * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.cancelar = function( objElemento ) { let modo = 'R'; let panel = objElemento.attr( 'data-gvhPanelOn' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); gvh.blockExit( true, modo, panel, claseM ); var destino = objElemento.attr( 'data-gvhDestino' ); if( (destino != 'cancelar') && (destino != '') ) { gvh.callControllerJS( objElemento ); } else { objElemento.loading( { message: 'Cancelando...' } ); setTimeout( 'window.top.location.reload()', 100 ); } } /** * insert: Inserción de los datos introducidos en el panel * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'insert' * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhPatronPanel * -> data-gvhActSobre * @access private * @var objElemento: componente que lanza el evento de insertar */ gvh.insert = function( objElemento ) { gvh.showConsoleMsg('log', ' *** gvh_function.js - insert()' ); let patronPanel = objElemento.attr( 'data-gvhPatronPanel' ); let panelOn = objElemento.attr( 'data-gvhPanelOn' ); let destino = objElemento.attr( 'data-gvhDestino' ); let actuaSobre = objElemento.attr( 'data-gvhActSobre' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); if( panelOn != 'fil' && panelOn == actuaSobre ) { gvh.blockExit( false, 'I', panelOn, claseM ); } switch( patronPanel ) { case 'TR': gvh.callControllerJS( objElemento ); break; case 'simple': case 'maestro': case 'detalle': $( 'div[data-gvhpagina=block][data-gvhWindow='+ambito+']' ).hide(); if( (panelOn == 'fil') || ((destino != undefined) && (destino != '')) ) { gvh.callControllerJS( objElemento ); } else { gvh.formOnInsert(objElemento); } break; default: break; } } /** * deleted: Eliminar el registro(s) seleccionado(s) * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'delete' * -> data-gvhClaseManejadora * -> data-gvhPanelOn * @access private * @var objElemento: componente que lanza el evento de eliminar */ gvh.deleted = function( objElemento ) { gvh.showConsoleMsg('log', ' *** gvh_function.js - deleted()' ); let id = objElemento.attr( 'id' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); let panelOn = objElemento.attr( 'data-gvhPanelOn' ); let panelJSON = panelOn.substr( 0, 3 ); let raizJSON = gvh.getRoot( claseM, panelJSON ); if( panelOn != 'fil' ) { gvh.blockExit( false, 'D', panelOn, claseM ); } switch( panelOn ) { case 'lis': case 'lisDetalle': let vSufijos = []; if( $('input:checkbox[id^=checkAll_]').is(':checked') ) { gvh.formOnDelete(objElemento); } else { $( 'input[data-gvhWindow='+ambito+'][id*=check_'+panelOn+']:checked' ).each( function() { let sufijo = $(this).attr( 'id' ).split('check_')[1]; let row = $(this).attr( 'data-gvhRow' ); let indiceJSON = gvh.indexDataJSON( raizJSON, row ); let estado = gvh.getStateReg(raizJSON,indiceJSON,'state'); if( estado == 'nada' ) { vSufijos.push( sufijo ); } } ); if( vSufijos.length > 0 ) { gvh.formOnDelete(objElemento); } else { gvh.showMessage( 'gvhlang_msj16', 'alert' ); } } break; case 'edi': case 'ediDetalle': var sufijo = ''; $( 'div[id*=pag_'+panelOn+'_]' ).each( function() { if( $(this).is( ':visible' ) ) { sufijo = $(this).attr( 'id' ).substring( 3, objElemento.attr('id').length ); } } ); gvh.formOnDelete(objElemento); break; default: break; } } /** * update: Modificar el registro(s) seleccionado(s) * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = 'update' * -> data-gvhClaseManejadora * -> data-gvhPanelOn * @access private * @var objElemento: componente que lanza el evento de update */ gvh.update = function( objElemento ) { gvh.showConsoleMsg('log', ' *** gvh_function.js - update()' ); let id = objElemento.attr('id'); let claseM = objElemento.attr('data-gvhClaseManejadora'); let panelOn = objElemento.attr('data-gvhPanelOn'); let patronPanel = objElemento.attr('data-gvhPatronPanel'); let panelJSON = panelOn.substr(0,3); let raizJSON = datosJSON[claseM][panelJSON]; let actuaSobre = objElemento.attr('data-gvhActSobre'); /* if( panelOn != 'fil' && panelOn == actuaSobre ) { gvh.blockExit( false, 'W', panelOn, claseM ); }*/ switch( panelOn ) { case 'edi': case 'ediDetalle': //var sufijo = panelOn+'_0'; gvh.formOnUpdate(objElemento); break; case 'lis': case 'lisDetalle': if( patronPanel == 'simple' ) // Patrón tabular simple/maestro/detalle { let vSufijos = []; if( $('input:checkbox[data-gvhWindow='+ambito+'][data-gvhFunction=checkAll]').is(':checked') ) { gvh.formOnUpdate(objElemento); } else { $( 'input[data-gvhFunction=checkRow][data-gvhWindow='+ambito+'][data-gvhPanelOn='+panelOn+']:checked' ).each( function() { let gvhWindow = objElemento.attr( 'data-gvhWindow' ); if( ambito == gvhWindow ) { let sufijo = $(this).attr( 'id' ).split('check_')[1]; let row = $(this).attr( 'data-gvhRow' ); let raizJSON = gvh.getRoot( claseM, panelJSON ); let indiceJSON = gvh.indexDataJSON(raizJSON, row ); let estado = gvh.getStateReg(raizJSON,indiceJSON,'state'); if( estado == 'nada' ) { vSufijos.push( row ); } } } ); if( vSufijos.length > 0 ) { gvh.formOnUpdate(objElemento); } else { gvh.showMessage( 'gvhlang_msj16', 'alert' ); } } } else if ( patronPanel == 'TR' ) // Patrón Tabular-Registro { let filaCheck = false; $( 'input[data-gvhFunction=checkRow][data-gvhWindow='+ambito+'][data-gvhPanelOn='+panelOn+']:checked' ).each( function() { if( $(this).is( ':checked' ) ) { filaCheck = true; return false; } } ); if( filaCheck ) { gvh.callControllerJS( objElemento ); } else { gvh.showMessage( 'gvhlang_msj16', 'alert' ); } } else { gvh.showConsoleMsg('error', ' ¡¡Botón tooltip modificar no definido el tipo de panel!! ' ); } break; default: gvh.showConsoleMsg('error', ' ¡¡Botón tooltip modificar no asociado a ningún panel!! ' ); break; } } /** * cancelarVS: Cancelar la acción de la ventana de selección * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = ['cancelarvs'] * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.cancelarVS = function( objElemento ) { let panel = objElemento.attr( 'data-gvhPanelOn' ); if( objElemento.attr('data-gvhConfirm') ) { let confirm = objElemento.attr( 'data-gvhConfirm' ); let vConfirm = confirm.split( '___' ); let destino = objElemento.attr( 'data-gvhDestino' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); let id = objElemento.attr( 'id' ); //showConfirm() - PARAMS: id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO gvh.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , panel , claseM ); } else { dialogWS.modal( 'hide' ); if( dialogIdWM.length <= 0 ) { ambito = 'gvhMain'; } else { ambito = 'gvhModal'; } } } /** * okWS: Aceptar la acción de la ventana de selección * @access private * @var actionOrigen: * @var fila: * @var panel: * @var fieldsSource: * @var fieldsWS: * @var claseMO: */ gvh.okWS = function(objElemento, actionOrigen, fila, panel, fieldsSource, fieldsWS, claseMO) { gvh.showConsoleMsg('log',' *** gvh_Function.js - okWS() '); // DATOS DE LA VENTANA SELECCIÓN // Clase manejadora de ventana selección var claseM_WS = objElemento.attr('data-gvhClaseManejadora'); // Datos JSON de la ventana de selección var raizJSON_WS = gvh.getRoot(claseM_WS,'lis'); var panelJSON = panel.substring(0,3); // DATOS DE LA VENTANA PADRE // Clase manejadora padre var ClaseMPadre = claseMO; gvh.showConsoleMsg('log',claseMO); var raizJSON = gvh.getRoot(claseMO,panelJSON); // Pág activa desde la que se ha invocado la ventana var indiceJSONPadre = 0; var regPadre = 0; if ((panel == 'lis') || (panel == 'lisDetalle')) { regPadre = $('#registroOrigen').val(); var indiceJSONPadre = gvh.indexDataJSON(raizJSON,regPadre); } // Datos JSON de la ventana padre // Estado panel padre, id campo var prefijo = "cam___"; var estado = "updated"; var modoPanelOn = objElemento.attr('data-gvhModoPanelOn'); if ((modoPanelOn == 'I') && (panel != 'fil')) { var prefijo = "ins___"; var estado = "inserted"; regPadre = raizJSON['panel']['pagActive']; }; // Var para marcar el panel como modificado var panelModif = false; var fieldActualiza = []; // Bucle de los campos a actualizar con los valores de la ventana de selección $.each(fieldsSource,function(index,value) { // Campo ventana padre var fSource = fieldsSource[index]; // Campo ventana de selección var fWS = fieldsWS[index]; // Cálculo del indiceJSON: registro seleccionado //var raizJSONWS = gvh.getRoot(claseM_WS,'lis'); var indiceJSONWS = gvh.indexDataJSON(raizJSON_WS,fila); //var indiceJSONWS = gvh.indexDataJSON(claseM_WS,'lis',fila); var newVal = gvh.getValue(raizJSON_WS,fWS,indiceJSONWS); var idSource = ''; // Actualización del objeto JSON de datos if (gvh.getExistField(raizJSON,fSource,indiceJSONPadre)) { gvh.setValue(raizJSON,fSource,indiceJSONPadre,newVal); if (panelJSON == 'fil') { idSource = gvh.getIdField(raizJSON,fSource,indiceJSONPadre); } else { idSource = prefijo+fSource+'___'+panel+'_'+regPadre; } $('#'+idSource+'[data-gvhClaseManejadora='+ClaseMPadre+']').val(newVal); gvh.setStateReg(raizJSON,estado,indiceJSONPadre); if ((panelModif == false) && (panelJSON != 'fil')) { idSource = gvh.getIdField(raizJSON,fSource,indiceJSONPadre); if ($('#'+idSource+'[data-gvhClaseManejadora='+ClaseMPadre+']').attr('readonly')) { panelModif = true; } } var funcion = ''; if ($('button[id='+value+']').attr('id')) { funcion = $('button[id='+value+']').attr('data-gvhFunction'); // Botón tooltip "updateField" } var actualizaA = $('#'+idSource+'[data-gvhClaseManejadora='+ClaseMPadre+']').attr('data-gvhActualizaA'); if (((actualizaA != 'undefined') && (actualizaA != undefined)) || (funcion == 'updateField')) { fieldActualiza.push(idSource); } } else { gvh.showConsoleMsg('error','¡¡¡ No existe el campo '+fSource+' para la clase manejadora '+claseM_WS); } }); if (fieldActualiza.length > 0) { $.each(fieldActualiza,function(index,value) { gvh.updateEvent($('#'+value+'[data-gvhClaseManejadora='+ClaseMPadre+']')); }); } dialogWS.modal('hide'); if (dialogIdWM.length <= 0) ambito = 'gvhMain'; else ambito = 'gvhModal'; } /** * aceptarVS: Aceptar la acción de la ventana de selección * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhFunction = ['cancelarvs'] * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.aceptarVS = function(objElemento ) { gvh.showConsoleMsg('log',' *** gvh_Function.js - aceptarVS() '); gvh.showConsoleMsg('log',objElemento); let panel = objElemento.attr( 'data-gvhPanelOn' ); let panelActua = objElemento.attr( 'data-gvhPanelActua' ); if( objElemento.attr('data-gvhConfirm') ) { let confirm = objElemento.attr( 'data-gvhConfirm' ); let vConfirm = confirm.split( '___' ); let destino = objElemento.attr( 'data-gvhDestino' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); let id = objElemento.attr( 'id' ); //showConfirm() - PARAMS: id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO gvh.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , panel , claseM ); } else { let destino = objElemento.attr( 'data-gvhDestino' ); let fieldsWS = objElemento.attr( 'data-gvhFieldsWS' ).split( ',' ); let fieldsSource = objElemento.attr( 'data-gvhFieldsSource' ).split( ',' ); let action = $( '#actionOrigen' ).val(); let id = $( 'input:radio[name=vsRadio]:checked' ).attr( 'id' ); if( id == undefined ) { $.getJSON( urlLang, function( data ) { let cod = desescapeIGEPjs( data['gvhlang_msj16']['cod'] ); let title = desescapeIGEPjs( data['gvhlang_msj16']['title'] ); let descrip = desescapeIGEPjs( data['gvhlang_msj16']['descr'] ); } ) .done( function() { alertify.suggest( cod, title, descrip ); } ); } else { let fila = id.split('_')[2]; // check_Tabla1_1 let modoPanel = objElemento.attr( 'data-gvhModoPanelOn' ); let claseMOrigen = objElemento.attr( 'data-gvhClaseMOrigen' ); gvh.okWS(objElemento, action,fila,panelActua,fieldsSource,fieldsWS,claseMOrigen); } } }; /********************************** / * FUNCIONES LLAMADAS A NEGOCIO /**********************************/ /** * callControllerJS: Llamada a negocio con los datos del panel * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhClaseManejadora * -> data-gvhDestino * -> data-gvhPanelOn * -> data-gvhConfirm * -> data-gvhNewWindow * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.callControllerJS = function( objElemento ) { gvh.showConsoleMsg('log',' *** gvh_Function.js - callControlerJS()'); let className = objElemento.attr( 'class' ); if( className == 'btnTooltip' ) { return; } let id = objElemento.attr( 'id' ); let claseM = objElemento.attr( 'data-gvhClaseManejadora' ); let panel = objElemento.attr( 'data-gvhPanelOn' ); let objPanel = $('#P_'+panel+'[data-gvhClaseManejadora='+claseM+']'); let destino = objElemento.attr( 'data-gvhDestino' ); let newWindow = objElemento.attr( 'data-gvhNewWindow' ); let confirmacion = objElemento.attr( 'data-gvhConfirm' ); // Averiguar si debemos comprobar los datos del formulario let checkForm = false; let estado = 'R'; const regex = /^.*checkForm=(0|1|true|false).*$/i; let m; if( (m = regex.exec(destino)) !== null ) { checkForm = m[1]; } checkForm = !(checkForm == false); // Obtenemos el estado del panel (=lectura/escritura/inserción/...) estado = $('#'+ambito).attr( 'data-gvhEstadoPanel' ); $( 'div[id^=P_][data-gvhWindow='+ambito+']' ).map( function() { let estadoPanel = $(this).attr( 'data-gvhEstadoPanel' ); if ( (estadoPanel != 'R') || (estado == undefined) ) { estado = estadoPanel; } }); // Comprobamos si el panel ha sido modificado let changed = false; if( objPanel.length > 0 ) { let gvhchanged = objPanel.attr( 'data-gvhchanged' ); if (typeof gvhchanged !== typeof undefined && gvhchanged !== false) { if( gvhchanged == 'true' || gvhchanged == '1' ) { changed = true; } } } //console.log( 'Changed!!! : ' + changed ); if( confirmacion ) { var vConfirm = confirmacion.split( '___' ); //showConfirm() - PARAMS: id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO gvh.showConsoleMsg('log',' ** showConfirm() '); gvh.showConsoleMsg('log',' id => '+id); gvh.showConsoleMsg('log',' codigo => '+vConfirm[0]); gvh.showConsoleMsg('log',' descBreve => '+desescapeIGEPjs( vConfirm[1] )); gvh.showConsoleMsg('log',' text => '+desescapeIGEPjs( vConfirm[2] )); gvh.showConsoleMsg('log',' btnOk => '+desescapeIGEPjs( vConfirm[3] )); gvh.showConsoleMsg('log',' btnCancel => '+desescapeIGEPjs( vConfirm[4] )); gvh.showConsoleMsg('log',' destino => '+destino); gvh.showConsoleMsg('log',' panel => '+panel); gvh.showConsoleMsg('log',' claseM => '+claseM); gvh.showConsoleMsg('log',' *********** '); gvh.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , panel , claseM ); } //else if( estado == 'R' || !changed || !checkForm ) else { objElemento.controllerJS( { id: id , claseM: claseM , panel: panel , destino: destino , newWindow: newWindow , confirm: '' , message: 'cargando' } ); } /*else { console.error( ' ¡¡¡ El panel está en modo activo (W/I) hay que acabar la acción o cancelarla para poder cambiar de panel!!! ' ); gvh.showMessage( 'gvhlang_msjUI', 'alert' ); }*/ } /** * loading: Muestra el cargando * @access private * @var modo: activar o desactivar ['on'|'off'] * @var message: cadena de texto si se quiere particularizar el mensaje "cargando" */ gvh.loading = function( modo, message ) { if( modo != 'on' ) { $( '#load-cover' ).hide(); $( '#load' ).hide(); $( '#load-cover' ).remove(); $( '#load' ).remove(); return; } if( $('#load-cover').length > 0 ) { $( '#load-cover' ).show(); $( '#load' ).show(); return; } var elCover = document.createElement( "div" ); elCover.setAttribute( "id", "load-cover" ); elCover.className = "load-cover"; document.body.appendChild( elCover ); var elLoad = document.createElement( "section" ); elLoad.setAttribute( "id", "load" ); elLoad.className = ""; document.body.appendChild( elLoad ); var contenido = '
'; contenido += ''; if( (message == '') || (message == undefined) ) { message = desescapeIGEPjs( msgLoad ); } else { message = desescapeIGEPjs( message) ; } contenido += '' + message + ''; contenido += '
'; $('#load').html( contenido ); } /*********************** / * FUNCIONES MENSAJES /***********************/ /** * showMessage: Muestra un mensaje con el texto del fichero json que corresponda (esp.json|val.json|eng.json) de igep * @access private * @var langCod: Código del mensaje a mostrar (ej. gvhlang_msjUI) * @var type: tipo de menssaje a mostrar ['alert'|'error'|'suggest'] * @var msg: texto que complementa al mensaje definido en el fichero json */ gvh.showMessage = function( langCod, type, msg ) { gvh.showConsoleMsg('log', ' *** showMessage() -> '+type ); // Mostramos el progreso Pace.restart(); document.body.className = document.body.className; // Forzamos a actualizar la interfaz $.ajax( { url: urlLang , dataType: 'json', async: false , type: 'post' , success: function( data ) { var cod = desescapeIGEPjs( data[langCod]['cod'] ); var title = desescapeIGEPjs( data[langCod]['title'] ); var descrip = desescapeIGEPjs( data[langCod]['descr'] ); if( (msg) && (msg != '') ) { descrip += '
'+msg; } switch( type ) { case 'alert': alertify.alert( cod, title, descrip ); break; case 'error': alertify.error( cod, title, descrip ); break; case 'suggest': alertify.suggest( cod, title, descrip ); break; } }, error: function ( jqXHR, textStatus, errorThrown ) { alert( jqXHR ); } } ); } /** * showConfirm() * FUNCIÓN: mostrar mensaje de confirmación * defaults: id - del botón para el que se van a activar los campos * codigo - código del mensaje (ej. APL-1) * descBreve - descripción breve de la cabecera * text - texto del cuerpo del mensaje * btnOk - texto del botón OK * btnCancel - texto del botón Cancelar */ gvh.showConfirm = function( id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO ) { alertify.set( { labels : { ok : btnOk , cancel : btnCancel } } ); alertify.confirm( codigo, descBreve, text, function( e ) { if( e ) { $(this).controllerJS( { id: id , panel: panel , destino: destino , newWindow: 'false' , confirm: '' , claseM: claseM , message: msgLoad } ); } else { $(this).controllerJS( { id: id , panel: panel , destino: destinoNO , newWindow: 'false' , confirm: '' , claseM: claseM , message: msgLoad } ); } } , 'Default Value' ); } /**************************************** / * FUNCIONES CONTROL SECUENCIA EVENTOS /****************************************/ /** * semaforoChange: Método que activa eventos y los vuelve a activar para evitar la propagación de eventos en el dom * @access private * @var objElemento: elemento que lanza el cambio y es necesaria evitar la propagación */ gvh.semaforoChange = function( funcion, objElemento ) { objElemento.off( 'change', $.fn.funcion ); gvh.changeField( objElemento ); objElemento.on( 'change', $.fn.funcion ); } gvh.getUrlParameter = function(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; /*********** / * REVIEW /***********/ /** * getRulesFilter() * FUNCIÓN: Parsea los parámetros introducidos en el filtro avanzado en formato JSON y SQL para guardarlos en datosJSON * @access private * @var filter: objeto filtro */ gvh.getRulesFilter = function(filter) { var claseM = filter.attr('data-gvhClaseManejadora'); var panel = filter.attr('data-gvhPanelOn'); var idFilteer = filter.attr('id'); //JSON resultado = filter.queryBuilder('getRules', { get_flags: true, skip_empty: true } ); gvh.showConsoleMsg('log',resultado); gvh.showConsoleMsg('log',resultado['rules']); resultParseJSON = JSON.stringify(resultado, undefined, 2); gvh.showConsoleMsg('log','parseJSON: '+resultParseJSON); // SQL parseSQL = ''; if (resultado['rules'].length > 0) { resultParseSQL = filter.queryBuilder('getSQL', false, false); parseSQL = resultParseSQL.sql + (resultParseSQL.params ? '\n\n' + JSON.stringify(resultParseSQL.params, undefined, 2) : ''); gvh.showConsoleMsg('log','parseSQL: '+parseSQL); } panelJSON = filter.attr('data-gvhPanelJSON'); raizJSON = datosJSON[claseM][panelJSON]; if (panelJSON == 'fil') { raizJSON['data'][0]['gvhJS_fields'][idFilter]['rules'] = resultParseJSON; raizJSON['data'][0]['gvhJS_fields'][idFilter]['rulesSQL'] = parseSQL; } gvh.showConsoleMsg('log',raizJSON); } /** * createTree() * FUNCIÓN: Crea un árbol jquery con el plugin jstree * @access private * @var objTree: objeto árbol * @var node: * @var multiple: selección múltiples valores * @var url * */ gvh.createTree = function(objTree, node, multiple, url) { var claseM = objTree.attr('data-gvhClaseManejadora'); var panel = objTree.attr('data-gvhPanelOn'); var actualizaA = objTree.attr('data-gvhActualizaA'); var idTree = objTree.attr('id'); var idForm = objTree.closest('form').attr('id'); if (multiple == "true") var multiple = true; else var multiple = false; // Comprobar si existe la variable datosJSON var raizJSON = datosJSON[claseM][panel]; var data = []; if (raizJSON['gvhJSON'] == 'false') { var data = JSON.stringify($("#"+idForm).serialize()); var url = url; } else { var data = datosJSON; var url = url+"&gvhcache=true&claseManejadora="+claseM+"&gvhpanel="+panel; } gvh.showConsoleMsg('log',data); $('#'+idTree).jstree({ "types" : { "default" : { "icon" : "glyphicon glyphicon-flash" }, "root" : { "icon" : "fa fa-chevron-down" }, "users" : { "icon" : "fa fa-users" }, "volley" : { "icon" : "fa fa-anchor" }, "ciclismo" : { "icon" : "fa fa-bicycle" }, "child" : { "icon" : "fa fa-child" } }, "core" : { "multiple": multiple, "checkbox": true, "ajax": true, "worker": true, "data": { "url": url, //"url": "phrame.php?action=TreeSelector__treeAjax", "data": function(data) { gvh.showConsoleMsg('log','data '+data); //json = node; return data;//{ "id" : node.id, "nodo": node }; }, "success": function (node) { gvh.showConsoleMsg('log','success '+node); }, /*'data': function(node) { gvh.showConsoleMsg('log','getJSONData '+node); json = node; return { "id" : node.id, "nodo": node }; }*/ "search": { "case_insensitive": true, "ajax" : { "url": "phrame.php?action=TreeSelector__treeAjax&value=search", 'dataType': 'json', 'type': 'POST', "data": function (node) { gvh.showConsoleMsg('log','search '+node.id) return { "id": node.id }; } } }, }, "themes": { 'name': 'proton', 'responsive': true }, }, /*"changed": function (e, data) { gvh.showConsoleMsg('log',"Nodo seleccionado:"); selectedNodes = data.selected; if (selectedNodes.length > 0) { $.each(selectedNodes, function( index, value ) { gvh.showConsoleMsg('log',value.id+' '+value.text); }); } else { gvh.showConsoleMsg('log','no hay seleccionados'); } }, "search": { "case_insensitive": true, "ajax" : { "url": "phrame.php?action=TreeSelector__treeAjax&value=search", 'dataType': 'json', 'type': 'POST', "data": function (node) { gvh.showConsoleMsg('log','search '+node.id) return { "id": node.id }; } } },*/ "plugins" : [ "types", "wholerow", "search", "themes", "html_data", "checkbox", "sort", "ui" ] }); } /** * validateDate() * FUNCIӓN: Comprobar que la fecha sea correcta * defaults: fecha - fecha introducida * separador */ gvh.validateDate = function(id,fecha,separador = '/',mascara='dd/mm/yyyy') { separador = separador; if (mascara.indexOf('/') != -1) separador = '/'; if (mascara.indexOf('-') != -1) separador = '-'; if ((mascara == 'dd/mm/yyyy') || (mascara == 'dd-mm-yyyy')) var dateDDMMYYYRegex = /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](18|19|20)\d\d$/; if ((mascara == 'mm/dd/yyyy') || (mascara == 'mm-dd-yyyy')) var dateDDMMYYYRegex = /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](18|19|20)\d\d$/; if (fecha != '') { correcto = fecha.match(dateDDMMYYYRegex); if (correcto) { fecha = fecha.split(separador); dia = fecha[0]; mes = fecha[1]; anio = fecha[2]; var error = 0; if ((mes==4 || mes==6 || mes==9 || mes==11) && dia==31) { correcto = false; } if (mes == 2) { // bisiesto var bisiesto = (anio % 4 == 0 && (anio % 100 != 0 || anio % 400 == 0)); if (dia > 29 || (dia==29 && !bisiesto)) { correcto = false; } } } if (!correcto) { //$('#'+id).showMessage('gvhlang_msj900','error'); gvh.showMessage('gvhlang_msj900','error'); $('#'+id).val(''); } return correcto; } }; /** * showLinkTree() * FUNCIӓN: mostrar la opción del árbol * */ var cont = 0; gvh.showLinkTree = function(id,linkRama) { gvh.showConsoleMsg('log',' ** gvh_funcionesPaneles.js - showLinkTree() '); var linkRama = linkRama; if (linkRama != '') { gvh.showConsoleMsg('log','Llamada ajax para mostrar el panel '+linkRama); Pace.restart(); document.body.className = document.body.className; // Forzamos a actualizar la interfaz var rspPhrame; $.ajax({ //data: data, type: "POST", cache: false, url: linkRama, beforeSend: function() { gvh.showConsoleMsg('log',' ... Beforesend ...'); gvh.loading('on'); }, success: function(response) { gvh.showConsoleMsg('log',' ... Success: '+response); rspPhrame = $.parseJSON(response); window.location.href = decodeURIComponent(rspPhrame.path); }, error:function( jqXHR, textStatus, errorThrown ) { gvh.showConsoleMsg('log',' ... # ERROR showLinkTree'); }, complete:function( jqXHR, textStatus, errorThrown ) { gvh.showConsoleMsg('log',' ... # COMPLETE showLinkTree'); gvh.loading('off'); } }) } }; /* * popupWindow() * FUNCIÓN: Abrir una ventana emergente como respuesta a evento sobre el DOM */ gvh.popupWindow = function(instanceSettings) { gvh.showConsoleMsg('log',' REVIEW: popupWindow() - gvh_funciones.js'); gvh.showConsoleMsg('log',instanceSettings); var defaultSettings = { centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left height:500, // sets the height in pixels of the window. left:0, // left position when the window appears. location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}. menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}. resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable. scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}. status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}. width:500, // sets the width in pixels of the window. windowName:null, // name of window set from the name attribute of the element that invokes the click windowURL:null, // url used for the popup top:0, // top position when the window appears. toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}. }; gvh.loading( 'off' ); //settings = $.extend({}, defaultSettings, instanceSettings || {}); var height = instanceSettings.height; var width = instanceSettings.width; if (instanceSettings.height == '') var height = 500; if (instanceSettings.width == '') var width = 500; var windowFeatures = 'height=' + height + ',width=' + width + ',toolbar=' + defaultSettings.toolbar + ',scrollbars=' + defaultSettings.scrollbars + ',status=' + defaultSettings.status + ',resizable=' + defaultSettings.resizable + ',location=' + defaultSettings.location + ',menuBar=' + defaultSettings.menubar; var centeredY,centeredX; if(instanceSettings.centerBrowser) { if ($.browser.msie) {//hacked together for IE browsers centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (height/2))); centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (width/2))); } else { centeredY = window.screenY + (((window.outerHeight/2) - (height/2))); centeredX = window.screenX + (((window.outerWidth/2) - (width/2))); } window.open(instanceSettings.windowURL, instanceSettings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus(); } else if(instanceSettings.centerScreen) { centeredY = (screen.height - height)/2; centeredX = (screen.width - width)/2; window.open(instanceSettings.windowURL, instanceSettings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus(); } else { window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + defaultSettings.left +',top=' + defaultSettings.top).focus(); } return false; }; } (jQuery);