/*
* 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 = '