Skip to content
ispconfig.min.js 17.5 KiB
Newer Older
var ISPConfig={pageFormChanged:!1,tabChangeWarningTxt:"",tabChangeDiscardTxt:"",tabChangeWarning:!1,tabChangeDiscard:!1,requestsRunning:0,indicatorCompleted:!1,registeredHooks:new Array,new_tpl_add_id:0,dataLogTimer:0,options:{useLoadIndicator:!1,useComboBox:!1},setOption:function(a,b){ISPConfig.options[a]=b},setOptions:function(a){$.extend(ISPConfig.options,a)},reportError:function(){},registerHook:function(a,b){ISPConfig.registeredHooks[a]||(ISPConfig.registeredHooks[a]=new Array);var c=ISPConfig.registeredHooks[a].length;ISPConfig.registeredHooks[a][c]=b},callHook:function(a,b){if(ISPConfig.registeredHooks[a])for(var c=0;c<ISPConfig.registeredHooks[a].length;c++){var d=ISPConfig.registeredHooks[a][c];d(a,b)}},resetFormChanged:function(){ISPConfig.pageFormChanged=!1},showLoadIndicator:function(){if(document.body.style.cursor="wait",1==ISPConfig.options.useLoadIndicator&&(ISPConfig.requestsRunning+=1,ISPConfig.requestsRunning<2)){var a=$("#ajaxloader");a.length<1&&(a=$('<div id="ajaxloader" style="display: none;"></div>'),a.appendTo("body"));var b=$("#content");if(b.length<1)return;ISPConfig.indicatorCompleted=!1;var c=b.offset().left+150,d=b.offset().top+150;a.css({left:c,top:d}).fadeIn("fast",function(){ISPConfig.indicatorCompleted=!0,ISPConfig.requestsRunning<1&&$(this).fadeOut("fast",function(){$(this).hide()})})}},hideLoadIndicator:function(){document.body.style.cursor="",ISPConfig.requestsRunning-=1,ISPConfig.requestsRunning<1&&(ISPConfig.requestsRunning=0,1==ISPConfig.indicatorCompleted&&$("#ajaxloader").fadeOut("fast",function(){$("#ajaxloader").hide()}))},onAfterSideNavLoaded:function(){1==ISPConfig.options.useComboBox&&$("#sidebar").find("select:not(.chosen-select)").select2({placeholder:"",width:"element",selectOnBlur:!0,allowClear:!0})},onAfterContentLoad:function(a,b){b=b?"&"+b:"",1==ISPConfig.options.useComboBox&&$("#pageContent").find("select:not(.chosen-select)").select2({placeholder:"",width:"element",selectOnBlur:!0,allowClear:!0,formatResult:function(a){return a.id&&$(a.element).parent().hasClass("flags")?'<span class="flags flag-'+a.id.toLowerCase()+'">'+a.text+"</span>":a.text},formatSelection:function(a){return a.id&&$(a.element).parent().hasClass("flags")?'<span class="flags flag-'+a.id.toLowerCase()+'">'+a.text+"</span>":a.text}}).on("change",function(){$("#pageForm .table #Filter").length>0&&$("#pageForm .table #Filter").trigger("click")}),$('input[data-input-element="date"]').datetimepicker({language:"en",todayHighlight:!0,todayBtn:"linked",bootcssVer:3,fontAwesome:!0,autoclose:!0,minView:"month"}),$('input[data-input-element="datetime"]').datetimepicker({language:"en",todayHighlight:!0,todayBtn:"linked",bootcssVer:3,fontAwesome:!0,autoclose:!0}),$('[data-toggle="tooltip"]').tooltip({}),$('input[type="password"]').each(function(){$(this).prop("readonly",!0).tooltip({title:"Click to set",placement:"left"})}),$('input[type="password"]').on("click focus",function(){$(this).prop("readonly",!1),$(this).tooltip("destroy")}),ISPConfig.callHook("onAfterContentLoad",{url:a,data:b})},submitForm:function(a,b,c){var d=arguments[3];if(c||(c=!1),!c||window.confirm(c)){$.ajax({type:"POST",url:b,data:$("#"+a).serialize(),dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(c,e,f){if(d&&alert(d),f.responseText.indexOf("HEADER_REDIRECT:")>-1){var g=f.responseText.split(":");ISPConfig.loadContent(g[1])}else f.responseText.indexOf("LOGIN_REDIRECT:")>-1?document.location.href="./index.php":($("#pageContent").html(f.responseText),ISPConfig.onAfterContentLoad(b,$("#"+a).serialize()),ISPConfig.pageFormChanged=!1);clearTimeout(dataLogTimer),ISPConfig.dataLogNotification(),ISPConfig.hideLoadIndicator()},error:function(a){ISPConfig.hideLoadIndicator();a.responseText.split(":");ISPConfig.reportError("Ajax Request was not successful. 111")}})}},submitUploadForm:function(a,b){var c=function(a){var b,c=a.contentWindow.document.body.innerHTML;try{b=JSON.parse(c)}catch(d){b=c}var e=$("<div></div>").html(b),f="",g=e.find("#OKMsg").html();g&&(f='<div id="OKMsg">'+g+"</div>");var h=e.find("#errorMsg").html();h&&(f=f+'<div id="errorMsg">'+h+"</div>");var i=e.find('input[name="_csrf_key"]').val(),j=e.find('input[name="_csrf_id"]').val();return f=f+'<input type="hidden" name="_csrf_id" value="'+j+'" /><input type="hidden" name="_csrf_key" value="'+i+'" />'},d="ajaxUploader-iframe-"+Math.round((new Date).getTime()/1e3);$("body").append('<iframe width="0" height="0" style="display:none;" name="'+d+'" id="'+d+'"/>'),$("#"+d).load(function(){var a=c(this);$("#errorMsg").remove(),$("#OKMsg").remove(),$('input[name="_csrf_key"]').remove(),$('input[name="_csrf_id"]').remove(),$('input[name="id"]').before(a),$(this).remove()}),$('input[type="file"]').closest("form").attr({target:d,action:b}).submit()},capp:function(a,b){$.ajax({type:"GET",url:"capp.php",data:"mod="+a+(void 0!=b?"&redirect="+b:""),dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(a,b,c){if(""!=c.responseText)if(c.responseText.indexOf("HEADER_REDIRECT:")>-1){var d=c.responseText.split(":");ISPConfig.loadContent(d[1])}else if(c.responseText.indexOf("URL_REDIRECT:")>-1){var e=c.responseText.substr(c.responseText.indexOf("URL_REDIRECT:")+"URL_REDIRECT:".length);document.location.href=e}ISPConfig.loadMenus(),ISPConfig.hideLoadIndicator()},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful."+a)}})},loadContent:function(a){{var b=arguments[1];$.ajax({type:"GET",url:a,data:b?b:null,dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(c,d,e){if(e.responseText.indexOf("HEADER_REDIRECT:")>-1){var f=e.responseText.split(":");ISPConfig.loadContent(f[1])}else if(e.responseText.indexOf("URL_REDIRECT:")>-1){var g=e.responseText.substr(e.responseText.indexOf("URL_REDIRECT:")+"URL_REDIRECT:".length);document.location.href=g}else $("#pageContent").html(e.responseText),ISPConfig.onAfterContentLoad(a,b?b:null),ISPConfig.pageFormChanged=!1;clearTimeout(dataLogTimer),ISPConfig.dataLogNotification(),ISPConfig.hideLoadIndicator()},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful. 113")}})}},loadContentRefresh:function(a){if($("#refreshinterval").val()>0){{$.ajax({type:"GET",url:a,data:"refresh="+document.getElementById("refreshinterval").value,dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(b,c,d){ISPConfig.hideLoadIndicator(),$("#pageContent").html(d.responseText),ISPConfig.onAfterContentLoad(a,"refresh="+document.getElementById("refreshinterval").value),ISPConfig.pageFormChanged=!1},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful."+a)}})}setTimeout("ISPConfig.loadContentRefresh('"+a+"&refresh="+document.getElementById("refreshinterval").value+"')",1e3*document.getElementById("refreshinterval").value*60)}},loadInitContent:function(){var a=$("#pageContent").attr("data-startpage");a||(a="dashboard/dashboard.php");$.ajax({type:"GET",url:a,data:"",dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(a,b,c){if(c.responseText.indexOf("HEADER_REDIRECT:")>-1){var d=c.responseText.split(":");ISPConfig.loadContent(d[1])}else $("#pageContent").html(c.responseText),ISPConfig.onAfterContentLoad("dashboard/dashboard.php",""),ISPConfig.pageFormChanged=!1;ISPConfig.hideLoadIndicator()},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful. 114")}});ISPConfig.loadMenus(),ISPConfig.keepalive(),ISPConfig.dataLogNotification(),setTimeout(function(){try{$("form#pageForm").find('input[name="username"]').focus()}catch(a){}},1e3)},loadMenus:function(){$.ajax({type:"GET",url:"nav.php",data:"nav=side",dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(a,b,c){ISPConfig.hideLoadIndicator(),$("#sidebar").html(c.responseText),ISPConfig.onAfterSideNavLoaded(),ISPConfig.loadPushyMenu()},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful. 115")}}),$.ajax({type:"GET",url:"nav.php",data:"nav=top",dataType:"html",beforeSend:function(){ISPConfig.showLoadIndicator()},success:function(a,b,c){ISPConfig.hideLoadIndicator(),$("#topnav-container").html(c.responseText),ISPConfig.loadPushyMenu()},error:function(){ISPConfig.hideLoadIndicator(),ISPConfig.reportError("Ajax Request was not successful. 116")}})},changeTab:function(a,b,c){if(ISPConfig.requestsRunning>0)return console.log("tab change interrupted, request still running."),!1;document.pageForm.next_tab.value=a;var d=$("form#pageForm").find('[name="id"]'),e=null;if(d.length>0&&(e=d.val()),"y"!=ISPConfig.tabChangeDiscard||c)if(e&&"y"==ISPConfig.tabChangeWarning&&1==ISPConfig.pageFormChanged)if(window.confirm(ISPConfig.tabChangeWarningTxt))ISPConfig.submitForm("pageForm",b);else{var f=a;e?ISPConfig.loadContent(b,{next_tab:f,id:e}):ISPConfig.loadContent(b,{next_tab:f})}else ISPConfig.submitForm("pageForm",b);else{if(!(d.length<1||e)||0!=ISPConfig.pageFormChanged&&!window.confirm(ISPConfig.tabChangeDiscardTxt))return!1;var f=a;e?ISPConfig.loadContent(b,{next_tab:f,id:e}):ISPConfig.loadContent(b,{next_tab:f})}},confirm_action:function(a,b){window.confirm(b)&&ISPConfig.loadContent(a)},loadContentInto:function(a,b){$.ajax({type:"GET",url:b,dataType:"html",beforeSend:function(){},success:function(b,c,d){$("#"+a).html(d.responseText)},error:function(){ISPConfig.reportError("Ajax Request was not successful. 118")}})},loadOptionInto:function(a,b,c){$.ajax({type:"GET",url:b,dataType:"html",beforeSend:function(){},success:function(d,e,f){var g=f.responseText,h=g.split("#");el=document.getElementById(a),el.innerHTML="";for(var i=0;i<h.length;++i){var j=document.createElement("option");j.appendChild(document.createTextNode(h[i])),j.value=h[i],el.appendChild(j)}"undefined"!=typeof c&&c(a,b)},error:function(){ISPConfig.reportError("Ajax Request was not successful. 119")}})},keepalive:function(){$.ajax({type:"GET",url:"keepalive.php",dataType:"html",success:function(){setTimeout(function(){ISPConfig.keepalive()},1e6)},error:function(){ISPConfig.reportError("Session expired. Please login again.")}})},dataLogNotification:function(){console.log(ISPConfig.options);$.ajax({type:"GET",url:"datalogstatus.php",dataType:"json",success:function(a){var d=[];$.each(a.entries,function(a,b){d.push("<li><strong>"+b.text+":</strong> "+b.count+"</li>")}),a.count>0?($(".modal-body").html(d.join("")),$(".notification_text").text(a.count),$(".notification").css("display",""),dataLogTimer=setTimeout(function(){ISPConfig.dataLogNotification()},2e3)):($(".notification").css("display","none"),$(".modal-body").html(""),$("#datalogModal").modal("hide"),dataLogTimer=setTimeout(function(){ISPConfig.dataLogNotification()},5e3))},error:function(){ISPConfig.reportError("Notification not loading, aborting."),$(".notification").css("display","none")}})},addAdditionalTemplate:function(){var a=$("#template_additional").val(),b=$("#tpl_add_select").val().split("|",2),c=b[0],d=b[1];if(c>0){var e=a.split("/");ISPConfig.new_tpl_add_id+=1;var f=$('<a href="#"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span></a>').attr("class","btn btn-danger btn-xs").click(function(a){a.preventDefault(),ISPConfig.delAdditionalTemplate($(this).parent().attr("rel"))});e[e.length]="n"+ISPConfig.new_tpl_add_id+":"+c,$("<li>"+d+"</li>").attr("rel","n"+ISPConfig.new_tpl_add_id).append(f).appendTo("#template_additional_list ul"),$("#template_additional").val(e.join("/")),alert("additional template "+d+" added to customer")}else alert("no additional template selcted")},delAdditionalTemplate:function(a){var b=$("#template_additional").val();if(a){var c=$("#template_additional_list ul").find('li[rel="'+a+'"]').eq(0),d=c.text();c.remove();for(var e=b.split("/"),f=new Array,g=0;g<e.length;g++){var h=e[g].split(":",2);(2!=h.length||h[0]!=a)&&(f[f.length]=e[g])}$("#template_additional").val(f.join("/")),alert("additional template "+d+" deleted from customer")}else if(""!=b){var i=document.getElementById("tpl_add_select").value.split("|",2),j=i[0],d=i[1];$("#template_additional_list ul").find("li:not([rel])").each(function(){var a=$(this).text();return a==d?($(this).remove(),!1):this});var f=b,k=new RegExp("(^|/)"+j+"(/|$)");f=f.replace(k,""),f=f.replace("//","/"),$("#template_additional").val(f),alert("additional template "+d+" deleted from customer")}else alert("no additional template selcted")}};$(document).on("change",function(a){var b=a.target.localName;$("#pageForm .table #Filter").length>0&&"select"==b&&(a.preventDefault(),$("#pageForm .table #Filter").trigger("click")),("select"==b||"input"==b||"textarea"==b)&&0==$(a.target).hasClass("no-page-form-change")&&(ISPConfig.pageFormChanged=!0)});var $page=$("html, body");$(document).on("click","a[data-load-content],button[data-load-content]",function(a){if(a.preventDefault(),ISPConfig.requestsRunning>0)return void console.log("preventing click because there is still a request running.");$page.on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()}),$page.animate({scrollTop:0},1e3,function(){$page.off("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()})});var b=$(this).attr("data-load-content");return b?void ISPConfig.loadContent(b):this}),$(document).on("click","a[data-capp],button[data-capp]",function(a){if(a.preventDefault(),ISPConfig.requestsRunning>0)return void console.log("preventing click because there is still a request running.");$page.on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()}),$page.animate({scrollTop:0},1e3,function(){$page.off("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()})});var b=$(this).attr("data-capp");return b?void ISPConfig.capp(b):this}),$(document).on("click","a[data-submit-form],button[data-submit-form]",function(a){if(a.preventDefault(),ISPConfig.requestsRunning>0)return void console.log("preventing click because there is still a request running.");$page.on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()}),$page.animate({scrollTop:0},1e3,function(){$page.off("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove",function(){$page.stop()})});var b=$(this),c=b.attr("data-form-action"),d=b.attr("data-submit-form");"true"==b.attr("data-form-upload")?ISPConfig.submitUploadForm(d,c):ISPConfig.submitForm(d,c)}),$(document).bind("keypress",function(a){"13"==a.which&&$("#pageForm .table #Filter").length>0&&0==$(a.target).hasClass("ui-autocomplete-input")&&(a.preventDefault(),$("#pageForm .table #Filter").trigger("click")),"13"==a.which&&$(".tab-content button.formbutton-success").length>0&&"textarea"!=a.target.localName&&$(a.target).is(":input")&&(a.preventDefault(),$(".tab-content button.formbutton-success").not("[disabled='disabled']").trigger("click"))}),$(document).on("click","th[data-column]",function(){var b=$(this),c=b.attr("data-column");if(!c)return this;if($("#pageForm .table #Filter").length>0&&"false"!=b.attr("data-sortable")){var d=$("#Filter"),e=d.attr("data-form-action"),f=d.attr("data-submit-form"),g=b.attr("data-ordered"),h="?";e.indexOf("?")>=0&&(h="&"),e=e+h+"orderby="+c,ISPConfig.submitForm(f,e),$(document).ajaxComplete(function(){var a=$('#pageForm .table th[data-column="'+c+'"]');a.parent().children("th[data-column]").removeAttr("data-ordered"),g&&"asc"==g?a.attr("data-ordered","desc"):a.attr("data-ordered","asc")})}}),$(document).on("click",".addPlaceholder",function(){var a=$(this).text(),b=$(this).siblings(":input");b.insertAtCaret(a)}),$(document).on("click",".addPlaceholderContent",function(){var a=$(this).find(".addPlaceholderContent").text(),b=$(this).siblings(":input");b.insertAtCaret(a)}),$(document).on("click","[data-check-fields] > input[type='checkbox']",function(){if($(this).is(":checked"))for(var a=$(this).parent().attr("data-check-fields"),b=a.split(/,/),c=0;c<b.length;c++){var d=b[c];$('input[type="checkbox"][name="'+d+'"]').prop("checked",!0)}}),$(document).on("click","[data-uncheck-fields] > input[type='checkbox']",function(){if(0==$(this).is(":checked"))for(var a=$(this).parent().attr("data-uncheck-fields"),b=a.split(/,/),c=0;c<b.length;c++){var d=b[c];$('input[type="checkbox"][name="'+d+'"]').prop("checked",!1)}}),$(document).on("ready",function(){$.fn.extend({insertAtCaret:function(a){return this.each(function(){if(document.selection)this.focus(),sel=document.selection.createRange(),sel.text=a,this.focus();else if(this.selectionStart||"0"==this.selectionStart){var c=this.selectionStart,d=this.selectionEnd,e=this.scrollTop;this.value=this.value.substring(0,c)+a+this.value.substring(d,this.value.length),this.focus(),this.selectionStart=c+a.length,this.selectionEnd=c+a.length,this.scrollTop=e}else this.value+=a,this.focus()})}}),$(".progress .progress-bar").css("width",function(){return $(this).attr("aria-valuenow")+"%"}),ISPConfig.loadInitContent(),$("#searchform").submit(function(a){a.preventDefault()}),$("#pageForm").submit(function(a){$("#pageForm .table #Filter").length>0&&a.preventDefault()}),$.fn.setCursorPosition=function(a){var b=$(this).get(0);if(b.setSelectionRange)b.setSelectionRange(a,a);else if(b.createTextRange){var c=b.createTextRange();c.collapse(!0),a<0&&(a=$(this).val().length+a),c.moveEnd("character",a),c.moveStart("character",a),c.select()}},$.fn.getCursorPosition=function(){var a=0,b=$(this).get(0);if("number"===typeof b.selectionStart)a="backward"==b.selectionDirection?b.selectionStart:b.selectionEnd;else if(document.selection){this.focus();var c=document.selection.createRange();c.moveStart("character",-b.value.length),a=c.text.length}return a}});