plexpy/data/interfaces/default/js/jquery-cron-min.js
2018-03-17 10:17:39 -07:00

1 line
8.0 KiB
JavaScript

!function(e){function t(e){return"undefined"==typeof e?!1:!0}function n(e){return!t(e)||"object"==typeof e}function s(n,s){if(t(s.customValues))for(key in s.customValues)if(n==s.customValues[key])return key;var a=/^((\d{1,2}|\*)\s){4}(\d{1,2}|\*)$/;if("string"!=typeof n||!a.test(n))return void e.error("cron: invalid initial value");for(var i=n.split(" "),r=[0,0,1,1,0],l=[59,23,31,12,6],c=0;c<i.length;c++)if("*"!=i[c]){var d=parseInt(i[c]);if(!(t(d)&&d<=l[c]&&d>=r[c]))return void e.error("cron: invalid value found (col "+(c+1)+") in "+o.initial)}for(var u in k)if(k[u].test(n))return u;return void e.error("cron: valid but unsupported cron format. sorry.")}function a(o,a){if(!t(s(a.initial,a)))return!0;if(!n(a.customValues))return!0;if(t(a.customValues))for(key in a.customValues)if(k.hasOwnProperty(key))return e.error("cron: reserved keyword '"+key+"' should not be used as customValues key."),!0;return!1}function i(e){var t=e.data("block"),o=hour=day=month=dow="*",n=t.period.find("select").val();switch(n){case"minute":break;case"hour":o=t.mins.find("select").val();break;case"day":o=t.time.find("select.cron-time-min").val(),hour=t.time.find("select.cron-time-hour").val();break;case"week":o=t.time.find("select.cron-time-min").val(),hour=t.time.find("select.cron-time-hour").val(),dow=t.dow.find("select").val();break;case"month":o=t.time.find("select.cron-time-min").val(),hour=t.time.find("select.cron-time-hour").val(),day=t.dom.find("select").val();break;case"year":o=t.time.find("select.cron-time-min").val(),hour=t.time.find("select.cron-time-hour").val(),day=t.dom.find("select").val(),month=t.month.find("select").val();break;default:return n}return[o,hour,day,month,dow].join(" ")}for(var r={initial:"* * * * *",minuteOpts:{minWidth:100,itemWidth:30,columns:4,rows:void 0,title:"Minutes Past the Hour"},timeHourOpts:{minWidth:100,itemWidth:20,columns:2,rows:void 0,title:"Time: Hour"},domOpts:{minWidth:100,itemWidth:30,columns:void 0,rows:10,title:"Day of Month"},monthOpts:{minWidth:100,itemWidth:100,columns:2,rows:void 0,title:void 0},dowOpts:{minWidth:100,itemWidth:void 0,columns:void 0,rows:void 0,title:void 0},timeMinuteOpts:{minWidth:100,itemWidth:20,columns:4,rows:void 0,title:"Time: Minute"},effectOpts:{openSpeed:400,closeSpeed:400,openEffect:"slide",closeEffect:"slide",hideOnMouseOut:!0},url_set:void 0,customValues:void 0,onChange:void 0,useGentleSelect:!1},l="",c=0;60>c;c++){var d=10>c?"0":"";l+="<option value='"+c+"'>"+d+c+"</option>\n"}for(var u="",c=0;24>c;c++){var d=10>c?"0":"";u+="<option value='"+c+"'>"+d+c+"</option>\n"}for(var m="",c=1;32>c;c++){if(1==c||21==c||31==c)var h="st";else if(2==c||22==c)var h="nd";else if(3==c||23==c)var h="rd";else var h="th";m+="<option value='"+c+"'>"+c+h+"</option>\n"}for(var p="",v=["January","February","March","April","May","June","July","August","September","October","November","December"],c=0;c<v.length;c++)p+="<option value='"+(c+1)+"'>"+v[c]+"</option>\n";for(var f="",y=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],c=0;c<y.length;c++)f+="<option value='"+c+"'>"+y[c]+"</option>\n";for(var g="",b=["minute","hour","day","week","month","year"],c=0;c<b.length;c++)g+="<option value='"+b[c]+"'>"+b[c]+"</option>\n";var O={minute:[],hour:["mins"],day:["time"],week:["dow","time"],month:["dom","time"],year:["dom","month","time"]},k={minute:/^(\*\s){4}\*$/,hour:/^\d{1,2}\s(\*\s){3}\*$/,day:/^(\d{1,2}\s){2}(\*\s){2}\*$/,week:/^(\d{1,2}\s){2}(\*\s){2}\d{1,2}$/,month:/^(\d{1,2}\s){3}\*\s\*$/,year:/^(\d{1,2}\s){4}\*$/},w={init:function(o){var n=o?o:{},s=e.extend([],r,n),i=e.extend({},r.effectOpts,n.effectOpts);if(e.extend(s,{minuteOpts:e.extend({},r.minuteOpts,i,n.minuteOpts),domOpts:e.extend({},r.domOpts,i,n.domOpts),monthOpts:e.extend({},r.monthOpts,i,n.monthOpts),dowOpts:e.extend({},r.dowOpts,i,n.dowOpts),timeHourOpts:e.extend({},r.timeHourOpts,i,n.timeHourOpts),timeMinuteOpts:e.extend({},r.timeMinuteOpts,i,n.timeMinuteOpts)}),a(this,s))return this;var c=[],d="",h=s.customValues;if(t(h))for(var v in h)d+="<option value='"+h[v]+"'>"+v+"</option>\n";c.period=e("<span class='cron-period'>Every <select name='cron-period' class='"+n.classes+"'>"+d+g+"</select> </span>").appendTo(this).data("root",this);var y=c.period.find("select");return y.bind("change.cron",S.periodChanged).data("root",this),s.useGentleSelect&&y.gentleSelect(i),c.dom=e("<span class='cron-block cron-block-dom'> on the <select name='cron-dom' class='"+n.classes+"'>"+m+"</select> </span>").appendTo(this).data("root",this),y=c.dom.find("select").data("root",this),s.useGentleSelect&&y.gentleSelect(s.domOpts),c.month=e("<span class='cron-block cron-block-month'> of <select name='cron-month' class='"+n.classes+"'>"+p+"</select> </span>").appendTo(this).data("root",this),y=c.month.find("select").data("root",this),s.useGentleSelect&&y.gentleSelect(s.monthOpts),c.mins=e("<span class='cron-block cron-block-mins'> at <select name='cron-mins' class='"+n.classes+"'>"+l+"</select> minutes past the hour </span>").appendTo(this).data("root",this),y=c.mins.find("select").data("root",this),s.useGentleSelect&&y.gentleSelect(s.minuteOpts),c.dow=e("<span class='cron-block cron-block-dow'> on <select name='cron-dow' class='"+n.classes+"'>"+f+"</select> </span>").appendTo(this).data("root",this),y=c.dow.find("select").data("root",this),s.useGentleSelect&&y.gentleSelect(s.dowOpts),c.time=e("<span class='cron-block cron-block-time'> at <select name='cron-time-hour' class='cron-time-hour "+n.classes+"'>"+u+"</select>:<select name='cron-time-min' class='cron-time-min "+n.classes+"'>"+l+" </span>").appendTo(this).data("root",this),y=c.time.find("select.cron-time-hour").data("root",this),s.useGentleSelect&&y.gentleSelect(s.timeHourOpts),y=c.time.find("select.cron-time-min").data("root",this),s.useGentleSelect&&y.gentleSelect(s.timeMinuteOpts),c.controls=e("<span class='cron-controls'>&laquo; save <span class='cron-button cron-button-save'></span> </span>").appendTo(this).data("root",this).find("span.cron-button-save").bind("click.cron",S.saveClicked).data("root",this).end(),this.find("select").bind("change.cron-callback",S.somethingChanged),this.data("options",s).data("block",c),this.data("current_value",s.initial),w.value.call(this,s.initial)},value:function(e){if(!e)return i(this);var o=this.data("options"),n=this.data("block"),a=o.useGentleSelect,r=s(e,o);if(!t(r))return!1;if(t(o.customValues)&&o.customValues.hasOwnProperty(r))r=o.customValues[r];else for(var l=e.split(" "),c={mins:l[0],hour:l[1],dom:l[2],month:l[3],dow:l[4]},d=O[r],u=0;u<d.length;u++){var m=d[u];if("time"==m){var h=n[m].find("select.cron-time-hour").val(c.hour);a&&h.gentleSelect("update"),h=n[m].find("select.cron-time-min").val(c.mins),a&&h.gentleSelect("update")}else{var h=n[m].find("select").val(c[m]);a&&h.gentleSelect("update")}}var p=n.period.find("select").val(r);return a&&p.gentleSelect("update"),p.trigger("change"),this}},S={periodChanged:function(){var t=e(this).data("root"),o=t.data("block"),n=(t.data("options"),e(this).val());if(t.find("span.cron-block").hide(),O.hasOwnProperty(n))for(var s=O[e(this).val()],a=0;a<s.length;a++)o[s[a]].show()},somethingChanged:function(){root=e(this).data("root"),t(root.data("options").url_set)?w.value.call(root)!=root.data("current_value")?(root.addClass("cron-changed"),root.data("block").controls.fadeIn()):(root.removeClass("cron-changed"),root.data("block").controls.fadeOut()):root.data("block").controls.hide();var o=root.data("options").onChange;t(o)&&e.isFunction(o)&&o.call(root)},saveClicked:function(){var t=e(this),o=t.data("root"),n=w.value.call(o);t.hasClass("cron-loading")||(t.addClass("cron-loading"),e.ajax({type:"POST",url:o.data("options").url_set,data:{cron:n},success:function(){o.data("current_value",n),t.removeClass("cron-loading"),n==w.value.call(o)&&(o.removeClass("cron-changed"),o.data("block").controls.fadeOut())},error:function(){alert("An error occured when submitting your request. Try again?"),t.removeClass("cron-loading")}}))}};e.fn.cron=function(t){return w[t]?w[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?void e.error("Method "+t+" does not exist on jQuery.cron"):w.init.apply(this,arguments)}}(jQuery);