webroar 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG +18 -1
  2. data/README +86 -0
  3. data/doc/user-guide.html +116 -74
  4. data/doc/user-guide.txt +3 -2
  5. data/lib/dependencies.rb +1 -1
  6. data/src/admin_panel/config/environment.rb +1 -1
  7. data/src/admin_panel/public/blank_iframe.html +2 -0
  8. data/src/admin_panel/public/images/calendar_date_select/calendar.gif +0 -0
  9. data/src/admin_panel/public/javascripts/calendar_date_select/calendar_date_select.js +443 -0
  10. data/src/admin_panel/public/javascripts/calendar_date_select/format_american.js +34 -0
  11. data/src/admin_panel/public/javascripts/calendar_date_select/format_db.js +27 -0
  12. data/src/admin_panel/public/javascripts/calendar_date_select/format_euro_24hr.js +7 -0
  13. data/src/admin_panel/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js +7 -0
  14. data/src/admin_panel/public/javascripts/calendar_date_select/format_finnish.js +32 -0
  15. data/src/admin_panel/public/javascripts/calendar_date_select/format_hyphen_ampm.js +37 -0
  16. data/src/admin_panel/public/javascripts/calendar_date_select/format_iso_date.js +46 -0
  17. data/src/admin_panel/public/javascripts/calendar_date_select/format_italian.js +24 -0
  18. data/src/admin_panel/public/javascripts/calendar_date_select/locale/de.js +11 -0
  19. data/src/admin_panel/public/javascripts/calendar_date_select/locale/fi.js +10 -0
  20. data/src/admin_panel/public/javascripts/calendar_date_select/locale/fr.js +10 -0
  21. data/src/admin_panel/public/javascripts/calendar_date_select/locale/pl.js +10 -0
  22. data/src/admin_panel/public/javascripts/calendar_date_select/locale/pt.js +11 -0
  23. data/src/admin_panel/public/javascripts/calendar_date_select/locale/ru.js +10 -0
  24. data/src/admin_panel/public/stylesheets/calendar_date_select/blue.css +130 -0
  25. data/src/admin_panel/public/stylesheets/calendar_date_select/default.css +135 -0
  26. data/src/admin_panel/public/stylesheets/calendar_date_select/plain.css +128 -0
  27. data/src/admin_panel/public/stylesheets/calendar_date_select/red.css +135 -0
  28. data/src/admin_panel/public/stylesheets/calendar_date_select/silver.css +133 -0
  29. data/src/head/wr_config.h +1 -1
  30. data/src/ruby_lib/analyzer/db_connect.rb +3 -3
  31. data/src/ruby_lib/mailer/smtpmail.rb +3 -3
  32. data/src/ruby_lib/ruby_interface/version.rb +1 -1
  33. data/src/ruby_lib/webroar_app_loader.rb +62 -57
  34. data/src/worker/wkr_http.c +5 -137
  35. data/src/worker/wkr_main.c +2 -2
  36. data/tasks/gem.rake +4 -3
  37. data/tasks/test.rake +4 -2
  38. data/test/spec/test_app/config/environment.rb +1 -1
  39. metadata +33 -94
