/* * eventCloseModal() * FUNCIÓN: submit del formulario. 3 opciones: Nueva ventana / Con mensaje de confirmación / submit directo * defaults: id - del botón para el que se van a activar los campos * prefijo - si los campos se activan para inserción o modificación ('ins'/'cam') * css - estilo que se le aplicará al campo * panel - panel donde se encuentran los campos */ $.fn.eventCloseModal = function(options) { var defaults = $.extend({ url: '', claseM: '', panel: '' },options); console.log('eventCloseModal() '+defaults.url); $.ajax({ data: datosJSON[defaults.claseM][defaults.panel], type: "POST", datatype: "json", url: defaults.url, beforeSend: function() { console.log('BEFORESEND eventCloseModal...'); $(this).loading({ modo: 'on', message: msgLoad }); }, success: function(rsp) { console.log('eventCloseModal '+rsp); }, complete: function( jqXHR, textStatus, errorThrown ) { console.log('COMPLETE eventCloseModal... '); }, error: function ( jqXHR, textStatus, errorThrown ) { console.log('ERROR: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); } }); } /* * compareViewsPath() * FUNCIÓN: compara dos url para comprobar si el valor del views es el mismo */ $.fn.compareViewsPath = function(options) { var defaults = $.extend({ pathActual: '', path: '' },options); console.log('compareViewsPath() '); viewsActual = defaults.pathActual.split('?view=')[1]; viewsNew = defaults.path.split('?view=')[1]; claseMActual = viewsActual.split('&')[0]; claseMNew = viewsNew.split('&')[0]; console.log('origen --> '+claseMActual); console.log('destino --> '+claseMNew); if (claseMNew != claseMActual) return false; else return true; } /* * controllerJS() * FUNCIÓN: submit del formulario. 3 opciones: Nueva ventana / Con mensaje de confirmación / submit directo * defaults: id - del botón para el que se van a activar los campos * prefijo - si los campos se activan para inserción o modificación ('ins'/'cam') * css - estilo que se le aplicará al campo * panel - panel donde se encuentran los campos */ $.fn.controllerJS = function(options) { var defaults = $.extend({ id: '', panel: '', destino: '', newWindow: 'false', confirm: '', claseM: '', message: '' },options); console.log('controllerJS()'); formulario = "F_"+defaults.panel; panelJSON = $('#'+defaults.id).attr('data-gvhPanelJSON'); // Comprobamos que llega la url destino para componer la url completa y el conjunto de datos if (defaults.destino != '') { if ((defaults.id == 'close') || ((defaults.claseM == '') && (defaults.panel == ''))) { urlPhrame = defaults.destino+"&gvhcache=true"; datos = datosJSON; } else { datos = datosJSON[defaults.claseM][panelJSON]; // Enviamos solamente los datos del panel correspondiente urlPhrame = defaults.destino+"&gvhcache=true&claseManejadora="+defaults.claseM+"&gvhpanel="+panelJSON; if ($('#WS').length > 0) { claseMOrigen = $('#'+defaults.id).attr('data-gvhclasemorigen'); urlPhrame += urlPhrame+'&claseManejadoraOrigen='+claseMOrigen; } } console.log('1) llamar a phrame: '+urlPhrame); console.log(datosJSON); var scriptPostLoad = ''; $.ajax({ //data: datosJSON[defaults.claseM][panelJSON], data: datos, type: "POST", datatype: "json", url: urlPhrame, beforeSend: function() { console.log('BEFORESEND...'); $(this).loading({ message: defaults.message, modo: 'on' }); }, success: function(rspPhrame) { console.log('SUCCESS... '+rspPhrame); rspPhrameJSON = $.parseJSON(rspPhrame); // Acción que vamos a realizar ['NoAction' | 'reload' | ...] action = rspPhrameJSON.context.action; targetType = rspPhrameJSON.context.targetType; switch(targetType) { case 'self': console.log(' * targetType: '+targetType+' - DESTINO EN LA MISMA PÁGINA'); switch(action) { // EJECUTA JAVASCRIPT EN LA PÁGINA case 'NoAction': console.log(' * action: '+action+' - EJECUTAMOS JAVASCRIPT EN LA PÁGINA'); eval(rspPhrameJSON.context.script); break; // RELOAD DE LA PÁGINA case 'reload': console.log(' * action: '+action+' - RELOAD DE LA PÁGINA'); window.location.reload(); break; // LLAMADA A NEGOCIO (ajax) QUE NOS DEVOLVERÁ LA PÁGINA (views) location.href => views case 'salto': path = decodeURIComponent(rspPhrameJSON.path); console.log(' * action: '+action+' - SALTO. LLAMADA A NEGOCIO '+path); $.ajax({ data: null, // Mandamos a null los datos porque se va a lanzar una claseManejadora nueva en la ventana. type: "POST", datatype: "json", url: path, beforeSend: function() { }, success: function(rspTpl) { rspTplJSON = $.parseJSON(rspTpl); path = rspTplJSON.path; console.log(' * action: '+action+' - location.href DEL VIEWS DEL SALTO '+path); endLoading = false; window.location.href = decodeURIComponent(path); }, error:function( jqXHR, textStatus, errorThrown ) { console.log('ERROR: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, always:function( jqXHR, textStatus, errorThrown ) { console.log('ALWAYS: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, fail:function( jqXHR, textStatus, errorThrown ) { console.log('FAIL: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, complete: function( jqXHR, textStatus, errorThrown ) { console.log('3 COMPLETE: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); } }) break; default: newWindow = defaults.newWindow; if (newWindow == 'false') // NO ABRIMOS VENTANA EMERGENTE { pathActual = window.location.href; path = rspPhrameJSON.path; var loadGVHMain = $(this).compareViewsPath({ pathActual: pathActual, path: decodeURIComponent(path) }); if (loadGVHMain) { console.log(' * CARGA EN LA CAPA gvhMain DE '+path); endLoading = true; // CARGAMOS EN LA CAPA gvhMain LA PÁGINA $('#gvhMain').load(decodeURIComponent(path)); } else { // LOAD DE LA PÁGINA (views) QUE NOS VIENE location.href console.log(' * action: '+action+' - LOAD DEL VIEWS QUE NOS LLEGA "location.href"'); endLoading = false; window.location.href = decodeURIComponent(path); } } else { // LA PÁGINA SE ABRE EN UNA VENTANA NUEVA path = rspPhrameJSON.path; console.log(' * CARGA EN NUEVA VENTANA (popup) DE '+path); $(this).popupWindow({ windowURL: path, centerScreen: 1, height: 600, width: 800, windowName:'help' }); } break; } break; // EL DESTINO ES UNA VENTANA MODAL case 'JDialog': target = rspPhrameJSON.context.targetType; scriptPostLoad = rspPhrameJSON.context.script; idVentana = rspPhrameJSON.context.idVentana; console.log(' * targetType: '+targetType+' - DESTINO EN VENTANA MODAL '+idVentana); ventanaModal = $('#'+idVentana); switch(action) { // CERRAMOS VENTANA MODAL case 'gvHidraCloseJDialog': console.log(' * action: '+action+' - CERRAR LA VENTANA MODAL'); if ((idVentana != null) && (idVentana != undefined)) { ventanaModal = $('#'+idVentana); if (ventanaModal.length > 0) { dialogWM.dialog('close'); } } break; // ABRIMOS VENTANA MODAL case 'gvHidraOpenJDialog': url = decodeURIComponent(rspPhrameJSON.path); console.log(' * action: '+action+' - ABRIR VENTANA MODAL '+url); if ((url == null) || (url == '') || (url == undefined)) { $(this).showMessage('gvhlang_ErrorProgramacion','error'); return false; } if (ventanaModal.length > 0) { console.log(' -> Ventana modal ya existe'); $('#'+idVentana).load(url); if (rspPhrameJSON.context.script != '') { eval(rspPhrameJSON.context.script); } } else { console.log(' -> Ventana modal NO EXISTE'); WSwidth = 1000; WSheight = 'auto'; if (rspPhrameJSON.context.width != '') { WSwidth = rspPhrameJSON.context.width; } if (rspPhrameJSON.context.height != '') { WSheight = rspPhrameJSON.context.height; } $.ajax({ data: null, // Mandamos a null los datos porque se va a lanzar una claseManejadora nueva en la ventana. type: "POST", datatype: "json", url: url, beforeSend: function() {}, success: function(rspTpl) { rspTplJSON = $.parseJSON(rspTpl); dialogWM = $('
') .dialog({ draggable: true, resizable: true, show: 'blind', hide: 'blind', autoOpen: false, modal: true, width: WSwidth, height: WSheight, title: aplTitle, open: function() { $(this).closest(".ui-dialog") .find(".ui-dialog-titlebar-close") .removeClass("ui-dialog-titlebar-close") .addClass("dialogButtonClose") .addClass("ui-dialog-titlebar-close") .html(""); }, close: function (event, ui) { //$('#'+idVentana).dialog('destroy').remove(); // REVIEW VERO: globalWM dialogWM.dialog('destroy').remove(); returnPath = rspPhrameJSON.context.returnPath; if ((returnPath != null) && (returnPath != undefined)) { returnPath = returnPath+"&gvhcache=true"; $(this).eventCloseModal({ idVentana: idVentana, url: returnPath, claseM: defaults.claseM, panel: panelJSON }); } } }); path = rspTplJSON.path; console.log(' -> TPL a cargar en la ventana modal: ');console.log(path); $('#'+idVentana).load(decodeURIComponent(path)); dialogWM.dialog('open'); }, error:function( jqXHR, textStatus, errorThrown ) { console.log('ERROR: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, always:function( jqXHR, textStatus, errorThrown ) { console.log('ALWAYS: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, fail:function( jqXHR, textStatus, errorThrown ) { console.log('FAIL: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, complete: function( jqXHR, textStatus, errorThrown ) { console.log('2 COMPLETE '+idVentana); console.log('2 COMPLETE: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); } }) } break; default: console.log('gvh_controller.js: '+targetType+' "action" no definido'); break; } break; default: console.log('gvh_controller.js: targetType no definido'); break; } }, error:function( jqXHR, textStatus, errorThrown ) { console.log('ERROR 1: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, always:function( jqXHR, textStatus, errorThrown ) { console.log('ALWAYS 1: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, fail:function( jqXHR, textStatus, errorThrown ) { console.log('FAIL 1: '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); }, complete:function ( jqXHR, textStatus, errorThrown ) { console.log('1 COMPLETE: '+defaults.id+': '+textStatus+' - status: '+jqXHR.status+' | '+errorThrown); } }) .done(function(resultado){ console.log('DONE '); }); }; eval(scriptPostLoad); }; /* $.drawProgress = function(options) { var defaults = $.extend({ mensaje: '' }) console.log('drawProgress... '+defaults.mensaje); // Capa de bloqueo var bloqueo = $('
', { 'class' : 'load-cover', 'id' : 'load-cover' }); $("body").append(bloqueo); // Contenedor barra de progreso var contenedor = $('
', { 'class' : 'contenedorLoad', 'id' : 'contenedorLoad' }); $("body").prepend(contenedor); // Barra de progreso var barraProgress = $('
', { 'class' : 'barraProgress', 'id' : 'barraProgress' }); $("#contenedorLoad").append(barraProgress); var progressLoad = $('
', { 'id' : 'progressLoad', 'class' : 'progressLoad' }); $('#barraProgress').append(progressLoad); var txtLoad = $('
', { 'id' : 'textoLoad', 'class' : 'txtLoad' }); $('#progressLoad').append(txtLoad); txtMsg = '

'+defaults.mensaje+'

'; $('#barraProgress').append(txtMsg); }*/ /* * loading() * FUNCIÓN: Muestra la imagen de cargando * defaults: message - texto (ej. "loading...") */ $.fn.loadingAJAX = function(options) { var defaults = $.extend({ message: '', // Var global con el msj de cargando modo: 'on' },options); if (defaults.modo == 'on') { $.ajax({ url: urlLang, dataType: 'json', async: false, type: 'post', success: function(data) { ////// claves = ['buscar','guardar','cancelar','volver','cargar']; // DIBUJO // Capa de bloqueo var bloqueo = $('
', { 'class' : 'load-cover', 'id' : 'load-cover' }); $("body").append(bloqueo); // Contenedor barra de progreso var contenedor = $('
', { 'class' : 'contenedorLoad', 'id' : 'contenedorLoad' }); $("body").prepend(contenedor); // Barra de progreso var barraProgress = $('
', { 'class' : 'barraProgress', 'id' : 'barraProgress' }); $("#contenedorLoad").append(barraProgress); var progressLoad = $('
', { 'id' : 'progressLoad', 'class' : 'progressLoad' }); $('#barraProgress').append(progressLoad); var txtLoad = $('
', { 'id' : 'textoLoad', 'class' : 'txtLoad' }); $('#progressLoad').append(txtLoad); $('#barraProgress').append('hola'); /* if ($.inArray(defaults.message,claves) == -1) { base = desescapeIGEPjs(data['gvhlang_load']); txtBase = ''+base+': '; txtLoad = ''+defaults.message+''; } else { base = desescapeIGEPjs(data['gvhlang_loadMsg'][defaults.message]); txtBase = ''+base+''; txtLoad = '/'; } txtLoad = 'estoy cargando'; txtMsg = '

'+txtBase+' '+txtLoad+'

'; $('#barraProgress').append(txtMsg);*/ /*$.drawProgress({ mensaje: defaults.message });*/ }, error: function ( jqXHR, textStatus, errorThrown ) { alert(jqXHR); }, }); /* if ($.inArray(defaults.message,claves) == -1) { txt = ""+msgLoad+""; if (defaults.message != '') txt = txt+": "+defaults.message+""; txtMsg = '

'+txt+'

'; $('#barraProgress').append(txtMsg); } else { $.ajax({ url: urlLang, dataType: 'json', async: false, type: 'post', success: function(data) { txt = desescapeIGEPjs(data['gvhlang_loadMsg'][defaults.message]); txtLoad = desescapeIGEPjs(""+txt+""); $.drawProgress({ mensaje: defaults.message }); }, error: function ( jqXHR, textStatus, errorThrown ) { alert(jqXHR); }, }); }*/ } else { $('#contenedorLoad').hide(); $('#load-cover').hide(); $('#barraProgress').hide(); $('#contenedorLoad').remove(); $('#load-cover').remove(); $('#barraProgress').remove(); } }; /* * loading() * FUNCIÓN: Muestra la imagen de cargando * defaults: message - texto (ej. "loading...") */ $.fn.loading = function(options) { var defaults = $.extend({ message: '', // Var global con el msj de cargando modo: 'on' },options); if (defaults.modo == 'on') { // Capa de bloqueo var bloqueo = $('
', { 'class' : 'load-cover', 'id' : 'load-cover' }); $("body").append(bloqueo); // Contenedor barra de progreso var contenedor = $('
', { 'class' : 'contenedorLoad', 'id' : 'contenedorLoad' }); $("body").prepend(contenedor); // Barra de progreso var barraProgress = $('
', { 'class' : 'barraProgress', 'id' : 'barraProgress' }); $("#contenedorLoad").append(barraProgress); var progressLoad = $('
', { 'id' : 'progressLoad', 'class' : 'progressLoad' }); $('#barraProgress').append(progressLoad); var txtLoad = $('
', { 'id' : 'textoLoad', 'class' : 'txtLoad' }); $('#progressLoad').append(txtLoad); switch(defaults.message) { case 'buscar': txt = 'Buscando...'; message = ""+txt+""; break; case 'guardar': txt = 'Guardando...'; message = ""+txt+""; break; case 'cancelar': txt = 'Cancelando...'; message = ""+txt+""; break; case 'volver': txt = 'Volver...'; message = ""+txt+""; break; case 'cargar': txt = 'Cargando...'; message = ""+txt+""; break; default: message = ""+msgLoad+""; if (defaults.message != '') message = message+": "+defaults.message+""; break; } txt = '

'+message+'

'; $('#barraProgress').append(txt); } else { $('#contenedorLoad').hide(); $('#load-cover').hide(); $('#barraProgress').hide(); $('#contenedorLoad').remove(); $('#load-cover').remove(); $('#barraProgress').remove(); } }; /* $(document).ajaxComplete(function(jqXHR, textStatus, errorThrown ) { console.log(' ** ajaxComplete() '); console.log(jqXHR); console.log(errorThrown); console.log('***********'); }); $(document).ajaxSend(function(jqXHR, textStatus, errorThrown ) { console.log(' ** ajaxSend() '); console.log(jqXHR); console.log(errorThrown); console.log('***********'); }); $(document).ajaxSuccess(function(jqXHR, textStatus, errorThrown ) { console.log(' ** ajaxSuccess() '); console.log(jqXHR); console.log(errorThrown); console.log('***********'); });*/ $(document).ajaxStop(function(jqXHR, textStatus, errorThrown ) { //console.log(' ** ajaxStop() '); if (endLoading) { $(document).loading({ modo: 'off' }); } });