/* * Codificación UTF-8 * * FUNCIONES: * semaforoChange( funcion, objElemento ) * blockExit( exit, modo, panel ) * showMessage( langCod, type, msg ) * showConfirm( id, codigo, descBreve, text, btnOk, btnCancel, destino, panel, claseM, destinoNO ) * iconUpdate( modo, panel ) * callControllerJS( objElemento ) * buscar( objElemento ) * guardar( objElemento ) * cancelar( objElemento ) * cancelarVS( objElemento ) * aceptarVS( objElemento ) * loading( modo, message ) * changeJSONField( objElemento ) */ var gvh = gvh || {}; +function($) { 'use strict'; /** * indexDataJSON: Calcula el índice del array datosJSON sobre el que queremos trabajar. * Útil para calcularlo cuando se trabaja con paneles lis. * @access private * @var claseManejadora: clase del panel sobre el que queremos calcular el índice * @var panel: tipo de panel sobre el que se está trabajando ['lis','lisDetalle'] * @var row: fila seleccionada del panel */ gvh.semaforoChange = function( funcion, objElemento ) { objElemento.off( 'change', $.fn.funcion ); gvh.changeJSONField( objElemento ); objElemento.on( 'change', $.fn.funcion ); } /** * blockExit: Bloquea la salida del panel mientras no se ejecute o cancele la acción que se haya indicado (insertar/modificar) * @access private * @var exit: booleano * @var panel: tipo de panel sobre el que se está trabajando ['edi'|'ediDetalle'|'lis'|'lisDetalle'] * @var modo: ['I' (inserción) | 'W' (modificación) | 'R' (lectura)] */ gvh.blockExit = function( exit, modo, panel, patron ) { console.log( ' *** blockExit() -> '+panel+' modo '+modo ); $( '#home' ).attr( 'data-gvhExit', exit ); $( '#close' ).attr( 'data-gvhExit', exit ); $( 'div[id=P_'+panel+'][data-gvhWindow='+ambito+']' ).attr( 'data-gvhestadopanel', modo ); if( panel != 'fil' ) { gvh.iconUpdate( modo, panel ); } } /** * 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 ) { console.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' ); } /** * iconUpdate() * FUNCIӓN: Mostrar icono barra inferior modificación * @access private * @var modo: ['R'|'I'|'W'] * @var panel: panel sobre el que se está trabajando */ gvh.iconUpdate = function( modo, panel ) { if( (panel == 'fil') || (panel == 'P_fil') ) { return; } var imgMod = panel + '_imgModificado'; var imgModificado = $( '#' + imgMod ); if( !imgModificado.length ) { console.log('¡¡¡Error icono modificación "'+imgMod+'"!!!'); return } if( modo == 'R' ) { imgModificado.hide(); } else { imgModificado.show(); } } /** * 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 ) { var className = objElemento.attr( 'class' ); if( className == 'btnTooltip' ) { return; } if( objElemento.attr('data-gvhConfirm') ) { var confirm = objElemento.attr( 'data-gvhConfirm' ); var vConfirm = confirm.split( '___' ); var destino = objElemento.attr( 'data-gvhDestino' ); var claseM = objElemento.attr( 'data-gvhClaseManejadora' ); var id = objElemento.attr( 'id' ); var panel = objElemento.attr( 'data-gvhPanelOn' ); this.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , claseM , panel ); } else { objElemento.controllerJS( { id: objElemento.attr( 'id' ) , panel: objElemento.attr( 'data-gvhPanelOn' ) , destino: objElemento.attr( 'data-gvhDestino' ) , newWindow: objElemento.attr( 'data-gvhNewWindow' ) , confirm: '' , claseM: objElemento.attr( 'data-gvhClaseManejadora' ) , message: 'cargando' } ); } } /** * 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( '___' ); this.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , claseM , panel ); } else { var idDiv = $( 'div' ).filter(' [data-gvhCWSource=CWFilter] ').attr( 'id' ); if( idDiv != undefined ) { $( '#' + idDiv ).getRulesFilter( { idFilter: idDiv , claseM: claseM , panel: panel } ); } this.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 ) { var accionActivaP = 'accionActivaP_'+objElemento.closest( 'form' ).attr( 'id' ); var modo = $( '#' + accionActivaP ).val(); var panel = objElemento.attr( 'data-gvhPanelOn' ); var idGuardar = objElemento.attr( 'id' ); var claseManejadora = objElemento.attr( 'data-gvhClaseManejadora' ); var estadoPanel = $( '#P_'+panel ).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 = objElemento.fieldsRequired( { id : idGuardar , panel : panel , estadoPanel : estadoPanel , claseM : claseManejadora } ); if( fields != '' ) { this.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' ); this.showConfirm( idGuardar , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , claseManejadora , panel , destinoNO ); } else { this.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 ) { var panel = objElemento.attr( 'data-gvhPanelOn' ); //var formulario = objElemento.closest( 'form' ); this.blockExit( true, 'R', panel ); var imgModificado = $( '#' + panel + '_imgModificado' ); if( imgModificado.length ) { imgModificado.hide(); } var destino = objElemento.attr( 'data-gvhDestino' ); if( (destino != 'cancelar') && (destino != '') ) { this.callControllerJS( objElemento ); } else { objElemento.loading( { message: 'Cancelando...' } ); setTimeout( 'window.top.location.reload()', 100 ); } } /** * 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 ) { var panel = objElemento.attr( 'data-gvhPanelOn' ); //var formulario = objElemento.closest('form'); if( objElemento.attr('data-gvhConfirm') ) { var confirm = objElemento.attr( 'data-gvhConfirm' ); var vConfirm = confirm.split( '___' ); var destino = objElemento.attr( 'data-gvhDestino' ); var claseM = objElemento.attr( 'data-gvhClaseManejadora' ); var id = objElemento.attr( 'id' ); this.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , claseM , panel ); } else { dialogWS.modal( 'hide' ); //dialogWS.dialog("destroy").remove(); 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 ) { var panel = objElemento.attr( 'data-gvhPanelOn' ); //var formulario = objElemento.closest('form'); if( objElemento.attr('data-gvhConfirm') ) { var confirm = objElemento.attr( 'data-gvhConfirm' ); var vConfirm = confirm.split( '___' ); var destino = objElemento.attr( 'data-gvhDestino' ); var claseM = objElemento.attr( 'data-gvhClaseManejadora' ); var id = objElemento.attr( 'id' ); this.showConfirm( id , vConfirm[0] , desescapeIGEPjs( vConfirm[1] ) , desescapeIGEPjs( vConfirm[2] ) , desescapeIGEPjs( vConfirm[3] ) , desescapeIGEPjs( vConfirm[4] ) , destino , claseM , panel ); } else { var destino = objElemento.attr( 'data-gvhDestino' ); var fieldsWS = objElemento.attr( 'data-gvhFieldsWS' ).split( ',' ); var fieldsSource = objElemento.attr( 'data-gvhFieldsSource' ).split( ',' ); var action = $( '#actionOrigen' ).val(); var id = $( 'input:radio[name=vsRadio]:checked' ).attr( 'id' ); if( id == undefined ) { $.getJSON( urlLang, function( data ) { var cod = desescapeIGEPjs( data['gvhlang_msj16']['cod'] ); var title = desescapeIGEPjs( data['gvhlang_msj16']['title'] ); var descrip = desescapeIGEPjs( data['gvhlang_msj16']['descr'] ); } ) .done( function() { alertify.suggest( cod, title, descrip ); } ); } else { var fila = id.split('_')[2]; // check_Tabla1_1 var modoPanel = objElemento.attr( 'data-gvhModoPanelOn' ); var claseMOrigen = objElemento.attr( 'data-gvhClaseMOrigen' ); objElemento.okWS( { actionOrigen: action , fila: fila , panel: panel , fieldsSource: fieldsSource , fieldsWS: fieldsWS , modoPanel: modoPanel , claseMO: claseMOrigen } ); } } } /** * 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 ); } /** * changeJSONField: Actualización del datosJSON con el cambio producido en el campo * El elemento necesita tener los siguientes atributos si se crea de forma directa en html: * -> data-gvhClaseManejadora * -> data-gvhPanelOn * @access private * @var objElemento: componente botón que se ha pulsado */ gvh.changeJSONField = function( objElemento ) { var fieldAmbito = objElemento.attr( 'data-gvhWindow' ); if( fieldAmbito == ambito ) { var claseM = objElemento.attr( 'data-gvhClaseManejadora' ); var panel = objElemento.attr( 'data-gvhPanelOn' ); var plugin = objElemento.attr( 'data-gvhCWSource' ); var panelJSON = panel.substring( 0, 3 ); var idCampo = objElemento.attr( 'id' ); console.log( 'changeJSONField() -> '+idCampo ); var campoJSON = idCampo; if( panelJSON != 'fil' ) { campoJSON = idCampo.split('___')[1]; if( plugin == 'cwlistaradio' ) { var name = objElemento.attr( 'name' ); campoJSON = name.split('___')[1]; } } var raizJSON = gvh.getRoot( claseM, panel ); var plugin = ''; var external = objElemento.attr( 'data-gvhExternal' ); if( external == 'true' ) // Tratamiento de campos external { console.log( 'campo external '+campoJSON ); if( raizJSON['external'][campoJSON] != undefined ) { plugin = raizJSON['external'][campoJSON]['CWPlugin']; } } else { var regJSON = 0; // Según el panel se calcula indice del datosJSON switch( panelJSON ) { case 'fil': regJSON = 0; break; case 'lis': var row = idCampo.split('___')[2].split('_')[1]; regJSON = gvh.indexDataJSON( raizJSON, row ); //regJSON = this.indexDataJSON( claseM, panel, row ) var sufijo = panel+'_'+row; break; case 'edi': var pagActual = datosJSON[claseM][panelJSON]['panel']['pagActive']; regJSON = pagActual; break; default: regJSON = 0; break; } if (raizJSON['data'][regJSON]['gvhJS_fields'][campoJSON] != undefined) { var plugin = raizJSON['data'][regJSON]['gvhJS_fields'][campoJSON]['CWPlugin']; var hidden = raizJSON['data'][regJSON]['gvhJS_fields'][campoJSON]['hidden']; raizJSON['data'][regJSON]['gvhJS_selected'] = "selected"; raizJSON['dataPerform']['data'][regJSON]['gvhJS_selected'] = 'selected'; gvh.setStateReg( raizJSON, 'selected', regJSON, 'add' ); var objPanel = $('div[id=P_'+panel+'][data-gvhWindow='+ambito+']'); var estado = $('div[id=P_'+panel+'][data-gvhWindow='+ambito+']').attr( 'data-gvhestadopanel' ); switch( estado ) { case 'W': estado = 'modificada'; gvh.setStateReg( raizJSON, 'updated', regJSON, 'add' ); break; case 'D': estado = 'borrada'; gvh.setStateReg( raizJSON, 'deleted', regJSON, 'add' ); break; case 'I': estado = 'insertada'; gvh.setStateReg( raizJSON , 'inserted', regJSON, 'add' ); break; default: estado = 'nada'; break; } raizJSON['data'][regJSON]['gvhJS_state'] = estado; raizJSON['dataPerform']['data'][regJSON]['gvhJS_state'] = estado; if( hidden == 1 ) // Campo oculto { plugin = 'Hidden'; } } } if( plugin != '' ) { var valorCampo = ''; switch( plugin ) { case 'cwcampotexto': case 'cwareatexto': case 'cwlista': valorCampo = objElemento.val(); break; case 'cwimagen': valorCampo = objElemento.attr( 'src' ); break; case 'cwlistaradio': valorCampo = $('input:radio[name='+name+'][data-gvhWindow='+ambito+']:checked').val(); //valorCampo = $('input:radio[id='+idCampo+'][data-gvhWindow='+ambito+']:checked').val(); break; case 'cwcheckbox': var campoPanel = idCampo.split('___')[1]+'___'+idCampo.split('___')[2]; valorCampo = $('#cam___'+campoPanel).val(); break; case 'Hidden': valorCampo = raizJSON['data'][0]['gvhJS_fields'][campoJSON]['value']; break; default: break; } if( external == 'true' ) { raizJSON['external'][idCampo]['value'] = valorCampo; raizJSON['dataPerform']['external'][idCampo]['value'] = valorCampo; } else { raizJSON['data'][regJSON]['gvhJS_fields'][campoJSON]['value'] = valorCampo; raizJSON['dataPerform']['data'][regJSON]['gvhJS_fields'][campoJSON]['value'] = valorCampo; } var actualizaA = objElemento.attr( 'data-gvhActualizaA' ); if( (actualizaA != '') && (actualizaA != undefined) ) { console.log('changeJSONField() - actualizaA'); var formulario = objElemento.closest( 'form' ); objElemento.updateEvent( { id: idCampo , actualizaA: actualizaA , panel: panel , claseM: claseM , formulario: formulario } ); } if( panel != 'fil' ) { this.blockExit( false, $('#P_'+panel).attr('data-gvhEstadoPanel'), panel ); } console.log( raizJSON ); } } } } (jQuery);