atd-calendar_date_select 1.11.20090108

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/History.txt +231 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest.txt +42 -0
  4. data/Rakefile +31 -0
  5. data/Readme.txt +16 -0
  6. data/init.rb +1 -0
  7. data/js_test/functional/cds_test.html +334 -0
  8. data/js_test/prototype.js +4184 -0
  9. data/js_test/test.css +40 -0
  10. data/js_test/unit/cds_helper_methods.html +46 -0
  11. data/js_test/unittest.js +564 -0
  12. data/lib/calendar_date_select.rb +33 -0
  13. data/lib/calendar_date_select/calendar_date_select.rb +116 -0
  14. data/lib/calendar_date_select/includes_helper.rb +29 -0
  15. data/public/blank_iframe.html +2 -0
  16. data/public/images/calendar_date_select/calendar.gif +0 -0
  17. data/public/javascripts/calendar_date_select/calendar_date_select.js +443 -0
  18. data/public/javascripts/calendar_date_select/format_american.js +34 -0
  19. data/public/javascripts/calendar_date_select/format_db.js +27 -0
  20. data/public/javascripts/calendar_date_select/format_euro_24hr.js +7 -0
  21. data/public/javascripts/calendar_date_select/format_euro_24hr_ymd.js +7 -0
  22. data/public/javascripts/calendar_date_select/format_finnish.js +32 -0
  23. data/public/javascripts/calendar_date_select/format_hyphen_ampm.js +36 -0
  24. data/public/javascripts/calendar_date_select/format_iso_date.js +46 -0
  25. data/public/javascripts/calendar_date_select/format_italian.js +24 -0
  26. data/public/javascripts/calendar_date_select/locale/de.js +11 -0
  27. data/public/javascripts/calendar_date_select/locale/fi.js +10 -0
  28. data/public/javascripts/calendar_date_select/locale/fr.js +10 -0
  29. data/public/javascripts/calendar_date_select/locale/pl.js +10 -0
  30. data/public/javascripts/calendar_date_select/locale/pt.js +11 -0
  31. data/public/javascripts/calendar_date_select/locale/ru.js +10 -0
  32. data/public/stylesheets/calendar_date_select/blue.css +130 -0
  33. data/public/stylesheets/calendar_date_select/default.css +135 -0
  34. data/public/stylesheets/calendar_date_select/plain.css +128 -0
  35. data/public/stylesheets/calendar_date_select/red.css +135 -0
  36. data/public/stylesheets/calendar_date_select/silver.css +133 -0
  37. metadata +103 -0
