/* * 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').offon( 'click', 'input[type=radio][data-gvhCWSource=cwlistaradio]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); gvh.changeField($(this)); }); // CAMPO DE TEXTO $('#gvhPage').offon( 'change', 'input[type=text][data-gvhCWSource=cwcampotexto]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); if ($(this).attr('data-inputmask') != undefined) { gvh.semaforoChange('changeInputMask',$(this)); } else { gvh.changeField($(this)); } }); // autocomplete $('#gvhPage').offon( 'keypress', 'input[type=text][data-gvhFuncion=autocomplete][data-gvhCWSource=cwcampotexto]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var idCampo = $(this).attr('id'); var claseM = $(this).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').offon( 'change', 'textarea', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); gvh.changeField($(this)); }); // SELECT $('#gvhPage').offon( 'change', "select[data-gvhCWSource='cwlista']", function(e) { e.stopPropagation(); e.stopImmediatePropagation(); gvh.changeField($(this)); }); $('#gvhPage').offon( 'change', "[data-gvhCWSource='cwlista_select2']", function(e) { e.stopPropagation(); e.stopImmediatePropagation(); gvh.changeField($(this)); }); // ÁREA DE TEXTO ENRIQUECIDO $('#gvhPage').offon( 'focusout', '.jqte_editor', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var id = $(this).attr('id'); var idTxtArea = id.split('editor_')[1]; var objElemento = $('#'+idTxtArea); gvh.changeField(objElemento); }); /* *********************************************************************************************************************** * EVENTOS ASOCIADOS A LAS OPCIONES DE MENÚ DE LA PANTALLA PRINCIPAL */ $('#gvhPage').offon( 'click', 'a[data-gvhLinkMenu=true] , div.item > a', function(e) { e.stopImmediatePropagation(); 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').offon( 'click', 'a[data-gvhFunction=nDetalles]', function(e) { e.stopImmediatePropagation(); gvh.callControllerJS($(this)); }); /* *********************************************************************************************************************** * EVENTOS ASOCIADO ETIQUETA URL */ $('#gvhPage').offon( 'click', 'a[data-gvhLabel=url]', function(e) { e.stopImmediatePropagation(); 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').offon( 'click', 'input[data-gvhFunction=checkRow]', function(e) { e.stopImmediatePropagation(); panel = $(this).attr('data-gvhPanelOn'); claseM = $(this).attr('data-gvhClaseManejadora'); id = $(this).attr('id'); row = id.split('_')[2]; claseM = $(this).attr('data-gvhClaseManejadora'); 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').offon( 'click', 'input[type=checkbox][data-gvhCWSource=cwcheckbox]', function(e) { e.stopPropagation(); e.stopImmediatePropagation(); var claseM = $(this).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 * */ $('#gvhPage').offon( 'click', 'button[data-gvhFunction=gvhTreeSelector][data-gvhTreeAjax=false]', function(e) { gvh.showConsoleMsg('log','gvh_tree.js - button gvhTreeSelector ajax false'); let panel = $(this).attr('data-gvhPanelOn'); let estado = $('div[id=P_'+panel+']').attr('data-gvhestadopanel'); let idPanel = 'P_'+panel; let claseManejadora = $(this).attr('data-gvhClaseManejadora'); let multiple = false; if ($(this).attr('data-gvhMultiple') == "true") { multiple = true; } let idForm = $(this).closest('form').attr('id'); let campoDestino = $(this).attr('data-gvhActualizaA'); let iterActual = $(this).attr('data-gvhIterActual'); let sufijo = panel+'_'+iterActual; if (panel == 'fil') { let campoDestinoValue = campoDestino; let campoDestinoID = 'tree_'+campoDestinoValue; } else { if (estado == 'I') { let campoDestinoValue = 'ins___'+campoDestino+'___'+sufijo; let campoDestinoID = 'ins___tree_'+campoDestino+'___'+sufijo; } else { let campoDestinoValue = 'cam___'+campoDestino+'___'+sufijo; let campoDestinoID = 'cam___tree_'+campoDestino+'___'+sufijo; } } let id = $(this).attr('id'); let vId = id.split('_'); // Comprobar si existe la variable gvh.datosJSON let raizJSON = gvh.datosJSON[claseManejadora][panel]; let data = []; let destino = $(this).attr('data-gvhDestino'); if (raizJSON['gvhJSON'] == 'false') { let data = JSON.stringify($("#"+idForm).serialize()); let url = "phrame.php?action="+claseManejadora+"__"+destino; } else { let data = gvh.datosJSON; let url = "phrame.php?action="+claseManejadora+"__"+destino+"&gvhcache=true&claseManejadora="+claseManejadora+"&gvhpanel="+panel; } gvh.showConsoleMsg('log',data); let 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'); let idTree = $(this).attr('id'); //$(this).attr('data-gvhIDTree'); //panel = $('#'+idTree).attr('data-gvhPanelOn'); let idPanel = 'P_'+panel; let panelJSON = panel; if (panel == 'lisDetalle') panelJSON = 'lis'; else if (panel == 'ediDetalle') panelJSON = 'edi'; let campoDestino = $('#'+idTree).attr('data-gvhActualizaA'); let iterActual = $('#'+idTree).attr('data-gvhIterActual'); let sufijo = panel+'_'+iterActual; if (panel == 'fil') { let campoDestinoValue = campoDestino; let campoDestinoID = 'tree_'+campoDestinoValue; } else { let estadoPanel = $('#'+idPanel).attr('data-gvhestadopanel'); gvh.showConsoleMsg('log','estadoPanel: '+estadoPanel); if (estadoPanel == 'I') { let campoDestinoValue = 'ins___'+campoDestino+'___'+sufijo; let campoDestinoID = 'ins___tree_'+campoDestino+'___'+sufijo; } else { let campoDestinoValue = 'cam___'+campoDestino+'___'+sufijo; let campoDestinoID = 'cam___tree_'+campoDestino+'___'+sufijo; } } let actualizaA = $('#'+campoDestinoValue).attr('data-gvhActualizaA'); let formulario = $('#'+campoDestinoValue).closest('form'); // checkedNodes = $('#'+idTree).jstree("get_checked",null,true); //gvh.showConsoleMsg('log','chequeados '+checkedNodes); let allText = []; /*$.each(checkedNodes, function (i, nodeId) { var node = $('#'+idTree).jstree("get_node", nodeId); allText.push(node.text); }); gvh.showConsoleMsg('log','allText '+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 - '+claseManejadora); gvh.showConsoleMsg('log',' formulario - '+formulario); gvh.updateEvent($('#'+campoDestinoValue)); } }, search: function(event,node) { $('#input-check-node').val(), { ignoreCase: false, exactMatch: false } }, }); } } }); }); $('#gvhPage').offon( 'click', 'button[data-gvhFunction=gvhTreeSelector][data-gvhTreeAjax=true]', function(e) { let panel = $(this).attr('data-gvhPanelOn'); let idPanel = 'P_'+panel; let claseManejadora = $(this).attr('data-gvhClaseManejadora'); let destino = $(this).attr('data-gvhDestino'); let url = "phrame.php?action="+claseManejadora+"__"+destino; let campoDestino = $(this).attr('data-gvhActualizaA'); let multiple = $(this).attr('data-gvhMultiple'); let idForm = $(this).closest('form').attr('id'); let id = $(this).attr('id'); let vId = id.split('_'); let json = null; $("#treeDialog_"+vId[1]).dialog("open"); $(this).createTree({ idTree: vId[1], node: '#', multiple: multiple, url: url, claseM: claseManejadora, destino: destino, actualizaA: campoDestino, panel: panel, idForm: idForm }); }); $('#gvhPage').offon( 'changed.jstree', 'div[data-gvhTree=true]', function(e) { let panel = $(this).attr('data-gvhPanelOn'); let idPanel = 'P_'+panel; let panelJSON = panel; if (panel == 'lisDetalle') panelJSON = 'lis'; else if (panel == 'ediDetalle') panelJSON = 'edi'; let claseManejadora = $(this).attr('data-gvhClaseManejadora'); let action = $(this).closest('form').attr('action'); let idForm = $(this).closest('form').attr('id'); let campoDestino = $(this).attr('data-gvhActualizaA'); let iterActual = $(this).attr('data-gvhIterActual'); let 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); }); /*$.ajax({ data: gvh.datosJSON, type: "POST", datatype: "json", url: action+"&gvhcache=true&claseManejadora="+claseManejadora+"&gvhpanel="+panelJSON, beforeSend: function() { $(this).loading(); }, success: function(response) { window.location.href = decodeURIComponent(jQuery.parseJSON(response)); }, fail: function() { alert('fail'); }, complete: function( jqXHR, textStatus, errorThrown ) { $('div[id=loading]').hide(); } })*/ } else { gvh.showConsoleMsg('log','no hay seleccionados'); } }); var to = false; //$('#search_treeDialog_arbolAjax').keyup(function () { $('#gvhPage').offon( 'keyup', '#search_treeDialog_arbolAjax', function(e) { var v = $(this).val(); gvh.showConsoleMsg('log',v); $('#arbolAjax').jstree(true).search(v);//, true, false, false, '#'); gvh.showConsoleMsg('log','post'); //if(to) { clearTimeout(to); } /*to = setTimeout(function () { var v = $(this).val(); $('#arbolAjax').jstree(true).search(v); }, 250);*/ }); $('#gvhPage').offon( 'change', 'input:text[data-gvhCalendar*=DT],input:text[data-gvhCalendar*=D-]', function(e) { 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').offon( 'click', 'button[id*=calT_]', function(e) { 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);