@@ -0,0 +1,443 @@
1
+ // CalendarDateSelect version 1.15 - a prototype based date picker
2
+ // Questions, comments, bugs? - see the project page: http://code.google.com/p/calendardateselect
3
+ if (typeof Prototype == 'undefined') alert("CalendarDateSelect Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (.g. <%= javascript_include_tag :defaults %>) *before* it includes calendar_date_select.js (.g. <%= calendar_date_select_includes %>).");
4
+ if (Prototype.Version < "1.6") alert("Prototype 1.6.0 is required. If using earlier version of prototype, please use calendar_date_select version 1.8.3");
5
+
6
+ Element.addMethods({
7
+ purgeChildren: function(element) { $A(element.childNodes).each(function(e){$(e).remove();}); },
8
+ build: function(element, type, options, style) {
9
+ var newElement = Element.buildAndAppend(type, options, style);
10
+ element.appendChild(newElement);
11
+ return newElement;
12
+ }
13
+ });
14
+
15
+ Element.buildAndAppend = function(type, options, style)
16
+ {
17
+ var e = $(document.createElement(type));
18
+ $H(options).each(function(pair) { e[pair.key] = pair.value });
19
+ if (style) e.setStyle(style);
20
+ return e;
21
+ };
22
+ nil = null;
23
+
24
+ Date.one_day = 24*60*60*1000;
25
+ Date.weekdays = $w("S M T W T F S");
26
+ Date.first_day_of_week = 0;
27
+ Date.months = $w("January February March April May June July August September October November December" );
28
+ Date.padded2 = function(hour) { var padded2 = parseInt(hour, 10); if (hour < 10) padded2 = "0" + padded2; return padded2; }
29
+ Date.prototype.getPaddedMinutes = function() { return Date.padded2(this.getMinutes()); }
30
+ Date.prototype.getAMPMHour = function() { var hour = this.getHours(); return (hour == 0) ? 12 : (hour > 12 ? hour - 12 : hour ) }
31
+ Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "AM" : "PM"; }
32
+ Date.prototype.stripTime = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate());};
33
+ Date.prototype.daysDistance = function(compare_date) { return Math.round((compare_date - this) / Date.one_day); };
34
+ Date.prototype.toFormattedString = function(include_time){
35
+ var hour, str;
36
+ str = Date.months[this.getMonth()] + " " + this.getDate() + ", " + this.getFullYear();
37
+
38
+ if (include_time) { hour = this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() + " " + this.getAMPM() }
39
+ return str;
40
+ }
41
+ Date.parseFormattedString = function(string) { return new Date(string);}
42
+ Math.floor_to_interval = function(n, i) { return Math.floor(n/i) * i;}
43
+ window.f_height = function() { return( [window.innerHeight ? window.innerHeight : null, document.documentElement ? document.documentElement.clientHeight : null, document.body ? document.body.clientHeight : null].select(function(x){return x>0}).first()||0); }
44
+ window.f_scrollTop = function() { return ([window.pageYOffset ? window.pageYOffset : null, document.documentElement ? document.documentElement.scrollTop : null, document.body ? document.body.scrollTop : null].select(function(x){return x>0}).first()||0 ); }
45
+
46
+ _translations = {
47
+ "OK": "OK",
48
+ "Now": "Now",
49
+ "Today": "Today",
50
+ "Clear": "Clear"
51
+ }
52
+ SelectBox = Class.create();
53
+ SelectBox.prototype = {
54
+ initialize: function(parent_element, values, html_options, style_options) {
55
+ this.element = $(parent_element).build("select", html_options, style_options);
56
+ this.populate(values);
57
+ },
58
+ populate: function(values) {
59
+ this.element.purgeChildren();
60
+ var that = this; $A(values).each(function(pair) { if (typeof(pair)!="object") {pair = [pair, pair]}; that.element.build("option", { value: pair[1], innerHTML: pair[0]}) });
61
+ },
62
+ setValue: function(value) {
63
+ var e = this.element;
64
+ var matched = false;
65
+ $R(0, e.options.length - 1 ).each(function(i) { if(e.options[i].value==value.toString()) {e.selectedIndex = i; matched = true;}; } );
66
+ return matched;
67
+ },
68
+ getValue: function() { return $F(this.element)}
69
+ }
70
+ CalendarDateSelect = Class.create();
71
+ CalendarDateSelect.prototype = {
72
+ initialize: function(target_element, options) {
73
+ this.target_element = $(target_element); // make sure it's an element, not a string
74
+ if (!this.target_element) { alert("Target element " + target_element + " not found!"); return false;}
75
+ if (this.target_element.tagName != "INPUT") this.target_element = this.target_element.down("INPUT")
76
+
77
+ this.target_element.calendar_date_select = this;
78
+ this.last_click_at = 0;
79
+ // initialize the date control
80
+ this.options = $H({
81
+ embedded: false,
82
+ popup: nil,
83
+ time: false,
84
+ buttons: true,
85
+ clear_button: true,
86
+ year_range: 10,
87
+ close_on_click: nil,
88
+ minute_interval: 5,
89
+ popup_by: this.target_element,
90
+ month_year: "dropdowns",
91
+ onchange: this.target_element.onchange,
92
+ valid_date_check: nil
93
+ }).merge(options || {});
94
+ this.use_time = this.options.get("time");
95
+ this.parseDate();
96
+ this.callback("before_show")
97
+ this.initCalendarDiv();
98
+ if(!this.options.get("embedded")) {
99
+ this.positionCalendarDiv()
100
+ // set the click handler to check if a user has clicked away from the document
101
+ Event.observe(document, "mousedown", this.closeIfClickedOut_handler = this.closeIfClickedOut.bindAsEventListener(this));
102
+ Event.observe(document, "keypress", this.keyPress_handler = this.keyPress.bindAsEventListener(this));
103
+ }
104
+ this.callback("after_show")
105
+ },
106
+ positionCalendarDiv: function() {
107
+ var above = false;
108
+ var c_pos = this.calendar_div.cumulativeOffset(), c_left = c_pos[0], c_top = c_pos[1], c_dim = this.calendar_div.getDimensions(), c_height = c_dim.height, c_width = c_dim.width;
109
+ var w_top = window.f_scrollTop(), w_height = window.f_height();
110
+ var e_dim = $(this.options.get("popup_by")).cumulativeOffset(), e_top = e_dim[1], e_left = e_dim[0], e_height = $(this.options.get("popup_by")).getDimensions().height, e_bottom = e_top + e_height;
111
+
112
+ if ( (( e_bottom + c_height ) > (w_top + w_height)) && ( e_bottom - c_height > w_top )) above = true;
113
+ var left_px = e_left.toString() + "px", top_px = (above ? (e_top - c_height ) : ( e_top + e_height )).toString() + "px";
114
+
115
+ this.calendar_div.style.left = left_px; this.calendar_div.style.top = top_px;
116
+
117
+ this.calendar_div.setStyle({visibility:""});
118
+
119
+ // draw an iframe behind the calendar -- ugly hack to make IE 6 happy
120
+ if(navigator.appName=="Microsoft Internet Explorer") this.iframe = $(document.body).build("iframe", {src: "javascript:false", className: "ie6_blocker"}, { left: left_px, top: top_px, height: c_height.toString()+"px", width: c_width.toString()+"px", border: "0px"})
121
+ },
122
+ initCalendarDiv: function() {
123
+ if (this.options.get("embedded")) {
124
+ var parent = this.target_element.parentNode;
125
+ var style = {}
126
+ } else {
127
+ var parent = document.body
128
+ var style = { position:"absolute", visibility: "hidden", left:0, top:0 }
129
+ }
130
+ this.calendar_div = $(parent).build('div', {className: "calendar_date_select"}, style);
131
+
132
+ var that = this;
133
+ // create the divs
134
+ $w("top header body buttons footer bottom").each(function(name) {
135
+ eval("var " + name + "_div = that." + name + "_div = that.calendar_div.build('div', { className: 'cds_"+name+"' }, { clear: 'left'} ); ");
136
+ });
137
+
138
+ this.initHeaderDiv();
139
+ this.initButtonsDiv();
140
+ this.initCalendarGrid();
141
+ this.updateFooter("&#160;");
142
+
143
+ this.refresh();
144
+ this.setUseTime(this.use_time);
145
+ },
146
+ initHeaderDiv: function() {
147
+ var header_div = this.header_div;
148
+ this.close_button = header_div.build("a", { innerHTML: "x", href:"#", onclick:function () { this.close(); return false; }.bindAsEventListener(this), className: "close" });
149
+ this.next_month_button = header_div.build("a", { innerHTML: "&gt;", href:"#", onclick:function () { this.navMonth(this.date.getMonth() + 1 ); return false; }.bindAsEventListener(this), className: "next" });
150
+ this.prev_month_button = header_div.build("a", { innerHTML: "&lt;", href:"#", onclick:function () { this.navMonth(this.date.getMonth() - 1 ); return false; }.bindAsEventListener(this), className: "prev" });
151
+
152
+ if (this.options.get("month_year")=="dropdowns") {
153
+ this.month_select = new SelectBox(header_div, $R(0,11).map(function(m){return [Date.months[m], m]}), {className: "month", onchange: function () { this.navMonth(this.month_select.getValue()) }.bindAsEventListener(this)});
154
+ this.year_select = new SelectBox(header_div, [], {className: "year", onchange: function () { this.navYear(this.year_select.getValue()) }.bindAsEventListener(this)});
155
+ this.populateYearRange();
156
+ } else {
157
+ this.month_year_label = header_div.build("span")
158
+ }
159
+ },
160
+ initCalendarGrid: function() {
161
+ var body_div = this.body_div;
162
+ this.calendar_day_grid = [];
163
+ var days_table = body_div.build("table", { cellPadding: "0px", cellSpacing: "0px", width: "100%" })
164
+ // make the weekdays!
165
+ var weekdays_row = days_table.build("thead").build("tr");
166
+ Date.weekdays.each( function(weekday) {
167
+ weekdays_row.build("th", {innerHTML: weekday});
168
+ });
169
+
170
+ var days_tbody = days_table.build("tbody")
171
+ // Make the days!
172
+ var row_number = 0, weekday;
173
+ for(var cell_index = 0; cell_index<42; cell_index++)
174
+ {
175
+ weekday = (cell_index+Date.first_day_of_week ) % 7;
176
+ if ( cell_index % 7==0 ) days_row = days_tbody.build("tr", {className: 'row_'+row_number++});
177
+ (this.calendar_day_grid[cell_index] = days_row.build("td", {
178
+ calendar_date_select: this,
179
+ onmouseover: function () { this.calendar_date_select.dayHover(this); },
180
+ onmouseout: function () { this.calendar_date_select.dayHoverOut(this) },
181
+ onclick: function() { this.calendar_date_select.updateSelectedDate(this, true); },
182
+ className: (weekday==0) || (weekday==6) ? " weekend" : "" //clear the class
183
+ },
184
+ { cursor: "pointer" }
185
+ )).build("div");
186
+ this.calendar_day_grid[cell_index];
187
+ }
188
+ },
189
+ initButtonsDiv: function()
190
+ {
191
+ var buttons_div = this.buttons_div;
192
+ if (this.options.get("time"))
193
+ {
194
+ var blank_time = $A(this.options.get("time")=="mixed" ? [[" - ", ""]] : []);
195
+ buttons_div.build("span", {innerHTML:"@", className: "at_sign"});
196
+
197
+ var t = new Date();
198
+ this.hour_select = new SelectBox(buttons_div,
199
+ blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getAMPMHour()+ " " + t.getAMPM(),x])} )),
200
+ {
201
+ calendar_date_select: this,
202
+ onchange: function() { this.calendar_date_select.updateSelectedDate( { hour: this.value });},
203
+ className: "hour"
204
+ }
205
+ );
206
+ buttons_div.build("span", {innerHTML:":", className: "seperator"});
207
+ var that = this;
208
+ this.minute_select = new SelectBox(buttons_div,
209
+ blank_time.concat($R(0,59).select(function(x){return (x % that.options.get('minute_interval')==0)}).map(function(x){ return $A([ Date.padded2(x), x]); } ) ),
210
+ {
211
+ calendar_date_select: this,
212
+ onchange: function() { this.calendar_date_select.updateSelectedDate( {minute: this.value }) },
213
+ className: "minute"
214
+ }
215
+ );
216
+
217
+ } else if (! this.options.get("buttons")) buttons_div.remove();
218
+
219
+ if (this.options.get("buttons")) {
220
+ buttons_div.build("span", {innerHTML: "&#160;"});
221
+ if (this.options.get("time")=="mixed" || !this.options.get("time")) b = buttons_div.build("a", {
222
+ innerHTML: _translations["Today"],
223
+ href: "#",
224
+ onclick: function() {this.today(false); return false;}.bindAsEventListener(this)
225
+ });
226
+
227
+ if (this.options.get("time")=="mixed") buttons_div.build("span", {innerHTML: "&#160;|&#160;", className:"button_seperator"})
228
+
229
+ if (this.options.get("time")) b = buttons_div.build("a", {
230
+ innerHTML: _translations["Now"],
231
+ href: "#",
232
+ onclick: function() {this.today(true); return false}.bindAsEventListener(this)
233
+ });
234
+
235
+ if (!this.options.get("embedded") && !this.closeOnClick())
236
+ {
237
+ buttons_div.build("span", {innerHTML: "&#160;|&#160;", className:"button_seperator"})
238
+ buttons_div.build("a", { innerHTML: _translations["OK"], href: "#", onclick: function() {this.close(); return false;}.bindAsEventListener(this) });
239
+ }
240
+ if (this.options.get('clear_button')) {
241
+ buttons_div.build("span", {innerHTML: "&#160;|&#160;", className:"button_seperator"})
242
+ buttons_div.build("a", { innerHTML: _translations["Clear"], href: "#", onclick: function() {this.clearDate(); if (!this.options.get("embedded")) this.close(); return false;}.bindAsEventListener(this) });
243
+ }
244
+ }
245
+ },
246
+ refresh: function ()
247
+ {
248
+ this.refreshMonthYear();
249
+ this.refreshCalendarGrid();
250
+
251
+ this.setSelectedClass();
252
+ this.updateFooter();
253
+ },
254
+ refreshCalendarGrid: function () {
255
+ this.beginning_date = new Date(this.date).stripTime();
256
+ this.beginning_date.setDate(1);
257
+ this.beginning_date.setHours(12); // Prevent daylight savings time boundaries from showing a duplicate day
258
+ var pre_days = this.beginning_date.getDay() // draw some days before the fact
259
+ if (pre_days < 3) pre_days += 7;
260
+ this.beginning_date.setDate(1 - pre_days + Date.first_day_of_week);
261
+
262
+ var iterator = new Date(this.beginning_date);
263
+
264
+ var today = new Date().stripTime();
265
+ var this_month = this.date.getMonth();
266
+ vdc = this.options.get("valid_date_check");
267
+ for (var cell_index = 0;cell_index<42; cell_index++)
268
+ {
269
+ day = iterator.getDate(); month = iterator.getMonth();
270
+ cell = this.calendar_day_grid[cell_index];
271
+ Element.remove(cell.childNodes[0]); div = cell.build("div", {innerHTML:day});
272
+ if (month!=this_month) div.className = "other";
273
+ cell.day = day; cell.month = month; cell.year = iterator.getFullYear();
274
+ if (vdc) { if (vdc(iterator.stripTime())) cell.removeClassName("disabled"); else cell.addClassName("disabled") };
275
+ iterator.setDate( day + 1);
276
+ }
277
+
278
+ if (this.today_cell) this.today_cell.removeClassName("today");
279
+
280
+ if ( $R( 0, 41 ).include(days_until = this.beginning_date.stripTime().daysDistance(today)) ) {
281
+ this.today_cell = this.calendar_day_grid[days_until];
282
+ this.today_cell.addClassName("today");
283
+ }
284
+ },
285
+ refreshMonthYear: function() {
286
+ var m = this.date.getMonth();
287
+ var y = this.date.getFullYear();
288
+ // set the month
289
+ if (this.options.get("month_year") == "dropdowns")
290
+ {
291
+ this.month_select.setValue(m, false);
292
+
293
+ var e = this.year_select.element;
294
+ if (this.flexibleYearRange() && (!(this.year_select.setValue(y, false)) || e.selectedIndex <= 1 || e.selectedIndex >= e.options.length - 2 )) this.populateYearRange();
295
+
296
+ this.year_select.setValue(y);
297
+
298
+ } else {
299
+ this.month_year_label.update( Date.months[m] + " " + y.toString() );
300
+ }
301
+ },
302
+ populateYearRange: function() {
303
+ this.year_select.populate(this.yearRange().toArray());
304
+ },
305
+ yearRange: function() {
306
+ if (!this.flexibleYearRange())
307
+ return $R(this.options.get("year_range")[0], this.options.get("year_range")[1]);
308
+
309
+ var y = this.date.getFullYear();
310
+ return $R(y - this.options.get("year_range"), y + this.options.get("year_range"));
311
+ },
312
+ flexibleYearRange: function() { return (typeof(this.options.get("year_range")) == "number"); },
313
+ validYear: function(year) { if (this.flexibleYearRange()) { return true;} else { return this.yearRange().include(year);} },
314
+ dayHover: function(element) {
315
+ var hover_date = new Date(this.selected_date);
316
+ hover_date.setYear(element.year); hover_date.setMonth(element.month); hover_date.setDate(element.day);
317
+ this.updateFooter(hover_date.toFormattedString(this.use_time));
318
+ },
319
+ dayHoverOut: function(element) { this.updateFooter(); },
320
+ clearSelectedClass: function() {if (this.selected_cell) this.selected_cell.removeClassName("selected");},
321
+ setSelectedClass: function() {
322
+ if (!this.selection_made) return;
323
+ this.clearSelectedClass()
324
+ if ($R(0,42).include( days_until = this.beginning_date.stripTime().daysDistance(this.selected_date.stripTime()) )) {
325
+ this.selected_cell = this.calendar_day_grid[days_until];
326
+ this.selected_cell.addClassName("selected");
327
+ }
328
+ },
329
+ reparse: function() { this.parseDate(); this.refresh(); },
330
+ dateString: function() {
331
+ return (this.selection_made) ? this.selected_date.toFormattedString(this.use_time) : "&#160;";
332
+ },
333
+ parseDate: function()
334
+ {
335
+ var value = $F(this.target_element).strip()
336
+ this.selection_made = (value != "");
337
+ this.date = value=="" ? NaN : Date.parseFormattedString(this.options.get("date") || value);
338
+ if (isNaN(this.date)) this.date = new Date();
339
+ if (!this.validYear(this.date.getFullYear())) this.date.setYear( (this.date.getFullYear() < this.yearRange().start) ? this.yearRange().start : this.yearRange().end);
340
+ this.selected_date = new Date(this.date);
341
+ this.use_time = /[0-9]:[0-9]{2}/.exec(value) ? true : false;
342
+ this.date.setDate(1);
343
+ },
344
+ updateFooter:function(text) { if (!text) text = this.dateString(); this.footer_div.purgeChildren(); this.footer_div.build("span", {innerHTML: text }); },
345
+ clearDate:function() {
346
+ if ((this.target_element.disabled || this.target_element.readOnly) && this.options.get("popup") != "force") return false;
347
+ var last_value = this.target_element.value;
348
+ this.target_element.value = "";
349
+ this.clearSelectedClass();
350
+ this.updateFooter('&#160;');
351
+ if (last_value!=this.target_element.value) this.callback("onchange");
352
+ },
353
+ updateSelectedDate:function(partsOrElement, via_click) {
354
+ var parts = $H(partsOrElement);
355
+ if ((this.target_element.disabled || this.target_element.readOnly) && this.options.get("popup") != "force") return false;
356
+ if (parts.get("day")) {
357
+ var t_selected_date = this.selected_date, vdc = this.options.get("valid_date_check");
358
+ for (var x = 0; x<=3; x++) t_selected_date.setDate(parts.get("day"));
359
+ t_selected_date.setYear(parts.get("year"));
360
+ t_selected_date.setMonth(parts.get("month"));
361
+
362
+ if (vdc && ! vdc(t_selected_date.stripTime())) { return false; }
363
+ this.selected_date = t_selected_date;
364
+ this.selection_made = true;
365
+ }
366
+
367
+ if (!isNaN(parts.get("hour"))) this.selected_date.setHours(parts.get("hour"));
368
+ if (!isNaN(parts.get("minute"))) this.selected_date.setMinutes( Math.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) );
369
+ if (parts.get("hour") === "" || parts.get("minute") === "")
370
+ this.setUseTime(false);
371
+ else if (!isNaN(parts.get("hour")) || !isNaN(parts.get("minute")))
372
+ this.setUseTime(true);
373
+
374
+ this.updateFooter();
375
+ this.setSelectedClass();
376
+
377
+ if (this.selection_made) this.updateValue();
378
+ if (this.closeOnClick()) { this.close(); }
379
+ if (via_click && !this.options.get("embedded")) {
380
+ if ((new Date() - this.last_click_at) < 333) this.close();
381
+ this.last_click_at = new Date();
382
+ }
383
+ },
384
+ closeOnClick: function() {
385
+ if (this.options.get("embedded")) return false;
386
+ if (this.options.get("close_on_click")===nil )
387
+ return (this.options.get("time")) ? false : true
388
+ else
389
+ return (this.options.get("close_on_click"))
390
+ },
391
+ navMonth: function(month) { (target_date = new Date(this.date)).setMonth(month); return (this.navTo(target_date)); },
392
+ navYear: function(year) { (target_date = new Date(this.date)).setYear(year); return (this.navTo(target_date)); },
393
+ navTo: function(date) {
394
+ if (!this.validYear(date.getFullYear())) return false;
395
+ this.date = date;
396
+ this.date.setDate(1);
397
+ this.refresh();
398
+ this.callback("after_navigate", this.date);
399
+ return true;
400
+ },
401
+ setUseTime: function(turn_on) {
402
+ this.use_time = this.options.get("time") && (this.options.get("time")=="mixed" ? turn_on : true) // force use_time to true if time==true && time!="mixed"
403
+ if (this.use_time && this.selected_date) { // only set hour/minute if a date is already selected
404
+ var minute = Math.floor_to_interval(this.selected_date.getMinutes(), this.options.get("minute_interval"));
405
+ var hour = this.selected_date.getHours();
406
+
407
+ this.hour_select.setValue(hour);
408
+ this.minute_select.setValue(minute)
409
+ } else if (this.options.get("time")=="mixed") {
410
+ this.hour_select.setValue(""); this.minute_select.setValue("");
411
+ }
412
+ },
413
+ updateValue: function() {
414
+ var last_value = this.target_element.value;
415
+ this.target_element.value = this.dateString();
416
+ if (last_value!=this.target_element.value) this.callback("onchange");
417
+ },
418
+ today: function(now) {
419
+ var d = new Date(); this.date = new Date();
420
+ var o = $H({ day: d.getDate(), month: d.getMonth(), year: d.getFullYear(), hour: d.getHours(), minute: d.getMinutes()});
421
+ if ( ! now ) o = o.merge({hour: "", minute:""});
422
+ this.updateSelectedDate(o, true);
423
+ this.refresh();
424
+ },
425
+ close: function() {
426
+ if (this.closed) return false;
427
+ this.callback("before_close");
428
+ this.target_element.calendar_date_select = nil;
429
+ Event.stopObserving(document, "mousedown", this.closeIfClickedOut_handler);
430
+ Event.stopObserving(document, "keypress", this.keyPress_handler);
431
+ this.calendar_div.remove(); this.closed = true;
432
+ if (this.iframe) this.iframe.remove();
433
+ if (this.target_element.type != "hidden" && ! this.target_element.disabled) this.target_element.focus();
434
+ this.callback("after_close");
435
+ },
436
+ closeIfClickedOut: function(e) {
437
+ if (! $(Event.element(e)).descendantOf(this.calendar_div) ) this.close();
438
+ },
439
+ keyPress: function(e) {
440
+ if (e.keyCode==Event.KEY_ESC) this.close();
441
+ },
442
+ callback: function(name, param) { if (this.options.get(name)) { this.options.get(name).bind(this.target_element)(param); } }
443
+ }
@@ -0,0 +1,34 @@
1
+ // American Format: 12/31/2000 5:00 pm
2
+ // Thanks, Wes Hays
3
+ Date.prototype.toFormattedString = function(include_time){
4
+ str = Date.padded2(this.getMonth() + 1) + '/' +Date.padded2(this.getDate()) + '/' + this.getFullYear();
5
+
6
+ if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() + " " + this.getAMPM() }
7
+ return str;
8
+ }
9
+
10
+ Date.parseFormattedString = function (string) {
11
+ // Test these with and without the time
12
+ // 11/11/1111 12pm
13
+ // 11/11/1111 1pm
14
+ // 1/11/1111 10:10pm
15
+ // 11/1/1111 01pm
16
+ // 1/1/1111 01:11pm
17
+ // 1/1/1111 1:11pm
18
+ var regexp = "(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *([0-9]{1,2}(:[0-9]{2})? *(am|pm))?";
19
+ var d = string.match(new RegExp(regexp, "i"));
20
+ if (d==null) {
21
+ return Date.parse(string); // Give javascript a chance to parse it.
22
+ }
23
+
24
+ mdy = d[1].split('/');
25
+ hrs = 0;
26
+ mts = 0;
27
+ if(d[3] != null) {
28
+ hrs = parseInt(d[3].split('')[0], 10);
29
+ if(d[5].toLowerCase() == 'pm') { hrs += 12; } // Add 12 more to hrs
30
+ mts = d[4].split(':')[1];
31
+ }
32
+
33
+ return new Date(mdy[2], parseInt(mdy[0], 10)-1, mdy[1], hrs, mts, 0);
34
+ }
@@ -0,0 +1,27 @@
1
+ // DB No Seconds Format: 2007-12-05 12:00
2
+
3
+ Date.padded2 = function(hour) { padded2 = hour.toString(); if ((parseInt(hour) < 10) || (parseInt(hour) == null)) padded2="0" + padded2; return padded2; }
4
+ Date.prototype.getAMPMHour = function() { hour=Date.padded2(this.getHours()); return (hour == null) ? 00 : (hour > 24 ? hour - 24 : hour ) }
5
+ Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "" : ""; }
6
+
7
+ Date.prototype.toFormattedString = function(include_time){
8
+ str = this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + Date.padded2(this.getDate());
9
+ if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() }
10
+ return str;
11
+ }
12
+
13
+ Date.parseFormattedString = function (string) {
14
+ var regexp = '([0-9]{4})-(([0-9]{1,2})-(([0-9]{1,2})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
15
+ var d = string.match(new RegExp(regexp, "i"));
16
+ if (d==null) return Date.parse(string); // at least give javascript a crack at it.
17
+ var offset = 0;
18
+ var date = new Date(d[1], 0, 1);
19
+ if (d[3]) { date.setMonth(d[3] - 1); }
20
+ if (d[5]) { date.setDate(d[5]); }
21
+ if (d[7]) {
22
+ date.setHours(parseInt(d[7], 10));
23
+ }
24
+ if (d[8]) { date.setMinutes(d[8]); }
25
+ if (d[10]) { date.setSeconds(d[10]); }
26
+ return date;
27
+ }
@@ -0,0 +1,7 @@
1
+ // Formats date and time as "01 January 2000 17:00"
2
+ Date.prototype.toFormattedString = function(include_time)
3
+ {
4
+ str = Date.padded2(this.getDate()) + " " + Date.months[this.getMonth()] + " " + this.getFullYear();
5
+ if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
6
+ return str;
7
+ }
@@ -0,0 +1,7 @@
1
+ // Formats date and time as "2000.01.20 17:00"
2
+ Date.prototype.toFormattedString = function(include_time)
3
+ {
4
+ str = this.getFullYear() + "." + Date.padded2(this.getMonth()+1) + "." + Date.padded2(this.getDate());
5
+ if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
6
+ return str;
7
+ }
@@ -0,0 +1,32 @@
1
+ Date.padded2 = function(hour) { padded2 = hour.toString(); if ((parseInt(hour) < 10) || (parseInt(hour) == null)) padded2="0" + padded2; return padded2; }
2
+ Date.prototype.getAMPMHour = function() { hour=Date.padded2(this.getHours()); return (hour == null) ? 00 : (hour > 24 ? hour - 24 : hour ) }
3
+ Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "" : ""; }
4
+
5
+ Date.prototype.toFormattedString = function(include_time){
6
+ str = this.getDate() + "." + (this.getMonth() + 1) + "." + this.getFullYear();
7
+ if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() }
8
+ return str;
9
+ }
10
+ Date.parseFormattedString = function (string) {
11
+ var regexp = '([0-9]{1,2})\.(([0-9]{1,2})\.(([0-9]{2,4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
12
+ var d = string.match(new RegExp(regexp, "i"));
13
+ if (d==null) return Date.parse(string); // at least give javascript a crack at it.
14
+ var offset = 0;
15
+ if (d[5] && d[5].length == 2) {
16
+ // we got only two digits for the year...
17
+ d[5] = Number(d[5]);
18
+ if (d[5] > 30)
19
+ d[5] += 1900;
20
+ else
21
+ d[5] += 2000;
22
+ }
23
+ var date = new Date(d[5], 0, 1);
24
+ if (d[3]) { date.setMonth(d[3] - 1); }
25
+ if (d[5]) { date.setDate(d[1]); }
26
+ if (d[7]) {
27
+ date.setHours(parseInt(d[7], 10));
28
+ }
29
+ if (d[8]) { date.setMinutes(d[8]); }
30
+ if (d[10]) { date.setSeconds(d[10]); }
31
+ return date;
32
+ }
@@ -0,0 +1,37 @@
1
+ Date.prototype.toFormattedString = function(include_time){
2
+ str = this.getFullYear() + "-" + Date.padded2(this.getMonth() + 1) + "-" +Date.padded2(this.getDate());
3
+
4
+ if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() + " " + this.getAMPM() }
5
+ return str;
6
+ }
7
+
8
+ Date.parseFormattedString = function (string) {
9
+ var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
10
+ "( ([0-9]{1,2}):([0-9]{2})? *(pm|am)" +
11
+ "?)?)?)?";
12
+ var d = string.match(new RegExp(regexp, "i"));
13
+ if (d==null) return Date.parse(string); // at least give javascript a crack at it.
14
+ var offset = 0;
15
+ var date = new Date(d[1], 0, 1);
16
+ if (d[3]) { date.setMonth(d[3] - 1); }
17
+ if (d[5]) { date.setDate(d[5]); }
18
+ if (d[7]) {
19
+ hours = parseInt(d[7], 10);
20
+ offset=0;
21
+ if (d[9]) {
22
+ is_pm = (d[9].toLowerCase()=="pm");
23
+ if (is_pm && hours <= 11) hours+=12;
24
+ if (!is_pm && hours == 12) hours=0;
25
+ }
26
+ date.setHours(hours);
27
+ }
28
+ if (d[8]) { date.setMinutes(d[8]); }
29
+ if (d[10]) { date.setSeconds(d[10]); }
30
+ if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
31
+ if (d[14]) {
32
+ offset = (Number(d[16]) * 60) + Number(d[17]);
33
+ offset *= ((d[15] == '-') ? 1 : -1);
34
+ }
35
+
36
+ return date;
37
+ }
@@ -0,0 +1,46 @@
1
+ Date.prototype.toFormattedString = function(include_time) {
2
+ var hour;
3
+ var str = this.getFullYear() + "-" + Date.padded2(this.getMonth() + 1) + "-" +Date.padded2(this.getDate());
4
+ if (include_time) {
5
+ hour = this.getHours();
6
+ str += " " + this.getHours() + ":" + this.getPaddedMinutes();
7
+ }
8
+ return str;
9
+ };
10
+
11
+ Date.parseFormattedString = function (string) {
12
+
13
+ var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
14
+ "( ([0-9]{1,2}):([0-9]{2})?" +
15
+ "?)?)?)?";
16
+
17
+ var d = string.match(new RegExp(regexp, "i"));
18
+ if (d === null) {
19
+ return Date.parse(string); // at least give javascript a crack at it.
20
+ }
21
+ var offset = 0;
22
+ var date = new Date(d[1], 0, 1);
23
+ if (d[3]) {
24
+ date.setMonth(d[3] - 1);
25
+ }
26
+ if (d[5]) {
27
+ date.setDate(d[5]);
28
+ }
29
+ if (d[7]) {
30
+ date.setHours(d[7]);
31
+ }
32
+ if (d[8]) {
33
+ date.setMinutes(d[8]);
34
+ }
35
+ if (d[0]) {
36
+ date.setSeconds(d[0]);
37
+ }
38
+ if (d[2]) {
39
+ date.setMilliseconds(Number("0." + d[2]));
40
+ }
41
+ if (d[4]) {
42
+ offset = (Number(d[6])) + Number(d[8]);
43
+ offset = ((d[5] == '-') ? 1 : -1);
44
+ }
45
+ return date;
46
+ };
@@ -0,0 +1,24 @@
1
+ // Italian Format: 31/12/2000 23:00
2
+ // Thanks, Bigonazzi!
3
+
4
+ Date.prototype.toFormattedString = function(include_time){
5
+ str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
6
+ if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
7
+ return str;
8
+ }
9
+
10
+ Date.parseFormattedString = function (string) {
11
+ var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
12
+ var d = string.match(new RegExp(regexp, "i"));
13
+ if (d==null) return Date.parse(string); // at least give javascript a crack at it.
14
+ var offset = 0;
15
+ var date = new Date(d[5], 0, 1);
16
+ if (d[3]) { date.setMonth(d[3] - 1); }
17
+ if (d[5]) { date.setDate(d[1]); }
18
+ if (d[7]) {
19
+ date.setHours(parseInt(d[7], 10));
20
+ }
21
+ if (d[8]) { date.setMinutes(d[8]); }
22
+ if (d[10]) { date.setSeconds(d[10]); }
23
+ return date;
24
+ }