saeedsq/django-fancy-cronfield

View on GitHub
fancy_cronfield/static/fancy_cronfield/js/jquery-cron.min.js

Summary

Maintainability
A
0 mins
Test Coverage
/*
 * jQuery gentleSelect plugin (version 0.1.4.1)
 * http://shawnchin.github.com/jquery-cron
 *
 * Copyright (c) 2010-2013 Shawn Chin.
 * Dual licensed under the MIT or GPL Version 2 licenses.
 */
(function(f){function k(a){return"undefined"===typeof a?!1:!0}function y(a,b){if(k(b.customValues))for(key in b.customValues)if(a===b.customValues[key])return key;var e=/^((\d{1,2}|\*)\s){4}(\d{1,2}|\*)$/;if("string"===typeof a&&e.test(a)){for(var e=a.split(" "),c=[0,0,1,1,0],z=[59,23,31,12,6],d=[b.allowMultiple_all||b.allowMultiple_minute,b.allowMultiple_all||b.allowMultiple_hour,b.allowMultiple_all||b.allowMultiple_dom,b.allowMultiple_all||b.allowMultiple_month,b.allowMultiple_all||b.allowMultiple_dow],
l=0;l<e.length;l++)if("*"!==e[l]){var g=parseInt(e[l],10);if(!(k(g)&&g<=z[l]&&g>=c[l]||d[l]||-1===e[l].indexOf(","))){var h="cron: invalid value found (col "+(l+1),h=h+(") in "+b.initial);f.error(h);return}}for(h in t)if(t[h].test(a))return h;f.error("cron: valid but unsupported cron format. sorry.")}else f.error("cron: invalid initial value")}function A(a,b){if(!k(y(b.initial,b)))return!0;var e=b.customValues;if(k(e)&&"object"!==typeof e)return!0;if(k(b.customValues))for(key in b.customValues)if(t.hasOwnProperty(key))return f.error("cron: reserved keyword '"+
key+"' should not be used as customValues key."),!0;return!1}for(var h={initial:"* * * * *",minuteOpts:{minWidth:100,itemWidth:30,columns:4,rows:void 0,title:gettext("Minutes Past the Hour")},timeHourOpts:{minWidth:100,itemWidth:20,columns:2,rows:void 0,title:gettext("Time: Hour")},domOpts:{minWidth:100,itemWidth:30,columns:void 0,rows:10,title:gettext("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:gettext("Time: Minute")},effectOpts:{openSpeed:400,closeSpeed:400,openEffect:"slide",closeEffect:"slide",hideOnMouseOut:!0},url_set:void 0,allowMultiple_all:!1,allowMultiple_dom:!1,allowMultiple_month:!1,allowMultiple_dow:!1,allowMultiple_minute:!1,allowMultiple_hour:!1,customValues:void 0,onChange:void 0,useGentleSelect:!1},r="",g=0,c=0;60>c;c++)g=10>c?"0":"",r+="<option value='"+c+"'>"+g+c+"</option>\n";for(var u=
"",c=0;24>c;c++)g=10>c?"0":"",u+="<option value='"+c+"'>"+g+c+"</option>\n";for(var m="",c=1;32>c;c++)g="",g=1===c||21===c||31===c?gettext("%(day)sst"):2===c||22===c?gettext("%(day)snd"):3===c||23===c?gettext("%(day)srd"):gettext("%(day)sth"),m+="<option value='"+c+"'>",m+=interpolate(g,{day:c},!0),m+="</option>\n";for(var n="",g=[gettext("January"),gettext("February"),gettext("March"),gettext("April"),gettext("May"),gettext("June"),gettext("July"),gettext("August"),gettext("September"),gettext("October"),
gettext("November"),gettext("December")],c=0;c<g.length;c++)n+="<option value='"+(c+1)+"'>",n+=g[c],n+="</option>\n";for(var v="",g=[gettext("Sunday"),gettext("Monday"),gettext("Tuesday"),gettext("Wednesday"),gettext("Thursday"),gettext("Friday"),gettext("Saturday")],c=0;c<g.length;c++)v+="<option value='"+c+"'>"+g[c]+"</option>\n";for(var p="",g=[gettext("minute"),gettext("hour"),gettext("day"),gettext("week"),gettext("month"),gettext("year")],c=0;c<g.length;c++)p+="<option value='"+g[c]+"'>",p+=
g[c],p+="</option>\n";var w={minute:[],hour:["mins"],day:["time"],week:["dow","time"],month:["dom","time"],year:["dom","month","time"]},t={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}\*$/},q={init:function(a){var b=a?a:{};a=f.extend([],h,b);var e=f.extend({},h.effectOpts,b.effectOpts);f.extend(a,{minuteOpts:f.extend({},h.minuteOpts,e,b.minuteOpts),domOpts:f.extend({},
h.domOpts,e,b.domOpts),monthOpts:f.extend({},h.monthOpts,e,b.monthOpts),dowOpts:f.extend({},h.dowOpts,e,b.dowOpts),timeHourOpts:f.extend({},h.timeHourOpts,e,b.timeHourOpts),timeMinuteOpts:f.extend({},h.timeMinuteOpts,e,b.timeMinuteOpts)});if(A(this,a))return this;var b=[],c="",g=a.customValues;if(k(g))for(var d in g)g.hasOwnProperty(d)&&(c+="<option value='"+g[d]+"'>"+d+"</option>\n");d="<span class='cron-period'>"+gettext("Every");d=d+(" <select name='cron-period'>"+c)+(p+"</select> </span>");b.period=
f(d).appendTo(this).data("root",this);d=b.period.find("select");d.bind("change.cron",x.periodChanged).data("root",this);a.useGentleSelect&&d.gentleSelect(e);e="";if(a.allowMultiple_all||a.allowMultiple_dom)e=" multiple='multiple'";d="<span class='cron-block cron-block-dom'>"+(" "+gettext("on the")+" <select name='cron-dom'");d+=e+">"+m+"</select> </span>";b.dom=f(d).appendTo(this).data("root",this);d=b.dom.find("select").data("root",this);a.useGentleSelect&&d.gentleSelect(a.domOpts);e="";if(a.allowMultiple_all||
a.allowMultiple_month)e=" multiple='multiple'";d="<span class='cron-block cron-block-month'>"+(" "+gettext("of")+" <select name='cron-month'");d+=e+">"+n+"</select> </span>";b.month=f(d).appendTo(this).data("root",this);d=b.month.find("select").data("root",this);a.useGentleSelect&&d.gentleSelect(a.monthOpts);e="";if(a.allowMultiple_all||a.allowMultiple_minute)e=" multiple='multiple'";d="<span class='cron-block cron-block-mins'>"+(" "+gettext("at")+" <select name='cron-mins'");d+=e+">"+r+"</select> ";
d+=gettext("minutes past the hour")+" </span>";b.mins=f(d).appendTo(this).data("root",this);d=b.mins.find("select").data("root",this);a.useGentleSelect&&d.gentleSelect(a.minuteOpts);c="";if(a.allowMultiple_all||a.allowMultiple_dow)c=" multiple='multiple'";d="<span class='cron-block cron-block-dow'>"+(" "+gettext("on")+" <select name='cron-dow'");d+=c+">"+v+"</select> </span>";b.dow=f(d).appendTo(this).data("root",this);d=b.dow.find("select").data("root",this);a.useGentleSelect&&d.gentleSelect(a.dowOpts);
c="";if(a.allowMultiple_all||a.allowMultiple_hour)c=" multiple='multiple'";d="<span class='cron-block cron-block-time'> "+gettext("at");d+=" <select name='cron-time-hour' class='cron-time-hour'";d+=c+">"+u;d+="</select>:<select name='cron-time-min'";d+="class='cron-time-min'"+e+">"+r;d+=" </span>";b.time=f(d).appendTo(this).data("root",this);d=b.time.find("select.cron-time-hour").data("root",this);a.useGentleSelect&&d.gentleSelect(a.timeHourOpts);d=b.time.find("select.cron-time-min").data("root",
this);a.useGentleSelect&&d.gentleSelect(a.timeMinuteOpts);d="<span class='cron-controls'>&laquo; save <span class='cron-button cron-button-save'></span>";d+=" </span>";b.controls=f(d).appendTo(this).data("root",this).find("span.cron-button-save").bind("click.cron",x.saveClicked).data("root",this).end();this.find("select").bind("change.cron-callback",x.somethingChanged);this.data("options",a).data("block",b);this.data("current_value",a.initial);return q.value.call(this,a.initial)},value:function(a){if(!a){var b;
a:{b=this.data("block");var e="*",c="*",f=a="*",d="*",g=b.period.find("select").val();switch(g){case "minute":break;case "hour":e=b.mins.find("select").val();break;case "day":e=b.time.find("select.cron-time-min").val();c=b.time.find("select.cron-time-hour").val();break;case "week":e=b.time.find("select.cron-time-min").val();c=b.time.find("select.cron-time-hour").val();d=b.dow.find("select").val();break;case "month":e=b.time.find("select.cron-time-min").val();c=b.time.find("select.cron-time-hour").val();
a=b.dom.find("select").val();break;case "year":e=b.time.find("select.cron-time-min").val();c=b.time.find("select.cron-time-hour").val();a=b.dom.find("select").val();f=b.month.find("select").val();break;default:b=g;break a}b=[e,c,a,f,d].join(" ")}return b}f=this.data("options");e=this.data("block");b=f.useGentleSelect;c=y(a,f);if(!k(c))return!1;if(k(f.customValues)&&f.customValues.hasOwnProperty(c))c=f.customValues[c];else for(a=a.split(" "),a={mins:a[0],hour:a[1],dom:a[2],month:a[3],dow:a[4]},f=w[c],
d=0;d<f.length;d++){var g=f[d],h;"time"===g?(h=e[g].find("select.cron-time-hour").val(a.hour),b&&h.gentleSelect("update"),h=e[g].find("select.cron-time-min").val(a.mins)):h=e[g].find("select").val(a[g]);b&&h.gentleSelect("update")}e=e.period.find("select").val(c);b&&e.gentleSelect("update");e.trigger("change");return this}},x={periodChanged:function(){var a=f(this).data("root"),b=a.data("block"),c=f(this).val();a.find("span.cron-block").hide();if(w.hasOwnProperty(c))for(a=w[f(this).val()],c=0;c<a.length;c++)b[a[c]].show()},
somethingChanged:function(){var a=f(this).data("root");k(a.data("options").url_set)?q.value.call(a)!==a.data("current_value")?(a.addClass("cron-changed"),a.data("block").controls.fadeIn()):(a.removeClass("cron-changed"),a.data("block").controls.fadeOut()):a.data("block").controls.hide();var b=a.data("options").onChange;k(b)&&f.isFunction(b)&&b.call(a)},saveClicked:function(){var a=f(this),b=a.data("root"),c=q.value.call(b);a.hasClass("cron-loading")||(a.addClass("cron-loading"),f.ajax({type:"POST",
url:b.data("options").url_set,data:{cron:c},success:function(){b.data("current_value",c);a.removeClass("cron-loading");c===q.value.call(b)&&(b.removeClass("cron-changed"),b.data("block").controls.fadeOut())},error:function(){alert(gettext("An error occurred when submitting your request. Try again?"));a.removeClass("cron-loading")}}))}};f.fn.cron=function(a){if(q[a])return q[a].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof a&&a)f.error("Method "+a+" does not exist on jQuery.cron");
else return q.init.apply(this,arguments)}})(jQuery_1_4_1);