/* * Codificación UTF-8 */ /* FUNCIONES: * - openWS(destino, campo, formOrigen, panelActua, claseManejadora, modoPanelOrigen) * - okWS(actionOrigen, fila, panel, fieldsSource, fieldsWS, claseMO) * - openModal(url, paramsSource, width, height, resizable, scroll, strictJS) * - closeModal(id) */ (function($) { /* * openWS() * FUNCIӓN: abrir ventana de selección */ $.fn.openWS = function(options) { var defaults = $.extend({ destino: '', campo: '', formOrigen: '', panelActua: '', claseManejadora: '', modoPanelOrigen: 'W', message: msgLoad },options); console.log('openWS() '); console.log(datosJSON); ambito = 'gvhModal'; panelJSON = defaults.panelActua; if (defaults.panelActua == 'lisDetalle') panelJSON = 'lis'; else if (defaults.panelActua == 'ediDetalle') panelJSON = 'edi'; data = JSON.stringify($("#"+defaults.idFormOrigen).serialize()); actionOrigen = $(defaults.formOrigen).attr('action'); targetOrigen = $(defaults.formOrigen).attr('target'); idForm = $(defaults.formOrigen).attr('id'); modoPanelOrigen = defaults.modoPanelOrigen; actionNueva = defaults.destino + "&nomForm="+idForm+ "&nomCampo="+defaults.campo+ "&panelActua="+defaults.panelActua+ "&actionOrigen="+actionOrigen+ "&modoPanelOrigen="+modoPanelOrigen+ "&gvhcache=true&gvhpanel="+panelJSON; $.ajax({ data: datosJSON, type: "POST", datatype: "json", cache: false, url: actionNueva, beforeSend: function() { $(this).loading({ modo: 'on', message: defaults.message }); }, success: function(rspTpl) { console.log(' # SUCCESS openWS(): '+rspTpl); rspTplJSON = $.parseJSON(rspTpl); urlTpl = decodeURIComponent(rspTplJSON.path); idWS = "WS_"+defaults.claseManejadora; idWS = "WS"; if ($('#'+idWS).length > 0) { if (rspTplJSON.context.action == 'gvHidraCloseJDialog') { // REVIEW VERO: globalWS globalWS.dialog('destroy').remove(); } else { console.log('La ventana modal ya existe'); $('#'+idWS).load(urlTpl); $(this).loading({ modo: 'off', message: defaults.message }); } } else { dialogWS = $('
') .dialog({ draggable: true, resizable: true, show: 'blind', hide: 'blind', remove: 'blind', autoOpen: false, modal: true, width: rspTplJSON.context.width, height: rspTplJSON.context.height, 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) { $(this).dialog('destroy').remove(); } }); $('#'+idWS).load(urlTpl); dialogWS.dialog('open'); }; }, complete:function( jqXHR, textStatus, errorThrown ) { } }) } $.fn.okWS = function(options) { var defaults = $.extend({ actionOrigen: '', fila: '', panel: '', fieldsSource: '', fieldsWS: '', claseMO: '' },options); console.log('okWS()'); // DATOS DE LA VENTANA SELECCIÓN // Clase manejadora de ventana selección claseM_WS = $(this).attr('data-gvhClaseManejadora'); // Datos JSON de la ventana de selección raizJSON_WS = datosJSON[claseM_WS]['lis']; console.log(' ** Objeto JSON de WS: ');console.log(raizJSON_WS); // DATOS DE LA VENTANA PADRE // Clase manejadora padre ClaseMPadre = defaults.claseMO; // Pág activa desde la que se ha invocado la ventana regPadre = 0; if (defaults.panel != 'fil') regPadre = $('#registroOrigen').val(); // Panel de la ventana padre panelJSON = defaults.panel; if (defaults.panel == 'lisDetalle') panelJSON = 'lis'; else if (defaults.panel == 'ediDetalle') panelJSON = 'edi'; // Datos JSON de la ventana padre raizJSON = datosJSON[ClaseMPadre][panelJSON]; // Estado panel padre, id campo var prefijo = "cam___"; var estado = "modificada"; modoPanelOn = $(this).attr('data-gvhModoPanelOn'); if ((modoPanelOn == 'I') && (defaults.panel != 'fil')) { var prefijo = "ins___"; var estado = "insertada"; regPadre = raizJSON['panel']['pagActive']; }; // Var para marcar el panel como modificado panelModif = false; fieldActualiza = []; // Bucle de los campos a actualizar con los valores de la ventana de selección $.each(defaults.fieldsSource,function(index,value) { // Campo ventana padre fSource = defaults.fieldsSource[index]; // Campo ventana de selección fWS = defaults.fieldsWS[index]; // Cálculo del indiceJSON: registro seleccionado indiceJSON = $(this).indexDataJSON({ claseManejadora: claseM_WS, panel: 'lis', row: defaults.fila }); newVal = raizJSON_WS['data'][indiceJSON]['gvhJS_fields'][fWS]['value']; // Actualización del objeto JSON de datos raizJSON['data'][regPadre]['gvhJS_fields'][fSource]['value'] = newVal; idSource = raizJSON['data'][regPadre]['gvhJS_fields'][fSource]['id']; $('#'+idSource).val(newVal); raizJSON['data'][regPadre]['gvhJS_state'] = estado; if ((panelModif == false) && (panelJSON != 'fil')) { idSource = raizJSON['data'][regPadre]['gvhJS_fields'][fSource]['id']; if ($('#'+idSource).attr('readonly')) { // El campo está deshabilitado por lo que hay que lanzar el icono de modificación $('#'+idSource).iconUpdate({ id: idSource, panel: defaults.panel }); panelModif = true; } } funcion = ''; if ($('button[id='+value+']').attr('id')) { funcion = $('button[id='+value+']').attr('data-gvhFunction'); // Botón tooltip "updateField" } actualizaA = $('#'+idSource).attr('data-gvhActualizaA'); if (((actualizaA != 'undefined') && (actualizaA != undefined)) || (funcion == 'updateField')) { fieldActualiza.push(idSource); } }); if (fieldActualiza.length > 0) { $.each(fieldActualiza,function(index,value) { actualizaA = $('#'+value).attr('data-gvhActualizaA'); $('#'+value).updateEvent({ id: value, actualizaA: actualizaA, panel: defaults.panel, claseM: ClaseMPadre, formulario: $('#'+value).closest('form') },options); }); } dialogWS.dialog("destroy").remove(); } /* * openModal() * FUNCIӓN: abrir ventana de selección */ $.fn.openModal = function(options) { var defaults = $.extend({ url: '', paramsSource: '', width: '', height: '', resizable: 'yes', scroll: 'yes', strictJS: 'true' },options); // cálculo de la posición de la ventana heightPosition = screen.height*0.6; widthPosition = screen.width*0.9; LeftPosition = (screen.width) ? (screen.width-widthPosition)/2 : 0; TopPosition = (screen.height) ? (screen.height-heightPosition)/2 : 0; //Cambiamos los settings para vindow.open settings = 'top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable='+defaults.resizable+',width='+defaults.width+',height='+defaults.height; settings = settings+',menubar=no,toolbar=no,location=no'; action = defaults.paramsSource.returnPath; console.log('openModal() - action: '+action); $.ajax({ data: datosJSON, type: "POST", datatype: "json", url: action,//+"&gvhcache=true&gvhpanel="+panelJSON, beforeSend: function() { console.log('beforeSend'); }, success: function(response) { console.log('success'); var dialogWM = $('
') .html(response) .dialog({ autoOpen: false, modal: true, minHeight: 'auto', minWidth: 'auto', title: "Ventana modal" }); dialogWM.dialog('open'); }, fail: function() { console.log('fail'); }, complete:function( jqXHR, textStatus, errorThrown ) { console.log('complete'); } }) }; /* * closeModal() * FUNCIÓN: Indicará si un objeto JSON es vacío o no */ $.fn.closeModal = function(options) { var defaults = $.extend({ id: '' },options); if ($('#'+defaults.id).length > 0) { // REVIEW VERO: globalWM ambito = 'gvhWindow'; globalWM.dialog('destroy').remove(); } } /********************************** REVISAR SI SE UTILIZAN *************************************/ /* * FUNCIÓN: Abrir una ventana flotante */ $.openWindow = function(options) { var defaults = $.extend({ windowURL: 'igep/blanco.htm', w: '700', h: '500', nameWindow: 'nWindow' },options); console.log(' REVIEW: openWindow() - gvh_funciones.js'); LeftPosition = (screen.width) ? (screen.width-defaults.w)/2 : 0; TopPosition = (screen.height) ? (screen.height-defaults.h)/2 : 0; settings = 'top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+defaults.w+',height='+defaults.h; //Si firefox o Mozilla eliminamos todas las barras, la hacemos modal,dependiente y que flote sobre el resto if (navigator.appCodeName =='Mozilla') settings = settings+',directories=no,personalbar=no,minimizable=no,alwaysRaised=yes,modal=yes,dependent=yes'; win = window.open(defaults.windowURL,defaults.nameWindow,settings); win.focus(); } /* * popupWindow() * FUNCIÓN: Abrir una ventana emergente como respuesta a evento sobre el DOM */ $.fn.popupWindow = function(instanceSettings) { console.log(' REVIEW: popupWindow() - gvh_funciones.js'); $.fn.popupWindow.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)}. }; $(this).loading({ modo: 'off' }); settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {}); var windowFeatures = 'height=' + settings.height + ',width=' + settings.width + ',toolbar=' + settings.toolbar + ',scrollbars=' + settings.scrollbars + ',status=' + settings.status + ',resizable=' + settings.resizable + ',location=' + settings.location + ',menuBar=' + settings.menubar; //alert(settings.windowURL); settings.windowName = this.name || settings.windowName; settings.windowURL = this.href || settings.windowURL; var centeredY,centeredX; if(settings.centerBrowser) { if ($.browser.msie) {//hacked together for IE browsers centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2))); centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2))); } else { centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2))); centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2))); } window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus(); } else if(settings.centerScreen) { centeredY = (screen.height - settings.height)/2; centeredX = (screen.width - settings.width)/2; window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus(); } else { window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus(); } return false; }; })(jQuery);