/** LIBRERÍA: gvh_init **/ /****************************/ // Constantes //var NAMESPACE_MAIN = 'gvh'; //var NAMESPACE_ALTERNATE = 'gvHidra'; gvh.VERSION = '5.0.0'; gvh.STOPONWARNING = true; // Solo se garantiza que parará si además está activado gvh.DEBUG gvh.onSelectionActive= false; // Para distinguir entre los eventos clic y seleccionar texto. gvh.orderTable; gvh.orderFieldTable; gvh.rewireUI = new Array(); gvh.dialogWS; gvh.dialogIdWM = new Array(); gvh.dialogWM; gvh.ambito = ''; gvh.aplTitle = ''; gvh.endLoading = true; //gvh.datosJSON; gvh.pagAct_edi = 'undefined'; gvh.pagAct_lis = 'undefined'; gvh.pagAct_ediDetalle = 'undefined'; gvh.pagAct_lisDetalle = 'undefined'; gvh.lang = 'esp'; gvh.urlLang = 'igep/include/gvh_lang/esp.json'; gvh.msgLoad = ''; // // Amplia la funcionalidad de jQuery, permitiendo unicidad en la definición de un evento // (elimina antes las definiciones previas del mismo evento, pero solo las idénticas). // jQuery.fn.extend( { /** * Amplia la funcionalidad de jQuery, permitiendo unicidad en la definición de un evento * (elimina antes las definiciones previas del mismo evento, pero solo las idénticas). * * Detach and attach an event handler function for one or more events to the selected elements. * * @param {object} elem * @param {string} types - Required. Specifies one or more event(s) or namespaces to attach to the selected elements. Multiple event values are separated by space. Must be a valid event. * @param {string} selector - Optional. Specifies that the event handler should only be attached to the specified child elements (and not the selector itself, like the deprecated delegate() method). * @param {anything} data - Optional. Specifies additional data to pass along to the function. * @param {function} fn - Required. Specifies the function to run when the event occurs. * @param {string} one - Specifies an event map ({event:function, event:function, ...}) containing one or more event to attach to the selected elements, and functions to run when the events occur. * * @return {jQuery} */ offon: function( elem, types, selector, data, fn, one ) { return this.off( types, selector, fn ).on( elem, types, selector, data, fn, one ); } , /* offon: function( types, selector, data, fn ) { this.off( types, selector, fn ); return this.on( this, types, selector, data, fn ); }, */ /** * Amplia la funcionalidad de jQuery, permitiendo unicidad en la definición de un evento * (elimina antes las definiciones previas del mismo evento, pero solo las idénticas) y * garantizando que como mucho se ejecutará una vez para cada elemento y tipo de evento. * * Detach and attach a handler to an event for the elements. The handler is executed at most once per element per event type. * * @param {string} types - Required. Specifies one or more event(s) or namespaces to attach to the selected elements. Multiple event values are separated by space. Must be a valid event. * @param {string} selector - Optional. Specifies that the event handler should only be attached to the specified child elements (and not the selector itself, like the deprecated delegate() method). * @param {anything} data - Optional. Specifies additional data to pass along to the function. * @param {function} fn - Required. Specifies the function to run when the event occurs. * * @return {jQuery} */ offone: function( types, selector, data, fn ) { return this.off( types, selector, fn ).one( this, types, selector, data, fn, 1 ); } } ); gvh.DEBUG = false; gvh.debugJS = function(debugJS) { if (debugJS == "LOG_ALL") { gvh.DEBUG = true; } }; gvh.findInRewireUI = function(key,val) { var ar = gvh.rewireUI; for (var i = 0,len = ar.length; i < len; i++) { if ( ar[i][key] === val ) { return i; } } return -1; } gvh.subscribeRewireUI = function( claseM,funcion ) { gvh.showConsoleMsg('log', ' - subscribeRewireUI() de '+claseM ); if ((gvh.rewireUI.length == 0) || (gvh.findInRewireUI('clase',claseM) == -1)) { var claseFuncion = {'clase': claseM,'funcion': funcion}; gvh.rewireUI.push(claseFuncion); } // Ejecutamos por primera vez la función recién suscrita. if( funcion && typeof funcion === "function" ) { funcion(); } } gvh.showConsoleMsg = function( type, msg ) { if( gvh.DEBUG ) { switch( type ) { case 'log': console.log( msg ); break; case 'error': console.error( msg ); break; case 'warn': console.warn( msg ); break; case 'dir': console.dir( msg ); break; case 'beginGroup': console.groupCollapsed( msg ); break; case 'endGroup': console.groupEnd( ); break; } } } /** * Comparar versiones de componentes software. * * Extraído de: https://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number */ gvh.versionCompare = function( v1, v2, options ) { let lexicographical = ''; let v1parts = ''; let v2parts = ''; let zeroExtend = ''; if (options != '') { lexicographical = options && options.lexicographical , zeroExtend = options && options.zeroExtend , v1parts = v1.split('.') , v2parts = v2.split('.'); } else { lexicographical = options, zeroExtend = options, v1parts = v1.split('.') , v2parts = v2.split('.'); } function isValidPart(x) { return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x); } if( (v1parts.isArray && !v1parts.every(isValidPart)) || (v2parts.isArray && !v2parts.every(isValidPart)) ) { return NaN; } if( zeroExtend ) { while( v1parts.length < v2parts.length ) { v1parts.push( "0" ); } while( v2parts.length < v1parts.length ) { v2parts.push( "0" ); } } if( !lexicographical ) { v1parts = v1parts.map( Number ); v2parts = v2parts.map( Number ); } for( let i=0; i v2parts[i] ) return 1; else return -1; } if( v1parts.length != v2parts.length ) return -1; return 0; } //gvh.versionCompare gvh.iniWindowVar = function(ambito, barTitle, dataJSON, lang, modal) { gvh.aplTitle = barTitle; gvh.ambito = ambito; if (typeof gvh.datosJSON === 'undefined') { gvh.datosJSON = dataJSON; } else { //gvh.datosJSON = Object.assign({},gvh.datosJSON, dataJSON); $.extend(true, gvh.datosJSON, dataJSON); } if (typeof gvh.pagAct_edi === 'undefined') { gvh.pagAct_edi = 0; } if (typeof gvh.pagAct_lis === 'undefined') { gvh.pagAct_lis = 0; } if (typeof gvh.pagAct_ediDetalle === 'undefined') { gvh.pagAct_ediDetalle = 0; } if (typeof gvh.pagAct_lisDetalle === 'undefined') { gvh.pagAct_lisDetalle = 0; } if (lang != '') gvh.lang = lang; gvh.urlLang = 'igep/include/gvh_lang/'+gvh.lang+'.json'; $.getJSON(gvh.urlLang, function(data) { gvh.msgLoad = data['gvhlang_load']; } ); if (typeof gvh.msgLoad === 'undefined') { gvh.msgLoad = $('body').attr('data-gvhMsgLoad'); } if (typeof gvh.objSliders === 'undefined') gvh.objSliders = []; if (typeof gvh.objColResizables === 'undefined') gvh.objColResizables = []; $.getScript( 'igep/smarty/plugins/gvh_calendar/js/jquery-ui-sliderAccess.js', function() { //console.log('Load jquery-ui-sliderAccess.js performed.'); $.getScript( 'igep/smarty/plugins/gvh_calendar/js/jquery-ui-timepicker-addon.js', function() { //console.log('Load jquery-ui-timepicker-addon.js performed.'); $.getScript( 'igep/js/gvh_iniCalendar.js', function() { //console.log('Load gvh_calendar.js performed.'); } ); } ); } ); } gvh.getUrlParameter = function(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } };