diff --git a/Cakefile b/Cakefile index 9f81177..074385b 100644 --- a/Cakefile +++ b/Cakefile @@ -3,7 +3,7 @@ task "full", -> exec "coffee -cb lib/icui.coffee", (e) -> console.log e if e - exec "uglifyjs lib/strftime.js lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> + exec "uglifyjs lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> console.log e if e exec "rm lib/icui.js" exec "git checkout gh-pages", (e) -> @@ -21,7 +21,7 @@ task "full", -> build = (cb) -> exec "coffee -cb lib/icui.coffee", (e) -> console.log e if e - exec "uglifyjs2 lib/strftime.js lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> + exec "uglifyjs2 lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> console.log e if e exec "rm lib/icui.js", (e) -> cb() if cb @@ -29,7 +29,7 @@ build = (cb) -> task 'build', -> exec "coffee -cb lib/icui.coffee", (e) -> console.log e if e - exec "uglifyjs2 lib/strftime.js lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> + exec "uglifyjs2 lib/icui.js -o js/jquery.icui.min.js -c -m", (e) -> console.log e if e exec "rm lib/icui.js" @@ -48,6 +48,7 @@ task 'develop', -> ICUI Test + @@ -60,7 +61,7 @@ task 'develop', ->

Editing

- +

Make new

