// var logCheckboxes = {}; var submenuId = ""; // Store ongoing AJAX requests in an array var ongoingRequests = []; // Start an AJAX request and add it to the ongoingRequests array function storeRequest(request) { ongoingRequests.push(request); } var vvUserActivityTimer = null; // Abort all ongoing AJAX requests function abortAllRequests() { for (let i = 0; i < ongoingRequests.length; i++) { if(ongoingRequests[i].readyState != 4){ ongoingRequests[i].abort(); console.log('About ongoing request ',ongoingRequests[i]); //delete ongoingRequests[i]; } } abortAllImageLoading(); //vvLoadHide(); } // Listen for the readystatechange event on the window object $(window).on('readystatechange', function () { if (document.readyState === 'complete') { abortAllRequests(); } }); // Listen for the popstate event on the window object $(window).on('popstate', function () { abortAllRequests(); }); // Bind the event listener to the beforeunload event window.addEventListener('beforeunload', abortAllRequests); let lastPingTime = 0; const cooldownDuration = 30000; // Cooldown duration in milliseconds // Function to handle mousemove event function handleMousemove() { const currentTime = Date.now(); if (currentTime - lastPingTime >= cooldownDuration) { vvSendPing({},'handleMousemove'); lastPingTime = currentTime; } } var userOnScreen = true; // Function to handle window focus event function handleWindowFocus() { console.log('welcome back'); const currentTime = Date.now(); if (currentTime - lastPingTime >= cooldownDuration) { vvSendPing({},'handleWindowFocus'); lastPingTime = Date.now(); } } // Function to handle visibility change event function handleVisibilityChange() { if (document.visibilityState === "visible") { userOnScreen = true; console.log("User returned to the tab"); const currentTime = Date.now(); if (currentTime - lastPingTime >= cooldownDuration) { vvSendPing({},'handleVisibilityChange'); setPollTimer(3000,'handleVisibilityChange'); lastPingTime = Date.now(); } } else { userOnScreen = false; console.log("User switched to a different tab or minimized the browser"); } } // Add event listeners document.addEventListener("mousemove", handleMousemove); window.addEventListener("focus", handleWindowFocus); document.addEventListener("visibilitychange", handleVisibilityChange); var _vvChangingSite = false; var vvChangeSiteId = function($id){ _vvChangingSite = true; vvLoadShow(); $('.dropdown-menu').removeClass('show'); $(document).trigger('vvChangeSiteId',$id); vvDebugg('+++ vvChangeSiteId -> '+$id); storeRequest( $.get('/?init=vvChangeSiteId&id='+$id,{},function(data){ vvDebugg(data); window.location.reload(); }) ); } async function vvGetAutomaticData(){ storeRequest( $.ajax({ url:settings['PIPE_URL']+'/?init=vvGetAutomaticProgressData', data:{'utoken':settings['utoken'],page:window.location.pathname,site_id:settings['site_id']}, type:'POST', dataType:"JSON", beforeSend: function(){ console.log('------->> vvGetAutomaticProgressData send'); }, complete: function(data){ console.log('------->> vvGetAutomaticProgressData Completed'); }, success: function(data){ console.log('------->> vvGetAutomaticProgressData Data::'); console.log(data); for(i in data){ item = data[i]; console.log(item); if($('#'+item.key).get(0) == undefined){ $(".header-alerts").append(HtmlDecode(item.html)); } } } }) ); } async function vvGetEmailsProgressData(){ storeRequest( $.ajax({ url:settings['PIPE_URL']+'/?init=vvGetEmailsProgressData', data:{'utoken':settings['utoken'],page:window.location.pathname}, type:'POST', dataType:"JSON", beforeSend: function(){ console.log('------->> vvGetEmailsProgressData send'); }, complete: function(data){ console.log('------->> vvGetEmailsProgressData Completed'); }, success: function(data){ console.log('------->> vvGetEmailsProgressData Data::'); console.log(data); for(i in data){ item = data[i]; console.log(item); if($('#'+item.key).get(0) == undefined){ $(".header-alerts").append(HtmlDecode(item.html)); } } } }) ); } var alertsAutomaticDataLoaded = false, alertsEmailsDataLoaded = false; async function headerAlerts(){ if(settings['user_online'] == true){ if(window.location.pathname == '/documents/issued/' || window.location.pathname == '/'){ if(!alertsAutomaticDataLoaded){ alertsAutomaticDataLoaded = true; vvGetAutomaticData(); } } if(!alertsEmailsDataLoaded){ alertsEmailsDataLoaded = true; vvGetEmailsProgressData(); } } } async function runTrueLogs(){ if(settings?.logs?.length){ if(settings.logs.length > 0){ for(i in settings.logs){ log = settings.logs[i]; if($('#item-'+log.rel_id).get(0) != undefined){ $('#item-'+log.rel_id).addClass('attention'); } } } } } function vvFilterList(){ var query = ""; _page = 0; $("#filters select,select.filters").each(function(){ if(query == ""){ query = "?"+$(this).attr('id')+'='+$(this).val(); }else{ query = query+"&"+$(this).attr('id')+'='+$(this).val(); } }); $("#filters input,input.filters").each(function(){ if(query == ""){ query = "?"+$(this).attr('id')+'='+$(this).val(); }else{ query = query+"&"+$(this).attr('id')+'='+$(this).val(); } }); query = query+'&page='+_page; pushState({idx:0,ID:0,Title:'Filter',LoadPage:true,AjaxBox:false},'', _url+query); } function closeFullscreen(){ $("body").removeClass('fullscreen'); $(".fullscreen-element").removeClass('fullscreen-element'); } function fullscreen(target){ if($("body").hasClass('fullscreen')){ closeFullscreen(); return; } $("body").addClass('fullscreen'); $(target).addClass('fullscreen-element'); } $.fn.serializeObject = function(options) { options = $.extend({}, options); var self = this, json = {}, push_counters = {}, patterns = { "validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/, "key": /[a-zA-Z0-9_\sąćęłóśżźĄĆĘŁÓŚŻŹ\/-]+|(?=\[\])/g, "push": /^$/, "fixed": /^\d+$/, "named": /^[a-zA-Z0-9_]+$/ }; this.build = function(base, key, value){ base[key] = value; return base; }; this.push_counter = function(key){ if(push_counters[key] === undefined){ push_counters[key] = 0; } return push_counters[key]++; }; $.each($(this).serializeArray(), function(){ var k, keys = this.name.match(patterns.key), merge = this.value, reverse_key = this.name; while((k = keys.pop()) !== undefined){ reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), ''); merge = self.build({}, k, merge); } json = $.extend(true, json, merge); }); return json; }; var countDown = 5, pageInterval = null; $(window).scroll(function() { $(".scroll-fixed-outside.enabled").each(function(){ if($(this).is(':visible')){ if(($(window).scrollTop()+$(window).height()) > $(this).attr('data-stick') - $(this).height()){ $(this).removeClass('on'); }else if($(window).height()>$(this).attr('data-stick')){ $(this).removeClass('on'); }else{ $(this).addClass('on'); } } }); }); $(document).ready(function(){ vvInit(); $(document).bind('closeFunctionVote',function(e,data){ $("#vote-"+data.section).fadeOut(); }); }); $(document).bind('vvInit',function(){ setTimeout("vvInit()",200); }); $(document).unbind('vvPageChange').bind('vvPageChange',function(e,j,x){ console.log(e,j,x); vvDebugg('--- vvPageChange triggerd'); submenu = []; vvDebugg('**** Reset submenu '); loadingcarbs = []; vvDebugg('**** Reset loading carbs '); $(".page-change-btn").trigger('click'); //Page change ajax if($("#page-container").hasClass('sidebar-o-xs')){ $("#page-container").removeClass('sidebar-o-xs'); } $(".navbar-toggle").addClass('collapsed'); $("#body").removeClass('nav-open').attr('style',''); $(document).trigger('vvPageChangeEnd'); for(i in settings['timers']){ clearInterval(settings['timers'][i]); settings['timers'][i] = undefined; } }); $(document).unbind('fileDeleted').bind('fileDeleted',function(e,data){ vvDebugg("*** REMOVE FILE "); if( $(".file-"+data.id).parent().hasClass('upload-box') ){ window.location.reload(); }else{ $(".file-"+data.id).parent().find('.upload-box').show(); $(".file-"+data.id).remove(); } $(document).trigger('fileDeleteAfter'); }); $(document).bind('vvPageLoad',function(){ vvDebugg('--- vvPageLoad triggerd'); //Ping vvSendPing({},'vvPageLoad'); $(".active").removeClass('active'); if(window.location.pathname.length > 1){ $('a[href*="'+window.location.pathname+'"]').each(function(){ var _obj = $(this); if(window.location.pathname == _obj.attr('href')){ if(_obj.parent().parent().hasClass('nav-main')){ _obj.parent().addClass('open'); _obj.parent().addClass('active'); _obj.addClass('active'); }else{ _obj.addClass('active'); } }else{ } }); } $(document).trigger('vvPageLoadEnd'); $(document).unbind('vvInitFooterEnd'); }); var pings = []; async function vvSendMessage(message){ if(pings[message] == undefined){ pings[message] = true; const body = {'message':message,'utoken':settings['utoken'],page:window.location.pathname}; const headers = {type: 'application/json'}; const blob = new Blob([JSON.stringify(body)], headers); navigator.sendBeacon(settings['PING_URL']+'?init=vvPing&message='+message+'&site_id='+settings['site_id']+'&uid='+settings['uid'], blob); } } async function vvSetTheme(data = {}){ vvDebugg('------------------------------------------- vvSetTheme -------------------------------------------'); $.ajax({ url:'/?init=vvSetTheme', data:data, type:'POST', dataType:"JSON", beforeSend: function(){ console.log('---- vvSetTheme '); }, complete: function(data){ console.log('---- vvSetTheme Completed'); }, success: function(data){ console.log('---- vvSetTheme Success:'); } }); } async function vvSendPing(data = {}, from = ''){ vvDebugg('------------------------------------------- sendBeacon :: '+from+' -------------------------------------------'); const body = {'utoken':settings['utoken'],page:window.location.pathname,...data}; console.log(body); const headers = {type: 'application/json'}; const blob = new Blob([JSON.stringify(body)], headers); navigator.sendBeacon(settings['PING_URL']+'?init=vvPing', blob); /* $.ajax({ url:settings['PIPE_URL']+'/?init=vvPing', data:{'utoken':settings['utoken'],page:window.location.pathname}, type:'POST', dataType:"JSON", beforeSend: function(){ console.log('---- Update Session'); }, complete: function(data){ console.log('---- Update Session Completed'); }, success: function(data){ console.log('---- Update Session Success:'); console.log(data); } }); $.ajax({ url:settings['PIPE_URL']+'/?init=vvRevive', data:{'utoken':settings['utoken'],page:window.location.pathname}, type:'POST', dataType:"JSON", beforeSend: function(){ console.log('---- Update Session'); }, complete: function(data){ console.log('---- Update Session Completed'); }, success: function(data){ console.log('---- Update Session Success:'); console.log(data); } }); */ } function lockUser(){ navigator.sendBeacon('/?init=lockUser'); top.location = "/lock-screen/?r="+encodeURIComponent(window.location.pathname+''+window.location.search); } function vvUserActivity(){ //Warning if(settings.user_online && (settings.timeout-(Math.floor(Date.now()/1000))) < 700){ swal({ title: "Inactivity alert", icon: "info", buttons: { btn1:{ text: "I'm back", value: false, }, btn2:{ text: "Lock account", value: true, } } }).then((value) => { if(value){ lockUser(); }else{ settings.timeout = (Math.floor(Date.now()/1000))+3600; vvSendPing({},'vvUserActivity'); } }); } //Lock user if(settings.user_online && (settings.timeout-(Math.floor(Date.now()/1000))) < 350){ if(!settings.user_activity_alert){ lockUser(); } } } $(document).bind('vvUserActivityEnd',function(e,data){ settings.timeout = data.timeout; }); $(document).bind('imageChangeUrlToPng', function (e, data) { var newSrc = $(".upload-key-" + data.id).find('img').attr('src').replace(/\.(jpg|jpeg|gif)/gi, '.png'); $(".upload-key-" + data.id).find('img').attr('src', newSrc); setTimeout(function(){ $(".upload-key-" + data.id).addClass('image-box-loading'); vvInit(); },500); }); $(document).bind('imageReloadFile', function (e, data) { $(".upload-key-" + data.id).addClass('image-box-loading'); vvInit(); }); function updateSubMenuSize(){ $("#nav-submenu-header li ul").each(function(){ li = $(this).parent(); a = li.find('.nav-submenu'); if(!a.hasClass('level-top-menu')){ return; } if(!a.hasClass('nav-submenu-resized')){ a.addClass('nav-submenu-resized'); } li.find('ul').css('opacity',0).show(); a_width = a.outerWidth(true); $(this).find('a').each(function(){ if($(this).outerWidth()>a_width){ a_width = $(this).outerWidth(true); } }); a.css('minWidth',((a_width+2))+'px'); li.find('ul').attr('style',""); }); } function printTheJSONInPrettyFormat(badJSON) { var parseJSON = JSON.parse(badJSON); var JSONInPrettyFormat = JSON.stringify(parseJSON, undefined, 4); return JSONInPrettyFormat; } $(document).unbind('vvInitEnded').bind('vvInitEnded',function(e,data){ _vvSetInputsDefaults(); $(".admin-list table").off('click', 'td').on('click', 'td', function(e) { if ($(e.target).is('a') || $(e.target).is('div')) { return; }else if($(e.target).is('td')){ $(this).parent().find('a').first().trigger('click'); } }); $('.info[data-toggle]').unbind('click').bind('click', function() { $($(this).data('target')).collapse("toggle"); }); $(".image-box-loading").each(function(){ var element = $(this); // Save the current context in a variable if(!element.hasClass('image-box-loading-init')){ element.addClass('image-box-loading-init'); console.log({'site_id': settings['site_id'], 'utoken': settings['utoken'], id: element.attr('data-id')}); $.ajax({ url: settings['PIPE_URL'] + '/?init=uploadBoxImageFetch', data: {'site_id': settings['site_id'], 'utoken': settings['utoken'], id: element.attr('data-id')}, type: 'POST', dataType: "HTML", beforeSend: function(){ // You can do something here before the request is sent, like showing a loader }, complete: function(data){ // This will be called after the request is complete, regardless of success or failure }, success: $.proxy(function(data){ console.log(data); this.parent().append($(data)); this.remove(); vvInit(); }, element) // Using $.proxy to maintain the context }); } }); $("a[href='#checklist']").unbind('click').bind('click',function(e){ e.preventDefault(); if ($('#page-container').hasClass('side-overlay-o')) { $(document).off('keydown.cb.sideOverlay'); $('#page-container').removeClass('side-overlay-o'); } else { $('#page-container').addClass('side-overlay-o'); } }); $("a[href='#onboarding-guide']").unbind('click').bind('click',function(e){ e.preventDefault(); userflow.start('6316d069-2a18-4ce4-aab5-85f2b5579d9e'); $(document).off('keydown.cb.sideOverlay'); $('#page-container').removeClass('side-overlay-o'); }); $("a[href='#userflow-billing']").unbind('click').bind('click',function(e){ e.preventDefault(); javascript:userflow.start('c531e4cb-a648-4f93-86e7-ad4698e4b40e'); $(document).off('keydown.cb.sideOverlay'); $('#page-container').removeClass('side-overlay-o'); }); $("a[href='#userflow-general-settings']").unbind('click').bind('click',function(e){ e.preventDefault(); userflow.start('1fcb829d-e88f-4e59-b1a5-2a4a546484ed'); $(document).off('keydown.cb.sideOverlay'); $('#page-container').removeClass('side-overlay-o'); }); $("a[href='#userflow-domain']").unbind('click').bind('click',function(e){ e.preventDefault(); userflow.start('0c489c4c-f241-4d05-9eb3-b759606ccf6f'); $(document).off('keydown.cb.sideOverlay'); $('#page-container').removeClass('side-overlay-o'); }); $(".log-delete-checkbox").unbind('change').bind('change',function(){ id = $(this).attr('id'); console.log($(this).parent().parent().parent()); if(logCheckboxes[id] == undefined || logCheckboxes[id] !== true) { $(this).parents('.show-on-hover').addClass('show'); logCheckboxes[id] = true; }else{ $(this).parents('.show-on-hover').removeClass('show'); logCheckboxes[id] = false; } }); for(i in logCheckboxes){ $("#"+i).prop("checked",logCheckboxes[i]).trigger('change'); } $(document).on('select2:open', (e) => { setTimeout(function() { var searchField = $($('.select2-container--open').get(1)).find('.select2-search__field').get(0); if (searchField) { searchField.focus(); } else { console.log("Search field not found"); } }, 500); //document.querySelector('.select2-search__field').focus(); }); $(".full-content-height").css('height',$("#page-container").height()); setTimeout(function(){ $(".full-content-height").css('height',$("#page-container").height()); },500); setTimeout(function(){ $(".full-content-height").css('height',$("#page-container").height()); },1500); setTimeout(function(){ $(".full-content-height").css('height',$("#page-container").height()); },2500); if(typeof submenu != "undefined"){ if(submenu.length>0){ /* if(submenu[0].children == undefined){ submenu[0].children ={}; $(".nav-main-header li").each(function(){ if($(this).parent().hasClass('nav-main-header')){ var id = $(this).find('a').attr('id'); if(id != undefined){ submenu[0].children[id] = { title:$(this).find('a').attr('title'), url:$(this).find('a').attr('href'), }; } } }); } */ //$("#nav-main-header").addClass('d-none'); $("#nav-submenu-header").html(""); for(i in submenu){ item = submenu[i]; if(item.class == undefined){ item.class = ''; } item._icon = ''; if(item.type == 'main'){ item._icon = ''; } if(item.type == 'break'){ item.class += 'd-none '; item._icon = ''; } if(item.active == 'auto' && location.pathname == item.url){ item.class += 'active '; }else if(item.active == true){ item.class += 'active '; } if(item.type == 'sub'){ item._icon = ''; } if(item.icon == true){ item._icon = ''; }else if(item.icon != undefined){ item._icon = ''; } if(item.children != undefined){ item.class += ' nav-submenu level-top-menu'; ul = '