15 lines
29 KiB
JavaScript
15 lines
29 KiB
JavaScript
|
(function(b){b.easyAjax=function(l){var f={type:"GET",container:"body",blockUI:true,disableButton:false,buttonSelector:"[type='submit']",dataType:"json",messagePosition:"toastr",errorPosition:"field",hideElements:false,redirect:true,data:{},file:false};var d=f;if(l){d=b.extend(f,l)}if(typeof d.beforeSend!="function"){d.beforeSend=function(){b(d.container).find(".has-error").each(function(){b(this).find(".help-block").text("");b(this).removeClass("has-error")});b(d.container).find("#alert").html("");if(d.blockUI){b.easyBlockUI(d.container)}if(d.disableButton){j(d.buttonSelector)}}}if(typeof d.complete!="function"){d.complete=function(i,m){if(d.blockUI){b.easyUnblockUI(d.container)}if(d.disableButton){c(d.buttonSelector)}}}if(typeof d.error!="function"){d.error=function(i,o,m){var n="A server side error occurred. Please try again after sometime.";if(o=="timeout"){n="Connection timed out! Please check your internet connection"}e(n,"error")}}function e(q,n,m){var p={error:"danger",success:"success",primary:"primary",warning:"warning",info:"info"};if(d.messagePosition=="toastr"){b.showToastr(q,n,m)}else{var o=b(d.container).find("#alert");var i='<div class="alert alert-'+p[n]+'">'+q+"</div>";if(o.length==0){b(d.container).find(".form-group:first").before('<div id="alert">'+i+"</div>")}else{o.html(i)}}}if(d.file==true){var g=new FormData(b(d.container)[0]);var k=Object.keys(d.data);for(var h=0;h<k.length;h++){g.append(k[h],d.data[k[h]])}d.data=g}b.ajax({type:d.type,url:d.url,dataType:d.dataType,data:d.data,beforeSend:d.beforeSend,contentType:(d.file)?false:"application/x-www-form-urlencoded; charset=UTF-8",processData:!d.file,error:d.error,complete:d.complete,success:function(m){if(m.status=="success"){if(m.action=="redirect"){if(d.redirect){var x="";if(typeof m.message!="undefined"){x+=m.message}x+=" Redirecting...";e(x,"success",{timeOut:100000,positionClass:"toast-top-center"});window.location.href=m.url}}else{if(typeof m.message!="undefined"){e(m.message,"success")}}if(d.removeElements==true){b(d.container).find(".form-group, button, input").remove()}}if(m.status=="fail"){if(typeof m.message!="undefined"){e(m.message,"error")}if(typeof m.errors!="undefined"){var u=Object.keys(m.errors);b(d.container).find(".has-error").find(".help-block").remove();b(d.container).find(".has-error").removeClass("has-error");if(d.errorPosition=="field"){for(var p=0;p<u.length;p++){var s=u[p].replace(".","\\.");var w=b(d.container).find("[name='"+s+"']");if(w.length==0){w=b(d.container).find("#"+s)}var t=w.closest(".form-group");b(t).find(".help-block").remove();var n=b(t).find("div:first");if(n.length==0){n=b(t)}n.append('<div class="help-block">'+m.errors[u[p]]+"</div>");b(t).addClass("has-error")}if(u.length>0){var o=b("[name='"+u[0]+"']");if(o.length>0){b("html, body").animate({scrollTop:o.offset().top-150},200)}}}else{var r="<ul>";for(var p=0;p<u.length;p++){r+="<li>"+m.errors[u[p]]+"</li>"}r+="</ul>";var v=b(d.container).find("#alert");var q='<div class="alert alert-danger">'+r+"</div>";if(v.length==0){b(d.container).find(".form-group:first").before('<div id="alert">'+q+"</div>")}else{v.html(q)}}}}if(typeof d.success=="function"){d.success(m)}}});function j(i){var m=b(d.container).find(i);var n="Submitting...";if(m.width()<20){n="..."}if(!m.is("input")){m.attr("data-prev-text",m.html());m.text(n);m.prop("disabled",true)}else{m.attr("data-prev-text",m.val());m.val(n);m.prop("disabled",true)}}function c(i){var m=b(d.container).find(i);if(!m.is("input")){m.html(m.attr("data-prev-text"));m.prop("disabled",false)}else{m.val(m.attr("data-prev-text"));m.prop("disabled",false)}}};b.easyBlockUI=function(c,f){if(f==undefined){f="Loading..."}var d='<div class="loading-message"><div class="block-spinner-bar"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div></div>';if(c!=undefined){var e=b(c);var g=false;if(e.height()<=(b(window).height())){g=true}e.block({message:d,baseZ:999999,centerY:g,css:{top:"10%",border:"0",padding:"0",backgroundColor:"none"},overlayCSS:{backgroundColor:"transparent",opacity:0.05,cursor:"
|
||
|
/*!
|
||
|
* jQuery blockUI plugin
|
||
|
* Version 2.70.0-2014.11.23
|
||
|
* Requires jQuery v1.7 or later
|
||
|
*
|
||
|
* Examples at: http://malsup.com/jquery/block/
|
||
|
* Copyright (c) 2007-2013 M. Alsup
|
||
|
* Dual licensed under the MIT and GPL licenses:
|
||
|
* http://www.opensource.org/licenses/mit-license.php
|
||
|
* http://www.gnu.org/licenses/gpl.html
|
||
|
*
|
||
|
* Thanks to Amir-Hossein Sobhi for some excellent contributions!
|
||
|
*/
|
||
|
;!function(){function b(w){function C(L,R){var N,Z,X=L==window,p=R&&void 0!==R.message?R.message:void 0;if(R=w.extend({},w.blockUI.defaults,R||{}),!R.ignoreIfBlocked||!w(L).data("blockUI.isBlocked")){if(R.overlayCSS=w.extend({},w.blockUI.defaults.overlayCSS,R.overlayCSS||{}),N=w.extend({},w.blockUI.defaults.css,R.css||{}),R.onOverlayClick&&(R.overlayCSS.cursor="pointer"),Z=w.extend({},w.blockUI.defaults.themedCSS,R.themedCSS||{}),p=void 0===p?R.message:p,X&&h&&j(window,{fadeOut:0}),p&&"string"!=typeof p&&(p.parentNode||p.jquery)){var V=p.jquery?p[0]:p,J={};w(L).data("blockUI.history",J),J.el=V,J.parent=V.parentNode,J.display=V.style.display,J.position=V.style.position,J.parent&&J.parent.removeChild(V)}w(L).data("blockUI.onUnblock",R.onUnblock);var aa,r,G,d,u=R.baseZ;aa=w(g||R.forceIframe?'<iframe class="blockUI" style="z-index:'+u+++';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+R.iframeSrc+'"></iframe>':'<div class="blockUI" style="display:none"></div>'),r=w(R.theme?'<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+u+++';display:none"></div>':'<div class="blockUI blockOverlay" style="z-index:'+u+++';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>'),R.theme&&X?(d='<div class="blockUI '+R.blockMsgClass+' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(u+10)+';display:none;position:fixed">',R.title&&(d+='<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(R.title||" ")+"</div>"),d+='<div class="ui-widget-content ui-dialog-content"></div>',d+="</div>"):R.theme?(d='<div class="blockUI '+R.blockMsgClass+' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(u+10)+';display:none;position:absolute">',R.title&&(d+='<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(R.title||" ")+"</div>"),d+='<div class="ui-widget-content ui-dialog-content"></div>',d+="</div>"):d=X?'<div class="blockUI '+R.blockMsgClass+' blockPage" style="z-index:'+(u+10)+';display:none;position:fixed"></div>':'<div class="blockUI '+R.blockMsgClass+' blockElement" style="z-index:'+(u+10)+';display:none;position:absolute"></div>',G=w(d),p&&(R.theme?(G.css(Z),G.addClass("ui-widget-content")):G.css(N)),R.theme||r.css(R.overlayCSS),r.css("position",X?"fixed":"absolute"),(g||R.forceIframe)&&aa.css("opacity",0);var P=[aa,r,G],f=w(X?"body":L);w.each(P,function(){this.appendTo(f)}),R.theme&&R.draggable&&w.fn.draggable&&G.draggable({handle:".ui-dialog-titlebar",cancel:"li"});var i=v&&(!w.support.boxModel||w("object,embed",X?null:L).length>0);if(B||i){if(X&&R.allowBodyStretch&&w.support.boxModel&&w("html,body").css("height","100%"),(B||!w.support.boxModel)&&!X){var K=x(L,"borderTopWidth"),e=x(L,"borderLeftWidth"),l=K?"(0 - "+K+")":0,Q=e?"(0 - "+e+")":0}w.each(P,function(I,E){var M=E[0].style;if(M.position="absolute",2>I){X?M.setExpression("height","Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.support.boxModel?0:"+R.quirksmodeOffsetHack+') + "px"'):M.setExpression("height",'this.parentNode.offsetHeight + "px"'),X?M.setExpression("width",'jQuery.support.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"'):M.setExpression("width",'this.parentNode.offsetWidth + "px"'),Q&&M.setExpression("left",Q),l&&M.setExpression("top",l)}else{if(R.centerY){X&&M.setExpression("top",'(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"'),M.marginTop=0}else{if(!R.centerY&&X){var n=R.css&&R.css.top?parseInt(R.css.top,10):0,H="((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "+n+') + "px"';M.setExpression("top",H)}}}})}if(p&&(R.theme?G.find(".ui-widget-content").append(p):G.append(p),(p.jquery||p.nodeType)&&w(p).show()),(g||R.forceIframe)&&R.showOverlay&&aa.show(),R.fadeIn){var Y=R.onBlock?R.onBlock:y,F=R.showO
|