data/History.txt ADDED
@@ -0,0 +1,231 @@
1
+ == Version 1.13
2
+ * Lots of code clean up!
3
+ * Moved test suite over to rspec
4
+ * CalendarDateSelect.default_options implemented. Use CalendarDateSelect.default_options.update(...) to set the default_options for your app.
5
+ * calendar_date_select and calendar_date_select_tag accept an :image parameter.
6
+ * Backwards compatibility hook for Rails 2.1
7
+ * RDOC!
8
+ * Don't try to focus a hidden or disabled element (closes #129 - thanks Bruno)
9
+ * Call onchange callback when clearing the calendar (closes #137 - thanks Chewi)
10
+ * Fixed issue that made :db format worthless (closes #135, thanks Andreas Zecher)
11
+ * dramatic optimization for calendar initial-rendering (thanks Yehudab, Bompus)
12
+
13
+ == Version 1.12 ==
14
+ * Updated for compatibility with Rails 2.2
15
+
16
+ == Version 1.11.1 ==
17
+ * properly wrap buttons if they are too big for the line
18
+ * more translations: german (Jonas), Added russian translation (DEkart)
19
+ * locale fixes:
20
+ * Fix: time doesn't work (using 12 hour instead of 24 hour) in Italian format.
21
+ * updated Portuguese translation with the "Clear" action (Daniel Luz)
22
+ * Portuguese was missing month of October
23
+ * Added a clear button (Hendy Tanata)
24
+ * Reverted a change that attempted to fix position in a scrollable div, but caused probles elsewhere
25
+ * Added :minute_interval to calendar_date_select_process_options, fixing http://code.google.com/p/calendardateselect/issues/detail?id=81
26
+ * Add helpers to give the list of javascripts and stylesheets (calendar_date_select_javascripts and calendar_date_select_stylesheets)
27
+ * Converted over to use Hoe (echoe was giving too many problems). Refactored the directory structure to make it more gem-ish.
28
+
29
+ == Version 1.11 ==
30
+
31
+ * Calendar Date Select now works as a ruby-gem (thanks, artmotion!)
32
+ * Applied fix outlined in Issue #83: http://code.google.com/p/calendardateselect/issues/detail?id=83 (Thanks David Bolton)
33
+
34
+ == Version 1.10.5 ==
35
+ Apr 7, 2008
36
+ * Javascript code refactoring! Less mess!
37
+ * Bugfix - range was including element 42, which is really the 43rd element, so there was an error happening when today happens exactly 43 days after the beginning date (caught this by chance, surprised it wasn't reported before)
38
+
39
+ == Version 1.10.4 ==
40
+ Mar 24, 2008
41
+ * patch applied to fix issue #92: nil object option causes CalendarDateSelect.calendar_date_select(object, method, options) to not use object. Thanks, sskirby!
42
+
43
+ == Version 1.10.3 ==
44
+ Mar 24. 2008
45
+ * Fixed active scaffold integration bug. Thanks tapajos!
46
+
47
+ == Version 1.10.2 ==
48
+ Mar 10. 2008
49
+ * bugfix: calendar_date_select_tag doesn't format Time and Date values (thanks for the patch, sskirby!)
50
+
51
+ == Version 1.10.1 ==
52
+ Mar 10, 2008
53
+ * updated to automatically install locale folder
54
+ * bugfix - cds "today" was showing up as Mar 9th 2008, when it was really Mar 10th 2008 - was caused by a wrinkle in time (Day light savings time)
55
+ * Prototype 1.6.0.1 compatibility issue (77) resolved - thanks mike.nicholaides for the patch!
56
+ * patch applied from mjroghelia to fix ie ssl iframe issue (84)
57
+ * xhtml error fixed -   replaced with #160;
58
+
59
+ ==Version 1.10 ==
60
+ Dec 3, 2007
61
+ * You can now pass in a parameter to tell CalendarDateSelect not to allow selection of certain dates. See the [http://www.restatesman.com/static/calendar?tab=other demo] for an example.
62
+
63
+ ==Version 1.9.2==
64
+ Nov 26, 2007
65
+ * CalendarDateSelect was leaking javascript variables. (nothing was explicitly declared local, so javascript assumes global). Added test case and applied fix. This may help with some of the conflicts CalendarDateSelect has been causing with other scripts.
66
+ * Applied Ryan Wood's patch to fix the problem with using a form builder against objects like authorization[coverage_attributes][]. Thanks Ryan Wood!
67
+ * Wes Hays brought up the point of parseInt trying to auto-detect number formats. Wrote code to force interpretation of digits as base10, with test cases to prove it.
68
+ * Misleading test case failure in Safari fixed: Safari won't let a boolean value to a property that should have a function (understandably). Changed the test variable names to prevent such a conflict.
69
+ * Now uses css :hover, rather than manually setting/removing the hover class. If you are using a custom stylesheet, you'll need to change ".calendar_date_select tbody td.hover" to ".calendar_date_select tbody td:hover" (thanks, Alex Egg)
70
+
71
+ ==Version 1.9.1==
72
+ Nov 15, 2007
73
+ * Removed dependency on deprecated features in 1.6.0. Thanks again, Richard Quadling!
74
+ * Bugfix - was showing wrong day selected when selecting Mar 23, 2008. (Day light savings time issue). Fixed with test case.
75
+ * Added CSS style to show red border around the embedded calendar_date_select div's with errors.
76
+ * Callbacks were broken with 1.9.0. Fixed, added test cases.
77
+
78
+ ==Version 1.9.0==
79
+ Nov 13, 2007
80
+ * Prototype 1.6.0 compatibility update. Will now break with earlier versions of prototype (ie 1.5.1). Big thanks to Kevin Alexander and Richard Quadling
81
+ * Additional test coverage for improved stability going forward.
82
+
83
+ ==Version 1.8.3==
84
+ Nov 12, 2007
85
+
86
+ * Improved close methods:
87
+ * Added "OK" button at the bottom
88
+ * Double clicking a day closes the calendar (not in IE, though... because IE is everyone's favorite browser to program for)
89
+ * Escape key closes calendar
90
+ * Added optional close button at the top, which is hidden by default. Don't use this unless you really need it, because it may disappear in the future.
91
+ * Don't focus a hidden element
92
+ * Navigate down to child input element if exists (in case a div tag is passed in). Resolves problems when input control is wrapped with a error div. Test cases
93
+ * Allow specific year ranges (pass in an array)
94
+ * restrict year navigation inside of a non-flexible range
95
+ * test case to check auto-repopulating of flexibleYearRanges.
96
+ * test case to check boundaries of nonFlexibleYearRanges.
97
+ * Ability to pass in :year_range => 5.years.ago..0.years.ago to calendar_date_select (ruby)
98
+ * Updated test cases
99
+ * Bugfix for duplicate days that were occuring across day-light-saving-time boundaries
100
+ * Added format_american.js (thanks, Wes Hays)
101
+ * Added format_italian.js (thanks, Bigonazzi)
102
+ * Added format_euro_24hr.js (thanks, James Silberbauer)
103
+ * Bugfix for Konqueror - Was showing blank white box for popup window - had to do with Iframe hack.
104
+ * Code-refactoring, clean up, breaking down methods, making the code easier to understand and extend.
105
+ * Added new stylesheet definition: .calendar_date_select .cds_header a.close { display: none}. Update your custom stylesheet with this new definition.
106
+
107
+
108
+ ==Version 1.8.1==
109
+ September 27 2007
110
+ * 1.8.0 was rushed. There were a bunch of bugs that cropped up immediately. This deploy includes JavaScript unit testing using the scriptaculous unit test framework! ([http://www.restatesman.com/calendar_date_select/js_test/functional/cds_test.html click here to run the tests on the latest trunk version]). These unit tests are going to greatly improve the reliability of CalendarDateSelect releases.
111
+
112
+ ==Version 1.8.0==
113
+
114
+ September 26 2007
115
+ * Bugfix - Safari 2 issue fixed (was interpreting "" as January 1, 1969)
116
+ * CSS overhaul - removed buttons and replaced with links. Cleaned up CSS. See CSSDiff_1_7_0__1_8_0 for a diff.
117
+ * :popup => :force (force the user to select a date)
118
+ * :time => "mixed" - You can now create a calendar control that allows a user to select "all day" or a specific time!
119
+ * :month_year => "label" - Replace the clunky dropdowns with a text.
120
+ * Some internal "gardening" on the code
121
+
122
+ ==Version 1.7.1==
123
+
124
+ Aug 29 2007
125
+
126
+ * Rendering options weren't being passed to the input control (like :style, :class, etc.)
127
+
128
+ ==Version 1.7.0==
129
+
130
+ Aug 24 2007
131
+
132
+ * update calendar date select to not rely on dom_id's anymore ( and no longer automatically changes the dom_id for your input fields )
133
+
134
+ * applied Steve Madsen's patch for not blanking out invalid dates.
135
+
136
+ ==Version 1.6.1==
137
+
138
+ Aug 24 2007
139
+
140
+ * Serious javascript bug when using "hyphen_ampm" format fixed. (Was only working in Firefox browsers with firebug installed)
141
+
142
+ * Added a bunch of new callbacks: before_show, before_close, after_show, after_close, after_navigate. (see [http://www.restatesman.com/static/calendar?tab=callbacks here] for details)
143
+
144
+
145
+ ==Version 1.6.0==
146
+
147
+ July 27 2007
148
+
149
+ * Now MUCH easier to change date formats! See ChangingDateFormat for details.
150
+ * Opera button labels fixed
151
+ * Calendar "flicker" fixed when displaying popup window.
152
+ * JS error 106 being thrown - fixed
153
+ * Bug fixes relating to calendar date select deciding whether to display above or below an element on a page
154
+ * XHTML compliance issue resolved - image had an invalid "id"
155
+ * Disabled/readonly elements can't be updated
156
+ * (note, if you wish to prevent user from inputting a date without the date picker, use the "embedded" option. See [http://restatesman.com/static/calendar/ demo] for example).
157
+ * Changes/cleanups submitted by Steve Madsen. If you see Steve, tell him what a great guy he is!
158
+ * Ability to change calendar image via CalendarDateSelect.image=
159
+ * cleaning up on how input tags are rendered
160
+
161
+ ==Version 1.5.2==
162
+
163
+ July 12 2007
164
+ * onchange event handler now supported.
165
+ * detects to see if prototype is loaded. If not, shows error message
166
+ * ability to hide "buttons"
167
+ * date parsing broken out to static function Date.parseFormattedString() for anyone who wants date's to parse a different way from javascript
168
+ * you can no longer select 1:60 pm.
169
+
170
+ ==Version 1.5.1==
171
+
172
+ June 21, 2007
173
+
174
+ * fixed following tickets:
175
+ * Selecting dates in April 2007 doesn't highlight day
176
+ * Selecting 29 February 2008 returns 1 March 2008
177
+ * options[:format] needs to be purged
178
+
179
+ ==Version 1.5==
180
+ June 18, 2007
181
+
182
+ * New CSS stylesheet
183
+
184
+ * Fixed "white on white" css issue when selecting a day
185
+
186
+ * Clicking today now updates the input field
187
+
188
+ ==Version 1.4==
189
+ June 16, 2007
190
+
191
+ * more bug fixes (selecting across daylight savings time causing js error. Sometimes clicking a day of the next month after selecting day 31 of the previous month was causing 2 months later to be selected)
192
+
193
+ * CSS improvements and refactoring
194
+
195
+ * form builder methods now automatically detect whether or not to use a Time field
196
+
197
+ * a bit more optimization
198
+
199
+ * refactored date formatter methods and others so they can be more easily overridden.
200
+
201
+ ==Version 1.3==
202
+ June 8, 2007
203
+
204
+ * a few bug fixes
205
+
206
+ * Modified the helper methods to allow passing of virtually any JavaScript argument into the JavaScript control.
207
+
208
+ ==Version 1.2==
209
+ June 4, 2007
210
+
211
+ * Big optimizations to the redrawing of the calendar. Now, previous/next buttons much more responsive.
212
+
213
+ * Improved feel of pop-up dialog - when somewhere else clicked on the screen other than the popup calendar, popup calendar will automatically close.
214
+
215
+ * If the popup window won't fit on the screen underneath the control, will automatically position to the top.
216
+
217
+
218
+ ==Version 1.1==
219
+ June 2, 2007
220
+
221
+ * There was a very strange bug that crept in for Internet Explorer. Internet Explorer does not allow you to set the innerHTML property for "button" elements. Therefore, it was necessary to change "button" elements to "input" elements of type button.
222
+
223
+ * There was a change to the CSS file. Anything applying styles to "button" elements has been changed to "input.button". If you have a custom stylesheet, update accordingly.
224
+
225
+ ==Version 1.0==
226
+ June 1, 2007
227
+
228
+ * Initial release!
229
+
230
+
231
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ All portions Copyright (c) 2007 Tim Harper
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,42 @@
1
+ History.txt
2
+ init.rb
3
+ js_test/functional/cds_test.html
4
+ js_test/prototype.js
5
+ js_test/test.css
6
+ js_test/unit/cds_helper_methods.html
7
+ js_test/unittest.js
8
+ lib/calendar_date_select/calendar_date_select.rb
9
+ lib/calendar_date_select/includes_helper.rb
10
+ lib/calendar_date_select/form_helpers.rb
11
+ lib/calendar_date_select.rb
12
+ Manifest.txt
13
+ MIT-LICENSE
14
+ public/blank_iframe.html
15
+ public/images/calendar_date_select/calendar.gif
16
+ public/javascripts/calendar_date_select/calendar_date_select.js
17
+ public/javascripts/calendar_date_select/format_american.js
18
+ public/javascripts/calendar_date_select/format_db.js
19
+ public/javascripts/calendar_date_select/format_euro_24hr.js
20
+ public/javascripts/calendar_date_select/format_euro_24hr_ymd.js
21
+ public/javascripts/calendar_date_select/format_finnish.js
22
+ public/javascripts/calendar_date_select/format_hyphen_ampm.js
23
+ public/javascripts/calendar_date_select/format_iso_date.js
24
+ public/javascripts/calendar_date_select/format_italian.js
25
+ public/javascripts/calendar_date_select/locale/de.js
26
+ public/javascripts/calendar_date_select/locale/fi.js
27
+ public/javascripts/calendar_date_select/locale/fr.js
28
+ public/javascripts/calendar_date_select/locale/pl.js
29
+ public/javascripts/calendar_date_select/locale/pt.js
30
+ public/javascripts/calendar_date_select/locale/ru.js
31
+ public/stylesheets/calendar_date_select/blue.css
32
+ public/stylesheets/calendar_date_select/default.css
33
+ public/stylesheets/calendar_date_select/plain.css
34
+ public/stylesheets/calendar_date_select/red.css
35
+ public/stylesheets/calendar_date_select/silver.css
36
+ Rakefile
37
+ Readme.txt
38
+ spec/
39
+ spec/calendar_date_select
40
+ spec/calendar_date_select/calendar_date_select_spec.rb
41
+ spec/calendar_date_select/form_helpers_spec.rb
42
+ spec/spec_helper.rb
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ $: << File.dirname(__FILE__) + "/lib/"
7
+ require "activesupport"
8
+ require './lib/calendar_date_select.rb'
9
+
10
+ Hoe.new('calendar_date_select', CalendarDateSelect::VERSION) do |p|
11
+ p.rubyforge_name = 'calendar_date_select'
12
+ p.developer('Tim Harper', 'tim c harper at gmail dot com')
13
+ end
14
+
15
+
16
+ task :set_version do
17
+ ["lib/calendar_date_select/calendar_date_select.rb", "public/javascripts/calendar_date_select/calendar_date_select.js"].each do |file|
18
+ abs_file = File.dirname(__FILE__) + "/" + file
19
+ src = File.read(abs_file);
20
+ src = src.map do |line|
21
+ case line
22
+ when /^ *VERSION/ then " VERSION = '#{ENV['VERSION']}'\n"
23
+ when /^\/\/ CalendarDateSelect version / then "// CalendarDateSelect version #{ENV['VERSION']} - a prototype based date picker\n"
24
+ else
25
+ line
26
+ end
27
+ end.join
28
+ File.open(abs_file, "wb") { |f| f << src }
29
+ end
30
+ end
31
+ # vim: syntax=Ruby
data/Readme.txt ADDED
@@ -0,0 +1,16 @@
1
+ = CalendarDateSelect
2
+
3
+ http://code.google.com/p/calendardateselect/
4
+
5
+ == Examples
6
+
7
+ "See a demo here":http://electronicholas.com/calendar
8
+
9
+ == Submitting patches
10
+
11
+ Please take care to do the following:
12
+
13
+ * Clean up your patch (don't send a patch bomb with a hundred features in one)
14
+ * Write test cases!
15
+ * As a general rule of thumb, think of ways to make things more general purpose than specific.
16
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/lib/calendar_date_select.rb"
@@ -0,0 +1,334 @@
1
+
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>Calendar Date Select Test Cases</title>
7
+ <script src="../prototype.js" type="text/javascript"></script>
8
+ <script src="../unittest.js" type="text/javascript"></script>
9
+ <!-- other JavaScript includes -->
10
+ <script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
11
+
12
+ <link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
13
+ <link rel="stylesheet" href="../test.css" type="text/css" />
14
+ </head>
15
+ <body>
16
+
17
+ <!-- Log output -->
18
+ <div id="testlog"> </div>
19
+
20
+ <!-- here go any elements you do the testing on -->
21
+ <div id="cds_test_div">
22
+ <input type="text" id="cds_test" />
23
+ </div>
24
+
25
+ <!-- Tests -->
26
+ <script type="text/javascript" language="javascript">
27
+ // <![CDATA[
28
+ new Test.Unit.Runner({
29
+ setup: function() { with(this){
30
+ $("cds_test").value="";
31
+ $("cds_test").disabled = false;
32
+ $("cds_test").readOnly = false;
33
+ }},
34
+ teardown: function() { with(this){
35
+ if (typeof(cds)!="undefined") assert(cds.closed,"all tests should close their calendar control");
36
+ Date.first_day_of_week = 0;
37
+ Date.weekdays = $w("S M T W T F S")
38
+ }},
39
+ testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
40
+ $A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
41
+ $("cds_test").value=d;
42
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
43
+ assertEqual(true, cds.use_time);
44
+ cds.close();
45
+ })
46
+
47
+ $("cds_test").value="January 2, 2007";
48
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
49
+ assertEqual(false, cds.use_time);
50
+ cds.close();
51
+ }},
52
+ testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
53
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
54
+ today_now = $$(".cds_buttons a[href=#]");
55
+ today_now[0].onclick();
56
+ assertEqual(false, cds.use_time, "when clicking today link");
57
+
58
+ today_now[1].onclick();
59
+ assertEqual(true, cds.use_time, "should have been true when clicking now link");
60
+ cds.close();
61
+ }},
62
+ test__selectMar_23_2008__shouldSelectCorrectDate: function() { with(this){
63
+ $("cds_test").value = "Mar 1, 2008"
64
+ cds = new CalendarDateSelect($("cds_test"), {time: "true"});
65
+ cds.updateSelectedDate({month: 2 /*+1*/, day: 23, year: 2008})
66
+
67
+ assertEqual("23", $$('td.selected div').first().innerHTML);
68
+ cds.close();
69
+ }},
70
+ test_updateSelectedDate: function() { with(this){
71
+ $("cds_test").value = "January 1, 2007"
72
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
73
+
74
+ cds.use_time=true;
75
+ cds.updateSelectedDate({hour: ""})
76
+ assertEqual(false, cds.use_time, "when setting hour to ''");
77
+
78
+ cds.use_time=true;
79
+ cds.updateSelectedDate({minute: ""})
80
+ assertEqual(false, cds.use_time, "when setting minute to ''");
81
+
82
+ cds.use_time=false;
83
+ cds.updateSelectedDate({hour: 0})
84
+ assertEqual(true, cds.use_time, "when setting hour to 0");
85
+
86
+ cds.use_time=false;
87
+ cds.updateSelectedDate({minute: 0})
88
+ assertEqual(true, cds.use_time, "when setting minute to 0");
89
+
90
+ cds.close();
91
+ }},
92
+ test_navYear: function() { with(this){
93
+ $("cds_test").value = "January 1, 2007";
94
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
95
+ cds.navYear(1870);
96
+ assertEqual(2007, cds.selected_date.getFullYear());
97
+ assertEqual(1870, cds.date.getFullYear());
98
+ cds.close();
99
+ }},
100
+ test_navMonth: function() { with(this){
101
+ $("cds_test").value = "January 1, 2007";
102
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
103
+ cds.navMonth(5);
104
+ assertEqual(0, cds.selected_date.getMonth());
105
+ assertEqual(5, cds.date.getMonth())
106
+ cds.close();
107
+ }},
108
+ test_callBacks: function() { with(this){
109
+ $("cds_test").up().build("div", {id: "global"});
110
+ cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
111
+ before_show: function() { $("global").before_show_called = true},
112
+ after_show: function() { $("global").after_show_called = true},
113
+ before_close: function() { $("global").before_close_called = true},
114
+ after_close: function() { $("global").after_close_called = true},
115
+ after_navigate: function() { $("global").after_navigate_called = true},
116
+ onchange: function() { $("global").onchange_called = true},
117
+ });
118
+ cds.navMonth(1);
119
+ cds.navMonth(10);
120
+ cds.updateSelectedDate({month: 1, day: 3, year: 2007});
121
+ cds.close();
122
+ assert($('global').before_show_called, "before_show wasnt called");
123
+ assert($('global').after_show_called, "after_show wasnt called");
124
+ assert($('global').before_close_called, "before_close wasnt called");
125
+ assert($('global').after_close_called, "after_close wasnt called");
126
+ assert($('global').after_navigate_called, "after_navigate wasnt called");
127
+ assert($('global').onchange_called, "onchange wasnt called");
128
+ $("global").remove();
129
+ }},
130
+ test_disabledElement_cantUpdate: function() {with(this){
131
+ $("cds_test").value = "May 10, 2007";
132
+ $("cds_test").disabled = true;
133
+ cds = new CalendarDateSelect($("cds_test"));
134
+
135
+ runTest = function() {
136
+ cds.updateSelectedDate({day: 1, month:0, year: 2007});
137
+ assertEqual(10, cds.selected_date.getDate())
138
+ }
139
+ runTest();
140
+ $("cds_test").disabled = false;
141
+ $("cds_test").readOnly = true;
142
+ runTest();
143
+
144
+ $("cds_test").readOnly = false;
145
+ cds.close();
146
+ }},
147
+ test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
148
+ $("cds_test").value = "May 10, 2007";
149
+ $("cds_test").readOnly = true;
150
+ cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
151
+
152
+ cds.updateSelectedDate({day: 1, month:0, year: 2007});
153
+ assertEqual(1, cds.selected_date.getDate())
154
+
155
+ $("cds_test").readOnly = false;
156
+ cds.close();
157
+ }},
158
+ test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
159
+ $("cds_test").value = "May 10, 2007 5:00 pm";
160
+ cds = new CalendarDateSelect($("cds_test"), {time:false});
161
+ assert(cds.closeOnClick(), "should set close_on_click to true when not using time")
162
+ assertEqual(false, cds.use_time, "When parsing time");
163
+ cds.today();
164
+ assert(cds.closed, "should close when clicking today");
165
+ assert(!cds.use_time, "Should not use time when calling today");
166
+
167
+ cds = new CalendarDateSelect($("cds_test"), {time:false});
168
+ cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
169
+ assertEqual(false, cds.use_time, "When setting hour/minute");
170
+ assert(cds.closed);
171
+ }},
172
+ test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
173
+ $("cds_test").value = "May 10, 2007 5:00 pm";
174
+ cds = new CalendarDateSelect($("cds_test"), {time:false});
175
+ assertEqual(false, cds.use_time, "When parsing time");
176
+ cds.setUseTime(true); // this will close the control
177
+ assert(! cds.use_time, "After calling setUseTime(true)");
178
+ cds.close();
179
+ }},
180
+ test_setMinute_notOnInterval_usesFloor: function() {with(this){
181
+ $("cds_test").value = "May 10, 2007 5:25 pm";
182
+ cds = new CalendarDateSelect($("cds_test"), {time:true});
183
+ cds.updateSelectedDate({hour: 1, minute: 4});
184
+ assertEqual(0, cds.selected_date.getMinutes());
185
+ assertEqual(1, cds.selected_date.getHours());
186
+
187
+ cds.close();
188
+ }},
189
+ // this checks for a safari 2 bug where safari parses "" as a date back in 1969
190
+ test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
191
+ $("cds_test").value = " ";
192
+ cds = new CalendarDateSelect($("cds_test"), {time:true});
193
+ assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
194
+ assertEqual(new Date().getFullYear(), cds.date.getFullYear());
195
+ assert(! cds.selection_made)
196
+ cds.close();
197
+ }},
198
+ test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
199
+ $("cds_test").value = "December 1, 2007 ";
200
+ cds = new CalendarDateSelect($("cds_test"), {time:true});
201
+ assert(cds.use_time)
202
+ cds.close();
203
+ }},
204
+ test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
205
+ cds = new CalendarDateSelect($("cds_test_div"), {time:true});
206
+ assertEqual("INPUT", cds.target_element.nodeName)
207
+ cds.close();
208
+ }},
209
+ test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
210
+ $("cds_test").value = "July 4, 1776";
211
+ cds = new CalendarDateSelect($("cds_test_div"), {time:true});
212
+ assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
213
+ assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
214
+ cds.close();
215
+ }},
216
+ test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
217
+ $("cds_test").value = "January 1, 2007";
218
+ cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
219
+
220
+ assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
221
+ assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
222
+ assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
223
+ assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
224
+ assert(cds.navMonth(1), "should allow me to be in boundary");
225
+ assert(cds.navYear(2007), "should allow me to be in boundary");
226
+ cds.close();
227
+ }},
228
+ test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
229
+ $("cds_test").value = "January 1, 2007";
230
+ cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [2007, 2007]});
231
+ assert(cds.year_select.setValue(2007), "should allow me to select 2007");
232
+ cds.close();
233
+ }},
234
+ test__nonflexibleYearRange__initializedWithDateOutsideOfRange__shouldShowNavDateAsClosestToOutsideYear: function() {with(this){
235
+ $("cds_test").value = "January 1, 1900";
236
+ cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
237
+ assertEqual(1997, cds.date.getFullYear(), "When going lesser than year_range");
238
+ cds.close();
239
+
240
+ $("cds_test").value = "January 1, 2010";
241
+ cds = new CalendarDateSelect($("cds_test"), {time:true, year_range: [1997, 2007]});
242
+ assertEqual(2007, cds.date.getFullYear(), "When going greater than year_range");
243
+
244
+ cds.close();
245
+ }},
246
+ test__nonflexibleYearRange__initializedWithDateInsideOfRange__shouldShowNavDateAsYear: function() {with(this){
247
+ $("cds_test").value = "January 1, 2005";
248
+ cds = new CalendarDateSelect($("cds_test"), {year_range: [1997, 2007]});
249
+ assertEqual(2005, cds.date.getFullYear(), "When going lesser than year_range");
250
+ cds.close();
251
+ }},
252
+ test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
253
+ $("cds_test").value = "January 1, 2007";
254
+ cds = new CalendarDateSelect($("cds_test"), {year_range: 10});
255
+ cds.navYear(1997);
256
+ assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
257
+ cds.navYear(2017);
258
+ assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
259
+ cds.close();
260
+ }},
261
+ test__should_show_iframe_only_in_ie: function() {with(this){
262
+ cds = new CalendarDateSelect($("cds_test"));
263
+
264
+ if (navigator.appName=="Microsoft Internet Explorer")
265
+ assertEqual(1, $$('iframe.ie6_blocker').length)
266
+ else
267
+ assertEqual(0, $$('iframe.ie6_blocker').length)
268
+
269
+ cds.close();
270
+ }},
271
+ test__should_populate_minute_box_according_to_minute_interval: function() {with(this){
272
+ cds = new CalendarDateSelect($("cds_test"), {time: true, minute_interval: 10});
273
+ assert(cds.minute_select.setValue(0), "should allow me to select 0 minutes" );
274
+ assert(!cds.minute_select.setValue(5), "should NOT allow me to select 5 minutes");
275
+ assert(cds.minute_select.setValue(10), "should allow me to select 10 minutes" );
276
+ cds.close();
277
+ }},
278
+ test__shouldnt_leak_variables: function() {with (this) {
279
+ var vars = $w("padded2 compare_date str minute hour value e above e_dim e_top e_left matched e_bottom e_height c_pos c_left c_top c_height left_px top_px top_div header_div body_div buttons_div footer_div bottom_div days_tbody row_number cell_index weekday that pre_days use_time m y hover_date x d o")
280
+ vars.each(function(v) {eval(v + " = -100");});
281
+
282
+ cds = new CalendarDateSelect($("cds_test"), {time: true});
283
+ cds.navMonth(1);
284
+ cds.navYear(2);
285
+ cds.dayHover($$('.cds_body td').first());
286
+ cds.updateSelectedDate({day:1, month:1, year:2007});
287
+ cds.close();
288
+
289
+ vars.each(function(v) {
290
+ assert(-100 == eval(v), "Variable " + v + " was leaked");
291
+ });
292
+ }},
293
+ test__valid_date__shouldnt_allow_selection_of_invalid_dates_and_should_apply_css: function() {with (this) {
294
+ $('cds_test').value = "December 11, 2007";
295
+ cds = new CalendarDateSelect($("cds_test"), {valid_date_check: function(date) { return date < new Date("December 13, 2007")}, time: "mixed"});
296
+ assertEqual("December 11, 2007", $F('cds_test'));
297
+ cds.updateSelectedDate({day:13, month:12-1, year:2007});
298
+ assertEqual("December 11, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
299
+ cds.updateSelectedDate({day:10, month:12-1, year:2007});
300
+ assertEqual("December 10, 2007", $F('cds_test'), "Date should not have been allowed to be selected");
301
+
302
+ day_12_element = $$('.calendar_date_select td')[17];
303
+ day_13_element = $$('.calendar_date_select td')[18];
304
+ assertEqual(12, day_12_element.day); // make sure we have th right one
305
+ assertEqual(13, day_13_element.day); // make sure we have th right one
306
+ assert( ! day_12_element.hasClassName("disabled"), "Day 12 shouldnt be disabled");
307
+ assert(day_13_element.hasClassName("disabled"), "Day 13 should be disabled");
308
+
309
+ cds.close();
310
+ }},
311
+ test__valid_date_check_is_nil__should_show_all_cells_as_enabled: function() {with (this) {
312
+ $('cds_test').value = "December 11, 2007";
313
+ cds = new CalendarDateSelect($("cds_test"));
314
+
315
+ $$('.calendar_date_select td').each(function(e){
316
+ assert( ! e.hasClassName("disabled"));
317
+ });
318
+
319
+ cds.close();
320
+ }},
321
+ test__should_pull_up_dec_07_when_first_day_of_week_is_1: function() {with (this) {
322
+ Date.first_day_of_week = 1;
323
+ Date.weekdays = $w("M T W T F S S");
324
+ $('cds_test').value = "December 1, 2007";
325
+ cds = new CalendarDateSelect($("cds_test"));
326
+
327
+ assertEqual(1, $$(".calendar_date_select").length);
328
+ cds.close();
329
+ }}
330
+ });
331
+ // ]]>
332
+ </script>
333
+ </body>
334
+ </html>