atd-calendar_date_select 1.11.20090216 → 1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Rakefile +6 -1
- data/js_test/functional/cds_test.html +15 -0
- data/lib/calendar_date_select.rb +1 -1
- data/lib/calendar_date_select/calendar_date_select.rb +1 -1
- data/lib/calendar_date_select/form_helpers.rb +8 -6
- data/public/javascripts/calendar_date_select/calendar_date_select.js +1 -1
- data/spec/calendar_date_select/calendar_date_select_spec.rb +14 -0
- data/spec/calendar_date_select/form_helpers_spec.rb +166 -0
- data/spec/spec_helper.rb +26 -0
- metadata +14 -12
data/History.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
== Version 1.15
|
2
|
+
* Bugfix: don't include the :image option in the input field
|
3
|
+
|
4
|
+
== Version 1.14
|
5
|
+
* Added support for Rails 2.3
|
6
|
+
|
7
|
+
== Version 1.13
|
2
8
|
* Lots of code clean up!
|
3
9
|
* Moved test suite over to rspec
|
4
10
|
* CalendarDateSelect.default_options implemented. Use CalendarDateSelect.default_options.update(...) to set the default_options for your app.
|
data/Rakefile
CHANGED
@@ -8,11 +8,16 @@ require "activesupport"
|
|
8
8
|
require './lib/calendar_date_select.rb'
|
9
9
|
|
10
10
|
Hoe.new('calendar_date_select', CalendarDateSelect::VERSION) do |p|
|
11
|
-
p.rubyforge_name = '
|
11
|
+
p.rubyforge_name = 'cds'
|
12
12
|
p.developer('Tim Harper', 'tim c harper at gmail dot com')
|
13
13
|
end
|
14
14
|
|
15
|
+
desc "Generate gemspec for GitHub deploy"
|
16
|
+
task :generate_gemspec do
|
17
|
+
`rake debug_gem > calendar_date_select.gemspec`
|
18
|
+
end
|
15
19
|
|
20
|
+
desc "Set the current gem version in the code (VERSION=version)"
|
16
21
|
task :set_version do
|
17
22
|
["lib/calendar_date_select/calendar_date_select.rb", "public/javascripts/calendar_date_select/calendar_date_select.js"].each do |file|
|
18
23
|
abs_file = File.dirname(__FILE__) + "/" + file
|
@@ -127,6 +127,21 @@
|
|
127
127
|
assert($('global').onchange_called, "onchange wasnt called");
|
128
128
|
$("global").remove();
|
129
129
|
}},
|
130
|
+
test_onchangeCallbackChangedOnclear: function() { with(this){
|
131
|
+
$("cds_test").up().build("div", {id: "global"});
|
132
|
+
cds = new CalendarDateSelect($("cds_test"), {time: "mixed",
|
133
|
+
onchange: function() { $("global").onchange_called = true},
|
134
|
+
});
|
135
|
+
$("cds_test").value = "";
|
136
|
+
cds.clearDate();
|
137
|
+
assert( ! $('global').onchange_called, "onchange was called, when the value wasn't actually changed");
|
138
|
+
$("cds_test").value = "boogy";
|
139
|
+
cds.clearDate();
|
140
|
+
assert( $('global').onchange_called, "onchange wasnt called, but should ahve been");
|
141
|
+
cds.close();
|
142
|
+
$("global").remove();
|
143
|
+
}},
|
144
|
+
|
130
145
|
test_disabledElement_cantUpdate: function() {with(this){
|
131
146
|
$("cds_test").value = "May 10, 2007";
|
132
147
|
$("cds_test").disabled = true;
|
data/lib/calendar_date_select.rb
CHANGED
@@ -2,7 +2,7 @@ require "calendar_date_select/calendar_date_select.rb"
|
|
2
2
|
require "calendar_date_select/form_helpers.rb"
|
3
3
|
require "calendar_date_select/includes_helper.rb"
|
4
4
|
|
5
|
-
if Object.const_defined?(:Rails) && File.directory?(Rails.root + "/public")
|
5
|
+
if Object.const_defined?(:Rails) && File.directory?(Rails.root.to_s + "/public")
|
6
6
|
ActionView::Helpers::FormHelper.send(:include, CalendarDateSelect::FormHelpers)
|
7
7
|
ActionView::Base.send(:include, CalendarDateSelect::FormHelpers)
|
8
8
|
ActionView::Base.send(:include, CalendarDateSelect::IncludesHelper)
|
@@ -96,7 +96,7 @@ module CalendarDateSelect::FormHelpers
|
|
96
96
|
#
|
97
97
|
# <%= calendar_date_select_tag "event_demo", "", :after_navigate => "alert('The current selected month is ' + this.calendar_date_select.selected_date.getMonth());" ,
|
98
98
|
def calendar_date_select_tag( name, value = nil, options = {})
|
99
|
-
options, javascript_options = calendar_date_select_process_options(options)
|
99
|
+
image, options, javascript_options = calendar_date_select_process_options(options)
|
100
100
|
value = CalendarDateSelect.format_time(value, javascript_options)
|
101
101
|
|
102
102
|
javascript_options.delete(:format)
|
@@ -106,7 +106,7 @@ module CalendarDateSelect::FormHelpers
|
|
106
106
|
hidden_field_tag(name, value, options) :
|
107
107
|
text_field_tag(name, value, options)
|
108
108
|
|
109
|
-
calendar_date_select_output(tag, options, javascript_options)
|
109
|
+
calendar_date_select_output(tag, image, options, javascript_options)
|
110
110
|
end
|
111
111
|
|
112
112
|
# Similar to the difference between +text_field_tag+ and +text_field+, this method behaves like +text_field+
|
@@ -126,7 +126,7 @@ module CalendarDateSelect::FormHelpers
|
|
126
126
|
use_time = false if Date===(obj.respond_to?(method) && obj.send(method))
|
127
127
|
end
|
128
128
|
|
129
|
-
options, javascript_options = calendar_date_select_process_options(options)
|
129
|
+
image, options, javascript_options = calendar_date_select_process_options(options)
|
130
130
|
|
131
131
|
options[:value] ||=
|
132
132
|
if(obj.respond_to?(method) && obj.send(method).respond_to?(:strftime))
|
@@ -142,6 +142,7 @@ module CalendarDateSelect::FormHelpers
|
|
142
142
|
tag = ActionView::Helpers::InstanceTag.new_with_backwards_compatibility(object, method, self, options.delete(:object))
|
143
143
|
calendar_date_select_output(
|
144
144
|
tag.to_input_field_tag( (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text", options),
|
145
|
+
image,
|
145
146
|
options,
|
146
147
|
javascript_options
|
147
148
|
)
|
@@ -151,6 +152,7 @@ module CalendarDateSelect::FormHelpers
|
|
151
152
|
# extracts any options passed into calendar date select, appropriating them to either the Javascript call or the html tag.
|
152
153
|
def calendar_date_select_process_options(options)
|
153
154
|
options, javascript_options = CalendarDateSelect.default_options.merge(options), {}
|
155
|
+
image = options.delete(:image)
|
154
156
|
callbacks = [:before_show, :before_close, :after_show, :after_close, :after_navigate]
|
155
157
|
for key in [:time, :valid_date_check, :embedded, :buttons, :clear_button, :format, :year_range, :month_year, :popup, :hidden, :minute_interval] + callbacks
|
156
158
|
javascript_options[key] = options.delete(key) if options.has_key?(key)
|
@@ -184,10 +186,10 @@ module CalendarDateSelect::FormHelpers
|
|
184
186
|
end
|
185
187
|
|
186
188
|
javascript_options[:year_range] = format_year_range(javascript_options[:year_range] || 10)
|
187
|
-
[options, javascript_options]
|
189
|
+
[image, options, javascript_options]
|
188
190
|
end
|
189
191
|
|
190
|
-
def calendar_date_select_output(input, options = {}, javascript_options = {})
|
192
|
+
def calendar_date_select_output(input, image, options = {}, javascript_options = {})
|
191
193
|
out = input
|
192
194
|
if javascript_options[:embedded]
|
193
195
|
uniq_id = "cds_placeholder_#{(rand*100000).to_i}"
|
@@ -196,7 +198,7 @@ module CalendarDateSelect::FormHelpers
|
|
196
198
|
out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{options_for_javascript(javascript_options)} ); ")
|
197
199
|
else
|
198
200
|
out << " "
|
199
|
-
out << image_tag(
|
201
|
+
out << image_tag(image,
|
200
202
|
:onclick => "new CalendarDateSelect( $(this).previous(), #{options_for_javascript(javascript_options)} );",
|
201
203
|
:style => 'border:0px; cursor:pointer;',
|
202
204
|
:class=>'calendar_date_select_popup_icon')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// CalendarDateSelect version 1.
|
1
|
+
// CalendarDateSelect version 1.15 - a prototype based date picker
|
2
2
|
// Questions, comments, bugs? - see the project page: http://code.google.com/p/calendardateselect
|
3
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
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");
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CalendarDateSelect do
|
4
|
+
it "should detect presence of time in a string" do
|
5
|
+
CalendarDateSelect.has_time?("January 7, 2007").should == false
|
6
|
+
CalendarDateSelect.has_time?("January 7, 2007 5:50pm").should == true
|
7
|
+
CalendarDateSelect.has_time?("January 7, 2007 5:50 pm").should == true
|
8
|
+
CalendarDateSelect.has_time?("January 7, 2007 16:30 pm").should == true
|
9
|
+
|
10
|
+
CalendarDateSelect.has_time?(Date.parse("January 7, 2007 3:00 pm")).should == false
|
11
|
+
CalendarDateSelect.has_time?(Time.parse("January 7, 2007 3:00 pm")).should == true
|
12
|
+
CalendarDateSelect.has_time?(DateTime.parse("January 7, 2007 3:00 pm")).should == true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CalendarDateSelect::FormHelpers do
|
4
|
+
include ActionView::Helpers::FormHelper
|
5
|
+
include ActionView::Helpers::JavaScriptHelper
|
6
|
+
include ActionView::Helpers::AssetTagHelper
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
include ActionView::Helpers::FormTagHelper
|
9
|
+
|
10
|
+
include CalendarDateSelect::FormHelpers
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@controller = ActionController::Base.new
|
14
|
+
@request = OpenStruct.new
|
15
|
+
@controller.request = @request
|
16
|
+
|
17
|
+
@model = OpenStruct.new
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "mixed mode" do
|
21
|
+
it "should not output a time when the value is a Date" do
|
22
|
+
@model.start_datetime = Date.parse("January 2, 2007")
|
23
|
+
output = calendar_date_select(:model, :start_datetime, :time => "mixed")
|
24
|
+
output.should_not match(/12:00 AM/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should output a time when the value is a Time" do
|
28
|
+
@model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
|
29
|
+
output = calendar_date_select(:model, :start_datetime, :time => "mixed")
|
30
|
+
output.should match(/12:00 AM/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should render a time when time is passed as 'true'" do
|
35
|
+
@model.start_datetime = Date.parse("January 2, 2007")
|
36
|
+
output = calendar_date_select(:model, :start_datetime, :time => "true")
|
37
|
+
output.should match(/12:00 AM/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should time_false__model_returns_time__should_render_without_time" do
|
41
|
+
@model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
|
42
|
+
output = calendar_date_select(:model, :start_datetime)
|
43
|
+
output.should_not match(/12:00 AM/)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should _nil_model__shouldnt_populate_value" do
|
47
|
+
@model = nil
|
48
|
+
output = calendar_date_select(:model, :start_datetime)
|
49
|
+
|
50
|
+
output.should_not match(/value/)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should _vdc__should_auto_format_function" do
|
54
|
+
@model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
|
55
|
+
output = calendar_date_select(:model,
|
56
|
+
:start_datetime,
|
57
|
+
:valid_date_check => "date < new Date()"
|
58
|
+
)
|
59
|
+
output.should include("valid_date_check:function(date) { return(date < new Date()) }")
|
60
|
+
|
61
|
+
output = calendar_date_select(:model,
|
62
|
+
:start_datetime,
|
63
|
+
:valid_date_check => "return(date < new Date())"
|
64
|
+
)
|
65
|
+
output.should include("valid_date_check:function(date) { return(date < new Date()) }")
|
66
|
+
output = calendar_date_select(:model,
|
67
|
+
:start_datetime,
|
68
|
+
:valid_date_check => "function(p) { return(date < new Date()) }"
|
69
|
+
)
|
70
|
+
output.should include("valid_date_check:function(p) { return(date < new Date()) }")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise an error if the valid_date_check function is missing a return statement" do
|
74
|
+
message = ":valid_date_check function is missing a 'return' statement. Try something like: :valid_date_check => 'if (date > new(Date)) return true; else return false;'"
|
75
|
+
lambda {
|
76
|
+
output = calendar_date_select(:model,
|
77
|
+
:start_datetime,
|
78
|
+
:valid_date_check => "date = 5; date < new Date());"
|
79
|
+
)
|
80
|
+
}.should raise_error(ArgumentError, message)
|
81
|
+
|
82
|
+
lambda {
|
83
|
+
output = calendar_date_select(:model,
|
84
|
+
:start_datetime,
|
85
|
+
:valid_date_check => "function(p) { date = 5; date < new Date()); }"
|
86
|
+
)
|
87
|
+
}.should raise_error(ArgumentError, message)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should render the year_range argument correctly" do
|
91
|
+
output = calendar_date_select(:model, :start_datetime)
|
92
|
+
output.should include("year_range:10")
|
93
|
+
output = calendar_date_select(:model, :start_datetime, :year_range => 2000..2010)
|
94
|
+
output.should include("year_range:[2000, 2010]")
|
95
|
+
output = calendar_date_select(:model, :start_datetime, :year_range => (15.years.ago..5.years.ago))
|
96
|
+
output.should include("year_range:[#{15.years.ago.year}, #{5.years.ago.year}]")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should disregard the :object parameter when nil" do
|
100
|
+
@model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
|
101
|
+
output = calendar_date_select(:model, :start_datetime, :time => true, :object => nil)
|
102
|
+
output.should include(CalendarDateSelect.format_date(@model.start_datetime))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should regard :object parameter" do
|
106
|
+
@model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
|
107
|
+
output = calendar_date_select(:lame_o, :start_datetime, :time => true, :object => @model)
|
108
|
+
output.should include(CalendarDateSelect.format_date(@model.start_datetime))
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should respect parameters provided in default_options" do
|
112
|
+
new_options = CalendarDateSelect.default_options.merge(:popup => "force")
|
113
|
+
CalendarDateSelect.stub!(:default_options).and_return(new_options)
|
114
|
+
calendar_date_select_tag(:name, "").should include("popup:'force'")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should respect the :image option" do
|
118
|
+
output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
|
119
|
+
output.should include("boogy.png")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not pass the :image option as a javascript option" do
|
123
|
+
output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
|
124
|
+
output.should_not include("image:")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should use the CSS class calendar_date_select_tag for popup selector icon" do
|
128
|
+
output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
|
129
|
+
output.should include("calendar_date_select_popup_icon")
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "calendar_date_select_tag" do
|
133
|
+
before(:each) do
|
134
|
+
@time = Time.parse("January 2, 2007 12:01:23 AM")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should use the string verbatim when provided" do
|
138
|
+
output = calendar_date_select_tag(:name, "Some String")
|
139
|
+
|
140
|
+
output.should include("Some String")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not render the time when time is false (or nil)" do
|
144
|
+
output = calendar_date_select_tag(:name, @time, :time => false)
|
145
|
+
|
146
|
+
output.should_not match(/12:01 AM/)
|
147
|
+
output.should include(CalendarDateSelect.format_date(@time.to_date))
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should render the time when :time => true" do
|
151
|
+
output = calendar_date_select_tag(:name, @time, :time => true)
|
152
|
+
|
153
|
+
output.should include(CalendarDateSelect.format_date(@time))
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should render the time when :time => 'mixed'" do
|
157
|
+
output = calendar_date_select_tag(:name, @time, :time => 'mixed')
|
158
|
+
output.should include(CalendarDateSelect.format_date(@time))
|
159
|
+
end
|
160
|
+
|
161
|
+
it "not include the image option in the result input tag" do
|
162
|
+
output = calendar_date_select_tag(:name, @time, :time => 'mixed')
|
163
|
+
output.should_not include("image=")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
gem 'activesupport', ">= 2.2.0"
|
6
|
+
gem 'actionpack', ">= 2.2.0"
|
7
|
+
|
8
|
+
require 'active_support'
|
9
|
+
require 'action_pack'
|
10
|
+
require 'action_controller'
|
11
|
+
require 'action_view'
|
12
|
+
|
13
|
+
require 'ostruct'
|
14
|
+
|
15
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
16
|
+
class << self; alias new_with_backwards_compatibility new; end
|
17
|
+
end
|
18
|
+
|
19
|
+
$: << (File.dirname(__FILE__) + "/../lib")
|
20
|
+
require "calendar_date_select"
|
21
|
+
|
22
|
+
class String
|
23
|
+
def to_regexp
|
24
|
+
is_a?(Regexp) ? self : Regexp.new(Regexp.escape(self.to_s))
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atd-calendar_date_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: "1.15"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Harper
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,9 +20,9 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.
|
23
|
+
version: 1.8.3
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description:
|
26
26
|
email:
|
27
27
|
- tim c harper at gmail dot com
|
28
28
|
executables: []
|
@@ -42,8 +42,8 @@ files:
|
|
42
42
|
- js_test/unit/cds_helper_methods.html
|
43
43
|
- js_test/unittest.js
|
44
44
|
- lib/calendar_date_select/calendar_date_select.rb
|
45
|
-
- lib/calendar_date_select/form_helpers.rb
|
46
45
|
- lib/calendar_date_select/includes_helper.rb
|
46
|
+
- lib/calendar_date_select/form_helpers.rb
|
47
47
|
- lib/calendar_date_select.rb
|
48
48
|
- Manifest.txt
|
49
49
|
- MIT-LICENSE
|
@@ -71,11 +71,13 @@ files:
|
|
71
71
|
- public/stylesheets/calendar_date_select/silver.css
|
72
72
|
- Rakefile
|
73
73
|
- Readme.txt
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
74
|
+
- spec/
|
75
|
+
- spec/calendar_date_select
|
76
|
+
- spec/calendar_date_select/calendar_date_select_spec.rb
|
77
|
+
- spec/calendar_date_select/form_helpers_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
77
79
|
has_rdoc: true
|
78
|
-
homepage:
|
80
|
+
homepage:
|
79
81
|
post_install_message:
|
80
82
|
rdoc_options:
|
81
83
|
- --main
|
@@ -96,10 +98,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
98
|
version:
|
97
99
|
requirements: []
|
98
100
|
|
99
|
-
rubyforge_project:
|
101
|
+
rubyforge_project: cds
|
100
102
|
rubygems_version: 1.2.0
|
101
103
|
signing_key:
|
102
104
|
specification_version: 2
|
103
105
|
summary: ""
|
104
|
-
test_files:
|
105
|
-
|
106
|
+
test_files: []
|
107
|
+
|