@@ -86,14 +87,9 @@ task 'develop', -> response.write("""$(function() {document.write("

Compile Error

#{("" + e).replace(/\n/g, "\\n")}
");});""", 'UTF-8') response.end() else - exec "cat lib/icui.js > js/icui.js && cat lib/strftime.js >> js/icui.js", (e) -> - if e - response.write("""document.body.write('

Compile Error

#{e}
)""", 'UTF-8') - response.end() - else - fs.readFile 'js/icui.js', "binary", (err, file) -> - response.write(file, "binary") - response.end() + fs.readFile 'lib/icui.js', "binary", (err, file) -> + response.write(file, "binary") + response.end() else if extension == 'js' && !uri.match(/jasmine/) comps = uri.split('.') comps.pop() diff --git a/README.md b/README.md index a1e9b4c..69a428b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,9 @@ def json2yaml(str) end ~~~ -ICUI is dependent on jQuery and expects it to be already present. Typically ICUI will be used with a hidden form field which contains as it's value the JSON representation of the IceCube schedule. Then the jQuery method `icui` should be called to instantiate ICUI. The form field will be updated automatically with a new JSON representation on form submission. +ICUI is dependent on jQuery and Moment.JS and expects them to be already present. + +Typically ICUI will be used with a hidden form field which contains as it's value the JSON representation of the IceCube schedule. Then the jQuery method `icui` should be called to instantiate ICUI. The form field will be updated automatically with a new JSON representation on form submission. For usage with AJAX the `icui.getData()` method must be called to get a native representation of the data. @@ -51,12 +53,8 @@ Gotcha's ICUI isn't tested on any IE, but should work, but might require a JSON shim. -ICUI currently extends the `Date` prototype with a `strftime` (written by Gianni Chiappetta) method, the plan is to drop this in the future. - Currently ICUI doesn't support the rules and validations that have higher resolution than 1 day, however it should be fairly trivial to add these and in fact this is on the development roadmap. -ICUI currently deals with all times as if they are UTC times. - Development and Extension ------------------------- diff --git a/js/jquery.icui.min.js b/js/jquery.icui.min.js index 43d9aad..b6efd5b 100644 --- a/js/jquery.icui.min.js +++ b/js/jquery.icui.min.js @@ -1 +1 @@ -"undefined"==typeof Date.prototype.strftime&&(Date.prototype.strftime=function(){function t(t){return t.getUTCDate()+""}function e(t){return t.getUTCDay()+""}function n(t){return((t.getTime()-C.start_of_year.getTime())/R+1+"").split(/\./)[0]}function r(e){return("0"+t(e)).slice(-2)}function a(t){return t.toLocaleString()}function i(t){return t.toLocaleDateString()}function u(t){return t.toLocaleTimeString()}function o(t){var e=t.getUTCHours();return 0===e?e=12:e>12&&(e-=12),e+""}function s(t){return t.getUTCHours()}function p(t){return("0"+s(t)).slice(-2)}function c(t){return("0"+o(t)).slice(-2)}function l(t){return t.getUTCHours()>=12?"pm":"am"}function h(t){return l(t).toUpperCase()}function d(t){return("0"+t.getUTCMinutes()).slice(-2)}function f(t){return("0"+(t.getUTCMonth()+1)).slice(-2)}function y(t){return O[t.getUTCMonth()]}function _(t){return I[t.getUTCMonth()]}function m(t){return("0"+t.getUTCSeconds()).slice(-2)}function g(t){var e=t.getTimezoneOffset();return(e>=0?"-":"")+("0"+e/60).slice(-2)+":"+("0"+e%60).slice(-2)}function v(t){return("0"+Math.round(parseInt(n(t),10)/7)).slice(-2)}function D(t){return M[t.getUTCDay()]}function b(t){return k[t.getUTCDay()]}function w(t){return t.getUTCFullYear()+""}function T(t){return w(t).slice(-2)}function x(t){var e,n=t;for(C.start_of_year=new Date("Jan 1 "+this.getUTCFullYear());e=S.exec(t);)e[1]in U&&(n=n.replace(new RegExp(e[0],"mg"),U[e[1]](this)));return n}var C={start_of_year:new Date("Jan 1 "+(new Date).getFullYear())},S=/%([a-z]|%)/gim,R=864e5,M=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],O=["January","February","March","April","May","June","July","August","September","October","November","December"],k=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],I=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],U={a:b,A:D,b:_,B:y,c:a,d:r,e:t,H:p,I:c,j:n,k:s,l:o,m:f,M:d,p:h,P:l,S:m,U:v,w:e,x:i,X:u,y:T,Y:w,z:g,"%":function(){return"%"}};return x}());var __hasProp={}.hasOwnProperty,__slice=[].slice,__bind=function(t,e){return function(){return t.apply(e,arguments)}},__extends=function(t,e){function n(){this.constructor=t}for(var r in e)__hasProp.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};!function(t){var e,n,r,a,i,u,o,s,p,c,l,h,d,f,y,_,m,g,v,D;return s={clone:D=function(t){var e,n,r;if(null==t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return e="",null!=t.global&&(e+="g"),null!=t.ignoreCase&&(e+="i"),null!=t.multiline&&(e+="m"),null!=t.sticky&&(e+="y"),new RegExp(t.source,e);null!=t.parent&&null!=t.data?(r=new t.constructor(t.parent,"__clone"),r.data=D(t.data)):r=new t.constructor;for(n in t)__hasProp.call(t,n)&&"parent"!==n&&"data"!==n&&"elem"!==n&&"function"!=typeof t[n]&&(r[n]=D(t[n]));return r},option:function(t,e,n){var r;return r="function"==typeof n?n(t):n===t,'"},select:function(t,e){var n,r,a;r=""},daysOfTheWeek:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthsOfTheYear:["January","February","March","April","May","June","July","August","September","October","November","December"],dateFromString:function(t){var e,n,r,a,i,u,o,s,p,c,l,h,d;return l=t.split(/[\sT]/),n=l[0],s=l[1],h=function(){var t,e,r,a;for(r=n.split("-"),a=[],t=0,e=r.length;e>t;t++)o=r[t],a.push(parseInt(o,10));return a}(),c=h[0],a=h[1],e=h[2],d=function(){var t,e,n,r;for(n=s.split(":"),r=[],t=0,e=n.length;e>t;t++)o=n[t],r.push(parseInt(o,10));return r}(),r=d[0],i=d[1],u=3<=d.length?__slice.call(d,2):[],a=a-1>=0?a-1:11,p=(new Date).getTimezoneOffset(),new Date(Date.UTC(c,a,e,r,i,0,0))}},h=function(){function e(t,e){this.parent=t,null==e&&(e=null),this.destroy=__bind(this.destroy,this),this.clone=__bind(this.clone,this),this.children=[],this.data={},"__clone"!==e&&(null!=e?this.fromData(e):this.defaults())}return e.prototype.fromData=function(){},e.prototype.defaults=function(){},e.prototype.clonable=function(){return!0},e.prototype.destroyable=function(){return this.parent.children.length>1},e.prototype.clone=function(){return this.parent.children.push(s.clone(this)),this.triggerRender()},e.prototype.destroy=function(){return this.elem.slideUp(100,function(t){return function(){return t.parent.children.splice(t.parent.children.indexOf(t),1),t.parent.triggerRender()}}(this))},e.prototype.render=function(){var e;return e=t("
"),this.clonable()&&e.append(t("+").click(this.clone)),this.destroyable()&&e.append(t("-").click(this.destroy)),e.append(this.renderChildren()),e.children()},e.prototype.renderChildren=function(){var t,e,n,r,a;for(r=this.children,a=[],e=0,n=r.length;n>e;e++)t=r[e],a.push(t.render());return a},e.prototype.triggerRender=function(){return this.parent.triggerRender()},e}(),d=function(e){function n(){n.__super__.constructor.apply(this,arguments),this.parent.after("
"),this.target=this.parent.siblings(".icui").first()}return __extends(n,e),n.prototype.clonable=function(){return!1},n.prototype.destroyable=function(){return!1},n.prototype.has_ending_time=!1,n.prototype.has_rules=!1,n.prototype.fromData=function(t){var e,n,r;this.children.push(new y(this,t.start_date)),t.end_time&&(this.has_ending_time=!0,this.children.push(new o(this,t.end_time))),r=[];for(e in t)n=t[e],n.length>0&&"start_date"!==e&&"end_time"!==e&&(this.has_rules=!0,r.push(this.children.push(new _(this,{type:e,values:n}))));return r},n.prototype.defaults=function(){return this.children.push(new y(this))},n.prototype.triggerRender=function(){return this.render()},n.prototype.render=function(){var e;return this.target.html(this.renderChildren()),this.has_ending_time||(e=t("Add Ending Time "),e.click(function(t){return function(){return t.has_ending_time=!0,e.hide(),t.children.push(new o(t)),t.triggerRender(),!1}}(this)),this.target.append(e),this.target.append("
")),this.has_rules?void 0:(e=t("Add Repetition"),e.click(function(t){return function(){return t.has_rules=!0,e.hide(),t.children.push(new _(t)),t.triggerRender(),!1}}(this)),this.target.append(e))},n.prototype.getData=function(){var t,e,n,r,a,i;for(n={},i=this.children,r=0,a=i.length;a>r;r++)t=i[r],e=t.getData(),n[e.type]=n[e.type]?n[e.type].concat(e.values):e.values;return n},n}(h),_=function(e){function r(){return r.__super__.constructor.apply(this,arguments)}return __extends(r,e),r.prototype.defaults=function(){return this.data.type="rtimes",this.children=[new n(this)]},r.prototype.fromData=function(t){var e,r,a,i,u,o,s,p,c;if(this.data.type=t.type,this.data.type.match(/times$/)){for(o=t.values,p=[],r=0,i=o.length;i>r;r++)e=o[r],p.push(this.children.push(new n(this,e)));return p}for(s=t.values,c=[],a=0,u=s.length;u>a;a++)e=s[a],c.push(this.children.push(new f(this,e)));return c},r.prototype.getData=function(){var t,e;return this.data.type.match(/times$/)?(e=function(){var e,n,r,a;for(r=this.children,a=[],e=0,n=r.length;n>e;e++)t=r[e],a.push(t.getData().time);return a}.call(this),{type:this.data.type,values:e}):(e=function(){var e,n,r,a;for(r=this.children,a=[],e=0,n=r.length;n>e;e++)t=r[e],a.push(t.getData());return a}.call(this),{type:this.data.type,values:e})},r.prototype.render=function(){var e;return this.elem=t('
Event on \n
"),e=this.elem.find("select"),e.first().change(function(t){return function(e){return t.data.type="1"===e.target.value?t.data.type.replace(/^ex/,"r"):t.data.type.replace(/^r/,"ex")}}(this)),e.last().change(function(t){return function(e){return"dates"===e.target.value?(t.data.type=t.data.type.match(/^r/)?"rtimes":"extimes",t.children=[new n(t)]):(t.data.type=t.data.type.match(/^r/)?"rrules":"exrules",t.children=[new f(t)]),t.triggerRender()}}(this)),this.elem.append(r.__super__.render.apply(this,arguments)),this.elem},r}(h),n=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return __extends(n,e),n.prototype.defaults=function(){var t;return null!=(t=this.data).time?t.time:t.time=new Date},n.prototype.fromData=function(t){return this.data.time=s.dateFromString(t)},n.prototype.getData=function(){return this.data},n.prototype.render=function(){var e,r,a;return this.elem=t('
\n \n \n
'),r=this.elem.find("input"),e=r.first(),a=r.last(),r.change(function(t){return function(){return t.data.time=s.dateFromString(e.val()+" "+a.val())}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(h),y=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return __extends(e,t),e.prototype.destroyable=function(){return!1},e.prototype.clonable=function(){return!1},e.prototype.getData=function(){return{type:"start_date",values:this.data.time}},e.prototype.render=function(){return this.elem=e.__super__.render.apply(this,arguments),this.elem.prepend("Start time"),this.elem},e}(n),o=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return __extends(e,t),e.prototype.destroyable=function(){return!0},e.prototype.clonable=function(){return!1},e.prototype.getData=function(){return{type:"end_time",values:this.data.time}},e.prototype.render=function(){return this.elem=e.__super__.render.apply(this,arguments),this.elem.prepend("End time"),this.elem},e}(n),f=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return __extends(n,e),n.prototype.defaults=function(){return this.data.rule_type="IceCube::YearlyRule",this.children=[new g(this)],this.data.interval=1},n.prototype.fromData=function(t){var e,n,r,a;this.data.rule_type=t.rule_type,this.data.interval=t.interval,t.count&&this.children.push(new g(this,{type:"count",value:t.count})),t.until&&this.children.push(new g(this,{type:"until",value:t.until})),r=t.validations,a=[];for(e in r)n=r[e],a.push(this.children.push(new g(this,{type:e,value:n})));return a},n.prototype.getData=function(){var t,e,n,r,a,i,u,o,s,p,c,l,h;for(a={},p=this.children,i=0,o=p.length;o>i;i++)if(t=p[i],"count"!==t.data.type&&"until"!==t.data.type){c=t.getData();for(n in c)r=c[n],a[n]=r}for(e={rule_type:this.data.rule_type,interval:this.data.interval,validations:a},l=this.children,u=0,s=l.length;s>u;u++)if(t=l[u],"count"===t.data.type||"until"===t.data.type){h=t.getData();for(n in h)r=h[n],e[n]=r}return e},n.prototype.render=function(){return this.elem=t('
\n Every\n \n '+s.select(this.data.rule_type,{"IceCube::YearlyRule":"years","IceCube::MonthlyRule":"months","IceCube::WeeklyRule":"weeks","IceCube::DailyRule":"days"})+"\n
"),this.elem.find("input").change(function(t){return function(e){return t.data.interval=parseInt(e.target.value)}}(this)),this.elem.find("select").change(function(t){return function(e){return t.data.rule_type=e.target.value,t.children=[new g(t)],t.triggerRender()}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(h),g=function(n){function o(){return o.__super__.constructor.apply(this,arguments)}return __extends(o,n),o.prototype.defaults=function(){return this.data.type="count",this.children=[new e(this)]},o.prototype.fromData=function(t){var n,a,u,o,s,p,c,l,h,d,f,y,_,g,v;switch(this.data.type=t.type,t.type){case"count":return this.children.push(new e(this,t.value));case"until":return this.children.push(new m(this,t.value));case"day":for(d=t.value,_=[],p=0,l=d.length;l>p;p++)o=d[p],_.push(this.children.push(new r(this,o)));return _;case"day_of_week":f=t.value,g=[];for(a in f)s=f[a],g.push(function(){var t,e,n;for(n=[],t=0,e=s.length;e>t;t++)o=s[t],n.push(this.children.push(new i(this,{nth:o,day:a})));return n}.call(this));return g;default:for(y=t.value,v=[],c=0,h=y.length;h>c;c++)o=y[c],u=this.choices(t.type),n=new u(this,o),v.push(this.children.push(n));return v}},o.prototype.choices=function(t){return{count:e,until:m,day:r,day_of_week:i,day_of_month:a,day_of_year:u,month_of_year:c,offset_from_pascha:l}[t]},o.prototype.getData=function(){var t,e,n,r,a,i;return n=this.data.type,i=function(){var i,u,o,s,p,c,l,h;switch(n){case"count":return this.children[0].getData();case"until":return this.children[0].getData();case"day_of_week":for(r={},p=this.children,i=0,o=p.length;o>i;i++)t=p[i],c=t.getData(),e=c[0],a=c[1],null==r[e]&&(r[e]=[]),r[e].push(a);return r;default:for(l=this.children,h=[],u=0,s=l.length;s>u;u++)t=l[u],h.push(t.getData());return h}}.call(this),r={},r[n]=i,r},o.prototype.destroyable=function(){return!0},o.prototype.render=function(){var e,n;return e='
\n '+(this.parent.children.indexOf(this)>0?"and if":"If")+" \n
",this.elem=t(e),this.elem.find("select").change(function(t){return function(e){var n;return n=t.choices(e.target.value),t.children=[new n(t)],t.data.type=e.target.value,t.triggerRender()}}(this)),this.elem.append(o.__super__.render.apply(this,arguments)),this.elem},o}(h),v=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return __extends(n,e),n.prototype.defaults=function(){return this.data.value=this["default"]},n.prototype.fromData=function(t){return this.data.value=t},n.prototype.getData=function(){return this.data.value},n.prototype.dataTransformer=parseInt,n.prototype["default"]=1,n.prototype.render=function(){return this.elem=t(this.html()),this.elem.find("input,select").change(function(t){return function(e){return t.data.value=t.dataTransformer(e.target.value)}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(h),e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return __extends(e,t),e.prototype.clonable=function(){return!1},e.prototype.html=function(){return'
\n \n day of the month.\n
"},e}(v),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return __extends(e,t),e.prototype.html=function(){var t,e,n,r,a,i;for(n='
\n \n
"},e}(v),i=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return __extends(n,e),n.prototype.getData=function(){return[this.data.day,this.data.nth]},n.prototype.fromData=function(t){this.data=t},n.prototype.defaults=function(){return this.data.nth=1,this.data.day=0},n.prototype.render=function(){var e,r,a,i,u,o,p;for(i='
\n \n \n
",this.elem=t(a),this.elem.find("input,select").change(function(t){return function(){return t.data.value=t.elem.find("select").val()}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(h),l=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return __extends(n,e),n.prototype.getData=function(){return this.data.value},n.prototype.defaults=function(){return this.data.value=0},n.prototype.fromData=function(t){return this.data.value=t},n.prototype.render=function(){var e;return e='
\n "+e+""},select:function(t,e){var n,r,i;r=""}},c=function(){function e(t,e){this.parent=t,null==e&&(e=null),this.destroy=bind(this.destroy,this),this.clone=bind(this.clone,this),this.children=[],this.data={},"__clone"!==e&&(null!=e?this.fromData(e):this.defaults())}return e.prototype.fromData=function(t){},e.prototype.defaults=function(){},e.prototype.clonable=function(){return!0},e.prototype.destroyable=function(){return this.parent.children.length>1},e.prototype.clone=function(){return this.parent.children.push(s.clone(this)),this.triggerRender()},e.prototype.destroy=function(){return this.elem.slideUp(100,function(t){return function(){return t.parent.children.splice(t.parent.children.indexOf(t),1),t.parent.triggerRender()}}(this))},e.prototype.render=function(){var e;return e=t("
"),this.clonable()&&e.append(t("+").click(this.clone)),this.destroyable()&&e.append(t("-").click(this.destroy)),e.append(this.renderChildren()),e.children()},e.prototype.renderChildren=function(){var t,e,n,r,i;for(r=this.children,i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(t.render());return i},e.prototype.triggerRender=function(){return this.parent.triggerRender()},e}(),d=function(e){function n(){n.__super__.constructor.apply(this,arguments),this.parent.after("
"),this.target=this.parent.siblings(".icui").first()}return extend(n,e),n.prototype.clonable=function(){return!1},n.prototype.destroyable=function(){return!1},n.prototype.has_ending_time=!1,n.prototype.has_rules=!1,n.prototype.fromData=function(t){var e,n,r;this.children.push(new y(this,t.start_time)),t.end_time&&(this.has_ending_time=!0,this.children.push(new o(this,t.end_time))),n=[];for(e in t)r=t[e],r.length>0&&"start_time"!==e&&"end_time"!==e&&(this.has_rules=!0,n.push(this.children.push(new _(this,{type:e,values:r}))));return n},n.prototype.defaults=function(){return this.children.push(new y(this))},n.prototype.triggerRender=function(){return this.render()},n.prototype.render=function(){var e;return this.target.html(this.renderChildren()),this.has_ending_time||(e=t("Add Ending Time "),e.click(function(t){return function(){return t.has_ending_time=!0,e.hide(),t.children.push(new o(t)),t.triggerRender(),!1}}(this)),this.target.append(e),this.target.append("
")),this.has_rules?void 0:(e=t("Add Repetition"),e.click(function(t){return function(){return t.has_rules=!0,e.hide(),t.children.push(new _(t)),t.triggerRender(),!1}}(this)),this.target.append(e))},n.prototype.getData=function(){var t,e,n,r,i,a;for(n={},a=this.children,r=0,i=a.length;i>r;r++)t=a[r],e=t.getData(),n[e.type]?n[e.type]=n[e.type].concat(e.values):n[e.type]=e.values;return n},n}(c),_=function(e){function r(){return r.__super__.constructor.apply(this,arguments)}return extend(r,e),r.prototype.defaults=function(){return this.data.type="rtimes",this.children=[new n(this)]},r.prototype.fromData=function(t){var e,r,i,a,u,o,s,p,h;if(this.data.type=t.type,this.data.type.match(/times$/)){for(u=t.values,s=[],e=0,i=u.length;i>e;e++)h=u[e],s.push(this.children.push(new n(this,h)));return s}for(o=t.values,p=[],r=0,a=o.length;a>r;r++)h=o[r],p.push(this.children.push(new f(this,h)));return p},r.prototype.getData=function(){var t,e;return this.data.type.match(/times$/)?(e=function(){var e,n,r,i;for(r=this.children,i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(t.getData().time);return i}.call(this),{type:this.data.type,values:e}):(e=function(){var e,n,r,i;for(r=this.children,i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(t.getData());return i}.call(this),{type:this.data.type,values:e})},r.prototype.render=function(){var e;return this.elem=t('
Event on \n
"),e=this.elem.find("select"),e.first().change(function(t){return function(e){return"1"===e.target.value?t.data.type=t.data.type.replace(/^ex/,"r"):t.data.type=t.data.type.replace(/^r/,"ex")}}(this)),e.last().change(function(t){return function(e){return"dates"===e.target.value?(t.data.type.match(/^r/)?t.data.type="rtimes":t.data.type="extimes",t.children=[new n(t)]):(t.data.type.match(/^r/)?t.data.type="rrules":t.data.type="exrules",t.children=[new f(t)]),t.triggerRender()}}(this)),this.elem.append(r.__super__.render.apply(this,arguments)),this.elem},r}(c),n=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return extend(n,e),n.prototype.defaults=function(){var t;return null!=(t=this.data).moment?t.moment:t.moment=moment()},n.prototype.fromData=function(t){return this.data.moment=moment(t)},n.prototype.getData=function(){return this.data},n.prototype.render=function(){var e,r,i;return this.elem=t('
\n \n \n
'),r=this.elem.find("input"),e=r.first(),i=r.last(),r.change(function(t){return function(n){return t.data.moment=moment(e.val()+" "+i.val(),"L LT")}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(c),y=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return extend(e,t),e.prototype.destroyable=function(){return!1},e.prototype.clonable=function(){return!1},e.prototype.getData=function(){return{type:"start_time",values:this.data.moment.format()}},e.prototype.render=function(){return this.elem=e.__super__.render.apply(this,arguments),this.elem.prepend("Start time"),this.elem},e}(n),o=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return extend(e,t),e.prototype.destroyable=function(){return!0},e.prototype.clonable=function(){return!1},e.prototype.getData=function(){return{type:"end_time",values:this.data.moment.format()}},e.prototype.render=function(){return this.elem=e.__super__.render.apply(this,arguments),this.elem.prepend("End time"),this.elem},e}(n),f=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return extend(n,e),n.prototype.defaults=function(){return this.data.rule_type="IceCube::YearlyRule",this.children=[new v(this)],this.data.interval=1},n.prototype.fromData=function(t){var e,n,r,i;this.data.rule_type=t.rule_type,this.data.interval=t.interval,t.count&&this.children.push(new v(this,{type:"count",value:t.count})),t.until&&this.children.push(new v(this,{type:"until",value:t.until})),n=t.validations,r=[];for(e in n)i=n[e],r.push(this.children.push(new v(this,{type:e,value:i})));return r},n.prototype.getData=function(){var t,e,n,r,i,a,u,o,s,p,h,l,c;for(c={},o=this.children,n=0,a=o.length;a>n;n++)if(t=o[n],"count"!==t.data.type&&"until"!==t.data.type){s=t.getData();for(r in s)l=s[r],c[r]=l}for(e={rule_type:this.data.rule_type,interval:this.data.interval,validations:c},p=this.children,i=0,u=p.length;u>i;i++)if(t=p[i],"count"===t.data.type||"until"===t.data.type){h=t.getData();for(r in h)l=h[r],e[r]=l}return e},n.prototype.render=function(){return this.elem=t('
\n Every\n \n '+s.select(this.data.rule_type,{"IceCube::YearlyRule":"years","IceCube::MonthlyRule":"months","IceCube::WeeklyRule":"weeks","IceCube::DailyRule":"days"})+"\n
"),this.elem.find("input").change(function(t){return function(e){return t.data.interval=parseInt(e.target.value)}}(this)),this.elem.find("select").change(function(t){return function(e){return t.data.rule_type=e.target.value,t.children=[new v(t)],t.triggerRender()}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(c),v=function(n){function o(){return o.__super__.constructor.apply(this,arguments)}return extend(o,n),o.prototype.defaults=function(){return this.data.type="count",this.children=[new e(this)]},o.prototype.fromData=function(t){var n,i,u,o,s,p,h,l,c,d,f,y,_,v,g;switch(this.data.type=t.type,t.type){case"count":return this.children.push(new e(this,t.value));case"until":return this.children.push(new m(this,t.value));case"day":for(l=t.value,f=[],i=0,p=l.length;p>i;i++)v=l[i],f.push(this.children.push(new r(this,v)));return f;case"day_of_week":c=t.value,y=[];for(u in c)g=c[u],y.push(function(){var t,e,n;for(n=[],t=0,e=g.length;e>t;t++)v=g[t],n.push(this.children.push(new a(this,{nth:v,day:u})));return n}.call(this));return y;default:for(d=t.value,_=[],s=0,h=d.length;h>s;s++)v=d[s],o=this.choices(t.type),n=new o(this,v),_.push(this.children.push(n));return _}},o.prototype.choices=function(t){return{count:e,until:m,day:r,day_of_week:a,day_of_month:i,day_of_year:u,month_of_year:h,offset_from_pascha:l}[t]},o.prototype.getData=function(){var t,e,n,r,i,a;return n=this.data.type,a=function(){var a,u,o,s,p,h,l,c;switch(n){case"count":return this.children[0].getData();case"until":return this.children[0].getData();case"day_of_week":for(r={},p=this.children,a=0,o=p.length;o>a;a++)t=p[a],h=t.getData(),e=h[0],i=h[1],null==r[e]&&(r[e]=[]),r[e].push(i);return r;default:for(l=this.children,c=[],u=0,s=l.length;s>u;u++)t=l[u],c.push(t.getData());return c}}.call(this),r={},r[n]=a,r},o.prototype.destroyable=function(){return!0},o.prototype.render=function(){var e,n;return n='
\n '+(this.parent.children.indexOf(this)>0?"and if":"If")+" \n
",this.elem=t(n),this.elem.find("select").change(function(t){return function(e){var n;return n=t.choices(e.target.value),t.children=[new n(t)],t.data.type=e.target.value,t.triggerRender()}}(this)),this.elem.append(o.__super__.render.apply(this,arguments)),this.elem},o}(c),g=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return extend(n,e),n.prototype.defaults=function(){return this.data.value=this["default"]},n.prototype.fromData=function(t){return this.data.value=t},n.prototype.getData=function(){return this.data.value},n.prototype.dataTransformer=parseInt,n.prototype["default"]=1,n.prototype.render=function(){return this.elem=t(this.html()),this.elem.find("input,select").change(function(t){return function(e){return t.data.value=t.dataTransformer(e.target.value)}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(c),e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return extend(e,t),e.prototype.clonable=function(){return!1},e.prototype.html=function(){return'
\n \n day of the month.\n
"},e}(g),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return extend(e,t),e.prototype.html=function(){var t,e,n,r,i,a;for(a='
\n \n
"},e}(g),a=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return extend(n,e),n.prototype.getData=function(){return[this.data.day,this.data.nth]},n.prototype.fromData=function(t){this.data=t},n.prototype.defaults=function(){return this.data.nth=1,this.data.day=0},n.prototype.render=function(){var e,r,i,a,u,o,p;for(p='
\n \n \n
",this.elem=t(o),this.elem.find("input,select").change(function(t){return function(e){return t.data.value=t.elem.find("select").val()}}(this)),this.elem.append(n.__super__.render.apply(this,arguments)),this.elem},n}(c),l=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return extend(n,e),n.prototype.getData=function(){return this.data.value},n.prototype.defaults=function(){return this.data.value=0},n.prototype.fromData=function(t){return this.data.value=t},n.prototype.render=function(){var e;return e='
\n = 0 then m - 1 else 11 - tz = (new Date).getTimezoneOffset() - new Date(Date.UTC(y, m, d, h, min, 0, 0)) - # The Base Class # -------------- # @@ -143,11 +131,11 @@ do ($ = jQuery) -> @target = @parent.siblings('.icui').first() fromData: (d) -> - @children.push new StartDate(@, d["start_date"]) + @children.push new StartDate(@, d["start_time"]) if d["end_time"] @has_ending_time = yes @children.push new EndTime(@, d["end_time"]) - for k,v of d when v.length > 0 and k != "start_date" and k != "end_time" + for k,v of d when v.length > 0 and k != "start_time" and k != "end_time" @has_rules = yes @children.push new TopLevel(@, {type: k, values: v}) @@ -281,23 +269,23 @@ do ($ = jQuery) -> # user interface, however we could probably easily extend this to use # something like jQuery UI. class DatePicker extends Option - defaults: -> @data.time ?= new Date + defaults: -> @data.moment ?= moment() - fromData: (d) -> @data.time = Helpers.dateFromString d + fromData: (d) -> @data.moment = moment d getData: -> @data render: -> @elem = $("""
- - + +
""") ss = @elem.find('input') date = ss.first() time = ss.last() ss.change (e) => - @data.time = Helpers.dateFromString date.val() + ' ' + time.val() + @data.moment = moment(date.val() + ' ' + time.val(), 'L LT') @elem.append super @elem @@ -308,7 +296,7 @@ do ($ = jQuery) -> class StartDate extends DatePicker destroyable: -> false clonable: -> false - getData: -> {type: "start_date", values: @data.time} + getData: -> {type: "start_time", values: @data.moment.format()} render: -> @elem = super @@ -322,7 +310,7 @@ do ($ = jQuery) -> class EndTime extends DatePicker destroyable: -> true clonable: -> false - getData: -> {type: "end_time", values: @data.time} + getData: -> {type: "end_time", values: @data.moment.format()} render: -> @elem = super @@ -513,7 +501,7 @@ do ($ = jQuery) -> # ----- # Until will repeat the event until a specified date. class Until extends DatePicker - getData: -> @data.time + getData: -> @data.moment.format() clonable: -> false destroyable: -> false @@ -546,7 +534,7 @@ do ($ = jQuery) -> str = """
@@ -566,7 +554,7 @@ do ($ = jQuery) ->
nth.
" @elem = $ str @@ -618,7 +606,7 @@ do ($ = jQuery) -> str = """
" @elem = $ str diff --git a/lib/strftime.js b/lib/strftime.js deleted file mode 100644 index a6c8ae9..0000000 --- a/lib/strftime.js +++ /dev/null @@ -1,225 +0,0 @@ -// Written by Gianni Chiappetta - gianni[at]runlevel6[dot]org -// Released under the WTFPL - -if (typeof Date.prototype.strftime == 'undefined') { - /** - * Date#strftime(format) -> String - * - format (String): Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string. - * - * Ruby-style date formatting. Format matchers: - * - * %a - The abbreviated weekday name (``Sun'') - * %A - The full weekday name (``Sunday'') - * %b - The abbreviated month name (``Jan'') - * %B - The full month name (``January'') - * %c - The preferred local date and time representation - * %d - Day of the month (01..31) - * %e - Day of the month without leading zeroes (1..31) - * %H - Hour of the day, 24-hour clock (00..23) - * %I - Hour of the day, 12-hour clock (01..12) - * %j - Day of the year (001..366) - * %k - Hour of the day, 24-hour clock w/o leading zeroes (0..23) - * %l - Hour of the day, 12-hour clock w/o leading zeroes (1..12) - * %m - Month of the year (01..12) - * %M - Minute of the hour (00..59) - * %p - Meridian indicator (``AM'' or ``PM'') - * %P - Meridian indicator (``am'' or ``pm'') - * %S - Second of the minute (00..60) - * %U - Week number of the current year, - * starting with the first Sunday as the first - * day of the first week (00..53) - * %W - Week number of the current year, - * starting with the first Monday as the first - * day of the first week (00..53) - * %w - Day of the week (Sunday is 0, 0..6) - * %x - Preferred representation for the date alone, no time - * %X - Preferred representation for the time alone, no date - * %y - Year without a century (00..99) - * %Y - Year with century - * %Z - Time zone name - * %z - Time zone expressed as a UTC offset (``-04:00'') - * %% - Literal ``%'' character - * - * http://www.ruby-doc.org/core/classes/Time.html#M000298 - * - **/ - - Date.prototype.strftime = (function(){ - var cache = {'start_of_year': new Date("Jan 1 " + (new Date()).getFullYear())}, - regexp = /%([a-z]|%)/mig, - day_in_ms = 1000 * 60 * 60 * 24, - days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], - months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], - abbr_days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], - abbr_months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], - formats = { - 'a': weekday_name_abbr, - 'A': weekday_name, - 'b': month_name_abbr, - 'B': month_name, - 'c': default_local, - 'd': day_padded, - 'e': day, - 'H': hour_24_padded, - 'I': hour_padded, - 'j': day_of_year, - 'k': hour_24, - 'l': hour, - 'm': month, - 'M': minute, - 'p': meridian_upcase, - 'P': meridian, - 'S': second, - 'U': week_number_from_sunday, - // 'W': week_number_from_monday, - 'w': day_of_week, - 'x': default_local_date, - 'X': default_local_time, - 'y': year_abbr, - 'Y': year, - // 'Z': time_zone_name, - 'z': time_zone_offset, - '%': function() { return '%'; } - }; - - // day - function day(date) { - return date.getUTCDate() + ''; - } - - // day_of_week - function day_of_week(date) { - return date.getUTCDay() + ''; - } - - // day_of_year - function day_of_year(date) { - return (((date.getTime() - cache['start_of_year'].getTime()) / day_in_ms + 1) + '').split(/\./)[0]; - } - - // day_padded - function day_padded(date) { - return ('0' + day(date)).slice(-2); - } - - // default_local - function default_local(date) { - return date.toLocaleString(); - } - - // default_local_date - function default_local_date(date) { - return date.toLocaleDateString(); - } - - // default_local_time - function default_local_time(date) { - return date.toLocaleTimeString(); - } - - // hour - function hour(date) { - var hour = date.getUTCHours(); - - if (hour === 0) hour = 12; - else if (hour > 12) hour -= 12; - - return hour + ''; - } - - // hour_24 - function hour_24(date) { - return date.getUTCHours(); - } - - // hour_24_padded - function hour_24_padded(date) { - return ('0' + hour_24(date)).slice(-2); - } - - // hour_padded - function hour_padded(date) { - return ('0' + hour(date)).slice(-2); - } - - // meridian - function meridian(date) { - return date.getUTCHours() >= 12 ? 'pm' : 'am'; - } - - // meridian_upcase - function meridian_upcase(date) { - return meridian(date).toUpperCase(); - } - - // minute - function minute(date) { - return ('0' + date.getUTCMinutes()).slice(-2); - } - - // month - function month(date) { - return ('0'+(date.getUTCMonth()+1)).slice(-2); - } - - // month_name - function month_name(date) { - return months[date.getUTCMonth()]; - } - - // month_name_abbr - function month_name_abbr(date) { - return abbr_months[date.getUTCMonth()]; - } - - // second - function second(date) { - return ('0' + date.getUTCSeconds()).slice(-2); - } - - // time_zone_offset - function time_zone_offset(date) { - var tz_offset = date.getTimezoneOffset(); - return (tz_offset >= 0 ? '-' : '') + ('0' + (tz_offset / 60)).slice(-2) + ':' + ('0' + (tz_offset % 60)).slice(-2); - } - - // week_number_from_sunday - function week_number_from_sunday(date) { - return ('0' + Math.round(parseInt(day_of_year(date), 10) / 7)).slice(-2); - } - - // weekday_name - function weekday_name(date) { - return days[date.getUTCDay()]; - } - - // weekday_name_abbr - function weekday_name_abbr(date) { - return abbr_days[date.getUTCDay()]; - } - - // year - function year(date) { - return date.getUTCFullYear() + ''; - } - - // year_abbr - function year_abbr(date) { - return year(date).slice(-2); - } - - /*------------------------------ Main ------------------------------*/ - function strftime(format) { - var match, output = format; - cache['start_of_year'] = new Date("Jan 1 " + this.getUTCFullYear()); - - while (match = regexp.exec(format)) { - if (match[1] in formats) output = output.replace(new RegExp(match[0], 'mg'), formats[match[1]](this)); - } - - return output; - } - - return strftime; - })(); -} \ No newline at end of file