)""", '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('
\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 = """