/* ***************************************** * FUNCIONES PARA BOTONES ****************************************** */ (function($){ /* * msgConfirm() * FUNCIÓN: mostrar mensaje de confirmación * PARAMS: 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 */ $.fn.showConfirm = function(options) { var defaults = $.extend({ id: '', codigo: '', descBreve: '-', text: '-', btnOk: 'Ok', btnCancel: 'Cancelar', destino: '', panel: '', claseM: '' },options); alertify.set({ labels : { ok : defaults.btnOk, cancel : defaults.btnCancel } }); alertify.confirm(defaults.codigo,defaults.descBreve,defaults.text, function (e) { if (e) { $(this).loading(msgLoad); if (defaults.panel != 'fil') { $(this).formSendJSON({ id: defaults.id, destino: defaults.destino, panelDestino: defaults.panel, claseM: defaults.claseM }) } else { if (defaults.destino != '') { $('#'+defaults.id).closest('form').prop("action", defaults.destino); } $('#'+defaults.id).closest('form').prop("target", "oculto"); $('#'+defaults.id).closest('form').submit(); } } }, 'Default Value'); }; })(jQuery); /********************************************************************************************************************************************** * * * EVENTOS DESDE EL DOM * * * ***********************************************************************************************************************************************/ /* *********************************************************************************************************************** * BOTÓN BUSCAR ************************************************************************************************************************ */ $('button[data-gvhFunction=buscar]').on({ click: function() { if ($(this).attr('data-gvhConfirm')) { var confirm = $(this).attr('data-gvhConfirm'); //$datos = confirm.split('/'); $datos = confirm.split('___'); $(this).showConfirm({ id: $(this).attr('id'), codigo: $datos[0], descBreve: desescapeIGEPjs($datos[1]), text: desescapeIGEPjs($datos[2]), btnOk: desescapeIGEPjs($datos[3]), btnCancel: desescapeIGEPjs($datos[4]), destino: $(this).attr('data-gvhDestino'), claseM: $(this).attr('data-gvhClaseManejadora') }) } else if (($(this).attr('data-gvhDestino').length) > 0) { $(this).loading(); $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), target: 'oculto' }); } else { $(this).loading(); $(this).closest('form').prop("target", "oculto"); $(this).closest('form').submit(); } } }) /* *********************************************************************************************************************** * BOTÓN GUARDAR ************************************************************************************************************************ */ $('button[data-gvhFunction=guardar]').on({ click: function() { accionActivaP = 'accionActivaP_'+$(this).closest('form').attr('id'); modo = $('#'+accionActivaP).val(); panel = $(this).attr('data-gvhPanelOn'); estadoPanel = $('#P_'+panel).attr('data-gvhestadopanel'); // comprobar solamente los de las filas a insertar fields = $(this).fieldsRequired({ id : $(this).attr('id'), panel : panel, estadoPanel : estadoPanel }); if (fields != '') { $(this).showMessage('gvhlang_msj901','alert',fields); } else { // FALTA data-gvhDestino con JSON /*if (($(this).attr('data-gvhDestino').length) > 0) { $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), target: 'oculto' }) } else { */ // FALTA data-gvhConfirm con JSON if ($(this).attr('data-gvhConfirm')) { var confirm = $(this).attr('data-gvhConfirm'); //$datos = confirm.split('/'); $datos = confirm.split('___'); $(this).showConfirm({ id: $(this).attr('id'), codigo: $datos[0], descBreve: desescapeIGEPjs($datos[1]), text: desescapeIGEPjs($datos[2]), btnOk: desescapeIGEPjs($datos[3]), btnCancel: desescapeIGEPjs($datos[4]), destino: $(this).attr('data-gvhDestino'), claseM: $(this).attr('data-gvhClaseManejadora') }) } else { panelJSON = panel; if (panel == 'lisDetalle') panelJSON = 'lis'; else if (panel == 'ediDetalle') panelJSON = 'edi'; if (datosJSON[$(this).attr('data-gvhClaseManejadora')][panelJSON]['gvhJSON'] == 'false') { $(this).loading(); $(this).closest('form').prop("target", "oculto"); //Si tiene accion especifica la cargamos (este caso ocurre cuando tenemos acciones particulares pero queremos botones guardar-cancelar, que se ocultan) $actionEspecifica = $(this).attr('data-gvhDestino'); if($actionEspecifica) { $(this).closest('form').prop("action", $actionEspecifica); } $(this).closest('form').submit(); } else { //console.log( datosJSON.toSource()); claseM = $(this).attr('data-gvhClaseManejadora'); action = $(this).closest('form').attr('action'); console.log('gvh_boton.js - guardar'); console.log(JSON.stringify(datosJSON)); $.ajax({ data: datosJSON, type: "POST", datatype: "json", url: action+"&gvhcache=true&claseManejadora="+claseM+"&gvhpanel="+panelJSON, beforeSend: function() { $(this).loading(); }, success: function(response) { window.location.href = decodeURIComponent(jQuery.parseJSON(response)); }, fail: function() { alert('fail'); }, complete: function() { $('div[id=loading]').hide(); } }) } } //} } } }); /* *********************************************************************************************************************** * BOTÓN CANCELAR ************************************************************************************************************************ */ $('button[data-gvhFunction=cancelar]').on({ click: function() { var panel = $(this).attr('data-gvhPanelOn'); var formulario = $(this).closest('form'); // Cambiamos el estado de bloqueo de salida del panel $('div[id=P_'+panel+']').attr('data-gvhestadopanel','R'); $('#capa_menuFalso').hide(); $('#capa_menuReal').show(); modificado = panel+'_imgModificado'; $('#'+modificado).hide(); var destino = $(this).attr('data-gvhDestino'); if (destino == 'oculto') { $oculto = $('iframe[id*=oculto]'); if ($oculto.attr('src').indexOf('?') == -1) { src = $oculto.attr('src') +'?cancelado'; } else { src = $oculto.attr('src')+'&cancelado'; } $(this).loading(); $oculto.attr('src',src); $oculto.submit(); setTimeout('window.top.location.reload()', 220); } else { $(this).loading(); $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), claseM: $(this).attr('data-gvhClaseManejadora') }) } } }); /* *********************************************************************************************************************** * BOTÓN VOLVER ************************************************************************************************************************ */ $('button[data-gvhFunction=volver]').on({ click: function() { $(this).loading(); $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), claseM: $(this).attr('data-gvhClaseManejadora'), target: 'oculto' }) } }); /* *********************************************************************************************************************** * BOTÓN SALTAR ************************************************************************************************************************ */ $('button[data-gvhFunction=saltar]').on({ click: function() { $(this).loading(); $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), claseM: $(this).attr('data-gvhClaseManejadora'), target: 'oculto' }) } }); /* *********************************************************************************************************************** * BOTÓN LISTAR ************************************************************************************************************************ */ $('button[data-gvhFunction=listar]').on({ click: function() { $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), claseM: $(this).attr('data-gvhClaseManejadora'), target: 'oculto' }) } }); /* *********************************************************************************************************************** * BOTÓN PARTICULAR ************************************************************************************************************************ */ $('button[data-gvhFunction=particular]').not('[class=btnToolTip]').on({ click: function() { /* if ($(this).attr('data-gvhConfirm')) { var confirm = $(this).attr('data-gvhConfirm'); //$datos = confirm.split('/'); $datos = confirm.split('___'); $(this).showConfirm({ id: $(this).attr('id'), codigo: $datos[0], descBreve: desescapeIGEPjs($datos[1]), text: desescapeIGEPjs($datos[2]), btnOk: desescapeIGEPjs($datos[3]), btnCancel: desescapeIGEPjs($datos[4]), destino: $(this).attr('data-gvhDestino'), claseM: $(this).attr('data-gvhClaseManejadora') }) } else {*/ //$(this).loading(); $(this).formActionSubmit({ id: $(this).attr('id'), panel: $(this).attr('data-gvhPanelOn'), destino: $(this).attr('data-gvhDestino'), newWindow: $(this).attr('data-gvhNewWindow'), confirm: $(this).attr('data-gvhConfirm'), claseM: $(this).attr('data-gvhClaseManejadora'), target: 'oculto' }) //} } });