/* * Codificación UTF-8 * Eventos asociados a los campos de la pantalla * Eventos del menú de pantalla entrada */ var gvh = gvh || {}; +function($){ $(".gvhModal").on('load', function () { alert('The modal is fully shown gvh_comprobar.'); }); /* *********************************************************************************************************************** * EVENTOS ASOCIADOS A LOS CAMBIOS EN CUALQUIER CAMPO */ // RADIO $('#gvhPage').off('click.radio').on( 'click.radio', 'input[type=radio][data-gvhCWSource=cwlistaradio]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); gvh.semaphoreEnqueue ( { id: 'click.radio' , callback: function() { gvh.changeField ($this); } } ); }); // CAMPO DE TEXTO $('#gvhPage').off('change.cwcampotexto').on( 'change.cwcampotexto', 'input[type=text][data-gvhCWSource=cwcampotexto]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'change.cwcampotexto' , callback: function() { gvh.changeField ($this); } } ); } ); // autocomplete $('#gvhPage').off('keypress.campotexto').on( 'keypress.campotexto', 'input[type=text][data-gvhFuncion=autocomplete][data-gvhCWSource=cwcampotexto]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'keypress.cwcampotexto' , callback: function() { var idCampo = $this.attr('id'); var claseM = $this.closest('[data-gvhClaseManejadora]').attr('data-gvhClaseManejadora'); var path = "phrame.php?action=gvHautocomplete&field="+idCampo+"&claseManejadora="+claseM; gvh.showConsoleMsg('log',path); $this.autocomplete( { source: path , minLength: $this.attr('data-gvhMinLength') } ); } } ); }); // TEXTAREA $('#gvhPage').off('change.textarea').on( 'change.textarea', 'textarea', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'change.textarea' , callback: function() { gvh.changeField ($this); } } ); }); // SELECT $('#gvhPage').off('change.cwlista').on( 'change.cwlista', "select[data-gvhCWSource=cwlista]", function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'change.cwlista' , callback: function() { gvh.changeField ($this); } } ); }); $('#gvhPage').off('change.cwlista_select2').on( 'change.cwlista_select2', "[data-gvhCWSource=cwlista_select2]", function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'change.cwlista_select2' , callback: function() { gvh.changeField ($this); } } ); }); // ÁREA DE TEXTO ENRIQUECIDO $('#gvhPage').off('focusout.jqte_editor').on( 'focusout.jqte_editor', '.jqte_editor', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'focusout.jqte_editor' , callback: function() { var id = $this.attr('id'); var idTxtArea = id.split('editor_')[1]; var objElemento = $('#'+idTxtArea); gvh.changeField (objElemento); } } ); }); $('.jqte_editor').on("paste", function(e) { e.preventDefault(); var text = e.originalEvent.clipboardData.getData('text/plain'); document.execCommand("insertText", false, text); }); /* *********************************************************************************************************************** * EVENTOS ASOCIADOS A LAS OPCIONES DE MENÚ DE LA PANTALLA PRINCIPAL */ $('#gvhPage').off('click.gvhLinkMenu').on( 'click.gvhLinkMenu', 'a[data-gvhLinkMenu=true] , div.item > a', function(e) { e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.gvhLinkMenu' , callback: function() { var text = $this.attr('title'); if (text.length == 0) { text = $this.attr('data-original-title'); } //gvh.loading('on',text); } } ); }); /* *********************************************************************************************************************** * EVENTOS ASOCIADOS A LOS TAB N-DETALLES */ $('#gvhPage').off('click.nDetalles').on( 'click.nDetalles', 'a[data-gvhFunction=nDetalles]', function(e) { e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.nDetalles' , callback: function() { // Comprobamos si algún panel tiene cambios pendientes. var changed = false; var gvhchanged = $( '[data-gvhchanged=true]' ); if (gvhchanged.length > 0) { changed = true; } // Si hay cambios pendientes, cancelamos y alertamos al usuario. if (changed) { e.preventDefault(); gvh.showMessage( 'gvhlang_msjUI', 'alert' ); return; } gvh.callControllerJS ($this); } } ); } ); /* *********************************************************************************************************************** * EVENTOS ASOCIADO ETIQUETA URL */ $('#gvhPage').off('click.gvhLabel_url').on( 'click.gvhLabel_url', 'a[data-gvhLabel=url]', function(e) { e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.gvhLabel_url' , callback: function() { if ($this.attr('data-gvhNewWindow')) { var id = $this.attr('id'); url = $this.attr('data-gvhDestino'); var http = url.indexOf("http"); var ftp = url.indexOf("ftp"); if ((url != '') && (url.indexOf("http") == -1) && (url.indexOf("ftp") == -1)) { url = "http://"+url; } if (((url != '') && ((url.indexOf("http") > -1) || (url.indexOf("ftp") > -1))) && ($this.attr('disabled') != 'disabled')) { gvh.callControllerJS($this); } } else { return ($this.attr('disabled')) ? false : true; } } } ); }); $('#gvhPage').off('click.checkRow').on( 'click.checkRow', 'input[data-gvhFunction=checkRow]', function(e) { e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.checkRow' , callback: function() { panel = $this.attr ('data-gvhPanelOn'); var claseM = $this.closest ('[data-gvhClaseManejadora]').attr ('data-gvhClaseManejadora'); id = $this.attr ('id'); row = id.split('_')[2]; json = false; if ($this.attr('data-gvhTipoPanel') == 'maestro') { gvh.checkUnique ($this.attr('id'), row, claseM, $this.attr('data-gvhPanelOn'), ''); gvh.callControllerJS ($this); } else { checked = 'false'; if ($this.is(':checked')) checked = 'selected'; gvh.checkRow (id, row, checked, panel, $this.attr('data-gvhCheck'), claseM); } } } ); }); $('#gvhPage').off('click.cwcheckbox').on( 'click.cwcheckbox', 'input[type=checkbox][data-gvhCWSource=cwcheckbox]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.cwcheckbox' , callback: function() { var claseM = $this.closest ('[data-gvhClaseManejadora]').attr ('data-gvhClaseManejadora'); if (claseM != '') { var panelJSON = $this.attr ('data-gvhPanelJSON'); if (panelJSON != '') { gvh.changeField ($this); } else { console.error ('¡¡¡ checkbox no tiene atributo data-gvhPanelJSON !!!'); } } else { console.error ('¡¡¡ checkbox no tiene atributo data-gvhClaseManejadora !!!'); } } } ); }); /************************************************************************************************************************ * BOTÓN TOOLTIP TREE SELECTOR *************************************************************************************************************************/ /* * BOTÓN TOOLTIP TREE SELECTOR * */ //REVIEW: VERO Eliminar cuando el nuevo árbol esté acabado $('#gvhPage').off('click.gvhTreeSelector_false').on( 'click.gvhTreeSelector_false', 'button[data-gvhFunction=gvhTreeSelector][data-gvhTreeAjax=false]', function(e) { gvh.showConsoleMsg('log','gvh_tree.js - button gvhTreeSelector ajax false'); var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.gvhTreeSelector_false' , callback: function() { var panel = $this.attr('data-gvhPanelOn'); var estado = $('div[id=P_'+panel+']').attr('data-gvhestadopanel'); var idPanel = 'P_'+panel; var claseM = $this.closest('[data-gvhClaseManejadora]').attr('data-gvhClaseManejadora'); var multiple = false; if ($this.attr('data-gvhMultiple') == "true") { multiple = true; } var idForm = $this.closest('form').attr('id'); var campoDestino = $this.attr('data-gvhActualizaA'); var iterActual = $this.attr('data-gvhIterActual'); var sufijo = panel+'_'+iterActual; if (panel == 'fil') { var campoDestinoValue = campoDestino; var campoDestinoID = 'tree_'+campoDestinoValue; } else { if (estado == 'I') { var campoDestinoValue = 'ins___'+campoDestino+'___'+sufijo; var campoDestinoID = 'ins___tree_'+campoDestino+'___'+sufijo; } else { var campoDestinoValue = 'cam___'+campoDestino+'___'+sufijo; var campoDestinoID = 'cam___tree_'+campoDestino+'___'+sufijo; } } var id = $this.attr('id'); var vId = id.split('_'); // Comprobar si existe la variable gvh.datosJSON var raizJSON = gvh.datosJSON[claseM][panel]; var data = []; var destino = $this.attr('data-gvhDestino'); if (raizJSON['gvhJSON'] == 'false') { var data = JSON.stringify($("#"+idForm).serialize()); var url = "phrame.php?action="+claseM+"__"+destino; } else { var data = gvh.datosJSON; var url = "phrame.php?action="+claseM+"__"+destino+"&gvhcache=true&claseManejadora="+claseM+"&gvhpanel="+panel; } gvh.showConsoleMsg('log',data); var json = null; $.ajax({ 'async': false, 'type': "POST", 'url': url, 'data': data, 'dataType': "json", 'fail': function(json) { gvh.showConsoleMsg('log','fail'); }, 'success': function(json) { gvh.showConsoleMsg('log',json); if ($this.isEmptyJSON(json)) { gvh.showConsoleMsg('log',"NO DATA!"); gvh.showMessage('gvhlang_NoData','alert'); $('#'+vId[1]).filter('[data-gvhTree=true]').treeview('remove'); } else { $("#treeDialog_"+vId[1]).dialog("open"); //gvh.showConsoleMsg('log','abrir el árbol '+vId[1]); $('#'+vId[1]).filter('[data-gvhTree=true]').treeview( { data: json, multiSelect: multiple, /*multiple*/ showCheckBox: true, showTags: true, highlightSelected: true, levels: 1, // árbol cerrado //nodeIcon: 'glyphicon glyphicon-user', onNodeUnselected: function (event, node) { $(':input[id='+campoDestinoValue+']').filter('[data-gvhpanelon='+panel+']').map(function() { $('input[id='+campoDestinoValue+']').val(''); $('input[id='+campoDestinoID+']').val(''); }); $("select[id="+campoDestinoValue+"] option[value="+node.id+"]").remove(); }, onNodeSelected: function(event, node) { $(':input[id='+campoDestinoValue+']').filter('[data-gvhpanelon='+panel+']').map(function() { $('input[id='+campoDestinoValue+']').val(node.text); $('input[id='+campoDestinoID+']').val(node.id); }); $('select[id='+campoDestinoValue+']').filter('[data-gvhpanelon='+panel+']') .append($("") .attr("value", node.id ) .attr("selected", true ) .text(node.text)); gvh.showConsoleMsg('log','vincular'); var idTree = $this.attr('id'); //$this.attr('data-gvhIDTree'); //panel = $('#'+idTree).attr('data-gvhPanelOn'); var idPanel = 'P_'+panel; var panelJSON = panel; if (panel == 'lisDetalle') panelJSON = 'lis'; else if (panel == 'ediDetalle') panelJSON = 'edi'; var campoDestino = $('#'+idTree).attr('data-gvhActualizaA'); var iterActual = $('#'+idTree).attr('data-gvhIterActual'); var sufijo = panel+'_'+iterActual; if (panel == 'fil') { var campoDestinoValue = campoDestino; var campoDestinoID = 'tree_'+campoDestinoValue; } else { var estadoPanel = $('#'+idPanel).attr('data-gvhestadopanel'); gvh.showConsoleMsg('log','estadoPanel: '+estadoPanel); if (estadoPanel == 'I') { var campoDestinoValue = 'ins___'+campoDestino+'___'+sufijo; var campoDestinoID = 'ins___tree_'+campoDestino+'___'+sufijo; } else { var campoDestinoValue = 'cam___'+campoDestino+'___'+sufijo; var campoDestinoID = 'cam___tree_'+campoDestino+'___'+sufijo; } } var actualizaA = $('#'+campoDestinoValue).attr('data-gvhActualizaA'); var formulario = $('#'+campoDestinoValue).closest('form'); var allText = []; if ($('#'+campoDestinoValue).attr('data-gvhActualizaA')) { gvh.showConsoleMsg('log',' PARAMS: '); gvh.showConsoleMsg('log',' id - '+campoDestinoValue); gvh.showConsoleMsg('log',' actualizaA - '+actualizaA); gvh.showConsoleMsg('log',' panel - '+panel); gvh.showConsoleMsg('log',' claseM - '+claseM); gvh.showConsoleMsg('log',' formulario - '+formulario); gvh.updateEvent($('#'+campoDestinoValue)); } }, search: function(event,node) { $('#input-check-node').val(), { ignoreCase: false, exactMatch: false } }, }); } } }); } } ); }); //REVIEW: VERO Eliminar cuando el nuevo árbol esté acabado $('#gvhPage').off('click.gvhTreeSelector_true').on( 'click.gvhTreeSelector_true', 'button[data-gvhFunction=gvhTreeSelector][data-gvhTreeAjax=true]', function(e) { var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.gvhTreeSelector_true' , callback: function() { var panel = $this.attr('data-gvhPanelOn'); var idPanel = 'P_'+panel; var claseM = $this.closest('[data-gvhClaseManejadora]').attr('data-gvhClaseManejadora'); var destino = $this.attr('data-gvhDestino'); var url = "phrame.php?action="+claseM+"__"+destino; var campoDestino = $this.attr('data-gvhActualizaA'); var multiple = $this.attr('data-gvhMultiple'); var idForm = $this.closest('form').attr('id'); var id = $this.attr('id'); var vId = id.split('_'); var json = null; $("#treeDialog_"+vId[1]).dialog("open"); $this.createTree( { idTree: vId[1], node: '#', multiple: multiple, url: url, claseM: claseM, destino: destino, actualizaA: campoDestino, panel: panel, idForm: idForm } ); } } ); }); //REVIEW: VERO Eliminar cuando el nuevo árbol esté acabado $('#gvhPage').off('changed.jstree').on( 'changed.jstree', 'div[data-gvhTree=true]', function(e) { var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.gvhTreeSelector_true' , callback: function() { var panel = $this.attr('data-gvhPanelOn'); var idPanel = 'P_'+panel; var panelJSON = panel; if (panel == 'lisDetalle') panelJSON = 'lis'; else if (panel == 'ediDetalle') panelJSON = 'edi'; var claseM = $this.closest('[data-gvhClaseManejadora]').attr('data-gvhClaseManejadora'); var action = $this.closest('form').attr('action'); var idForm = $this.closest('form').attr('id'); var campoDestino = $this.attr('data-gvhActualizaA'); var iterActual = $this.attr('data-gvhIterActual'); var sufijo = panel+'_'+iterActual; if (panel == 'fil') { campoDestinoValue = campoDestino; campoDestinoID = 'tree_'+campoDestinoValue; } else { estadoPanel = $('#'+idPanel).attr('data-gvhestadopanel'); if (estadoPanel == 'I') { campoDestinoValue = 'ins___'+campoDestino+'___'+sufijo; campoDestinoID = 'ins___tree_'+campoDestino+'___'+sufijo; } else { campoDestinoValue = 'cam___'+campoDestino+'___'+sufijo; campoDestinoID = 'cam___tree_'+campoDestino+'___'+sufijo; } } gvh.showConsoleMsg('log',"Nodo seleccionado:"); selectedNodes = data.selected; gvh.showConsoleMsg('log',data.selected); if (selectedNodes.length > 0) { $.each(selectedNodes, function( index, value ) { gvh.showConsoleMsg('log','1 - '+data.instance.get_selected(true)[index].text); $('#'+campoDestinoValue).val(data.instance.get_selected(true)[index].text); $('#'+campoDestinoID).val(data.instance.get_selected(true)[index].id); //gvh.showConsoleMsg('log','2 - '+data.instance.get_node(data.selected[index]).text); }); } else { gvh.showConsoleMsg('log','no hay seleccionados'); } } } ); }); //REVIEW: VERO Eliminar cuando el nuevo árbol esté acabado $('#gvhPage').off('keyup.search_treeDialog_arbolAjax').on( 'keyup.search_treeDialog_arbolAjax', '#search_treeDialog_arbolAjax', function(e) { var $this = $(this); gvh.semaphoreEnqueue ( { id: 'keyup.search_treeDialog_arbolAjax' , callback: function() { var v = $this.val(); gvh.showConsoleMsg('log',v); $('#arbolAjax').jstree(true).search(v);//, true, false, false, '#'); gvh.showConsoleMsg('log','post'); } } ); }); $('#gvhPage').off('change.input_gvhCalendar').on( 'change.input_gvhCalendar', 'input:text[data-gvhCalendar*=DT],input:text[data-gvhCalendar*=D-]', function(e) { var $this = $(this); gvh.semaphoreEnqueue ( { id: 'change.input_gvhCalendar' , callback: function() { var tipo = $this.attr('data-gvhCalendar').split('-'); var id = $this.attr('id'); var idInfoFecha = "infoFecha"+id; var info = ''; if (tipo.length > 1) { if ((tipo[1] != 'none') && (tipo[1] != 'undefined')) { //$dayOfWeek info = " "+$this.mostrarDiaSemanaJS($this.val(),tipo[1]); } if ((tipo[2] != 'none') && (tipo[2] != 'undefined')) { //$dayOfYear info += " D"+$this.calcularDiaAnyoJS($this.val()); } if ((tipo[3] != 'none') && (tipo[3] != 'undefined')) { //$weekOfYear info += " S"+$this.calcularSemanaJS($this.val()); } if (info != '') { $('#'+idInfoFecha).text(info); } } } } ); }); /* * TIME */ $('#gvhPage').off('click.calT').on( 'click.calT', 'button[id*=calT_]', function(e) { var $this = $(this); gvh.semaphoreEnqueue ( { id: 'click.calT' , callback: function() { var id_calendar = $this.attr ('id'); id_calendar = id_calendar.replace ('calT_', ''); var almohadilla = "#"; var id_calendar_comp = almohadilla + id_calendar; $(id_calendar_comp).timepicker( { hourMin: 8 , hourMax: 24 } ).focus(); } } ); }); }(jQuery);