From b62243a5cc957ae0c7380bf8e020219e45366fe2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 11 Sep 2005 05:58:00 +0000 Subject: Added :disabled option to all data selects that'll make the elements inaccessible for change #2167, #253 [eigentone] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2184 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 + actionpack/lib/action_view/helpers/date_helper.rb | 20 +++++--- actionpack/test/template/date_helper_test.rb | 62 ++++++++++++++++++++++- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 1b8c9b3c2f..029dcfeda2 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added :disabled option to all data selects that'll make the elements inaccessible for change #2167, #253 [eigentone] + * Fixed that TextHelper#auto_link_urls would include punctuation in the links #2166, #1671 [eigentone] * Fixed that number_to_currency(1000, {:precision => 0})) should return "$1,000", instead of "$1,000." #2122 [sd@notso.net] diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index a516072acb..6323006bd0 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -62,6 +62,8 @@ module ActionView # set the order of the tags using the :order option with an array of symbols :year, :month and :day in # the desired order. Symbols may be omitted and the respective select is not included. # + # Passing :disabled => true as part of the +options+ will make elements inaccessible for change. + # # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed. # # Examples: @@ -118,7 +120,7 @@ module ActionView ) end - select_html(options[:field_name] || 'second', second_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'second', second_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. @@ -135,7 +137,7 @@ module ActionView ) end - select_html(options[:field_name] || 'minute', minute_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'minute', minute_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. @@ -151,7 +153,7 @@ module ActionView ) end - select_html(options[:field_name] || 'hour', hour_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'hour', hour_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end # Returns a select tag with options for each of the days 1 through 31 with the current day selected. @@ -167,7 +169,7 @@ module ActionView ) end - select_html(options[:field_name] || 'day', day_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'day', day_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end # Returns a select tag with options for each of the months January through December with the current month selected. @@ -203,7 +205,7 @@ module ActionView ) end - select_html(options[:field_name] || 'month', month_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'month', month_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end # Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius @@ -229,14 +231,16 @@ module ActionView ) end - select_html(options[:field_name] || 'year', year_options, options[:prefix], options[:include_blank], options[:discard_type]) + select_html(options[:field_name] || 'year', year_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled]) end private - def select_html(type, options, prefix = nil, include_blank = false, discard_type = false) + def select_html(type, options, prefix = nil, include_blank = false, discard_type = false, disabled = false) select_html = %(\n" diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index c90a478292..ac2a62129d 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -86,6 +86,15 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_month(8) end + def test_select_month_with_disabled + expected = %(\n" + + assert_equal expected, select_month(Time.mktime(2003, 8, 16), :disabled => true) + assert_equal expected, select_month(8, :disabled => true) + end + def test_select_month_with_field_name_override expected = %(\n) + expected << %(\n\n\n) + expected << "\n" + + assert_equal expected, select_year(Time.mktime(2003, 8, 16), :disabled => true, :start_year => 2003, :end_year => 2005) + assert_equal expected, select_year(2003, :disabled => true, :start_year => 2003, :end_year => 2005) + end + def test_select_year_with_field_name_override expected = %(\n) expected << %(\n\n\n) @@ -177,7 +194,7 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_year( 2003, :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005) end - + def test_select_year_descending expected = %(\n) + expected << %(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n) + expected << "\n" + + assert_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :disabled => true) + end + def test_select_hour_with_field_name_override expected = %(\n) + expected << %(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n) + expected << "\n" + + assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18), :disabled => true) + end + def test_select_minute_with_field_name_override expected = %(\n) + expected << %(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n) + expected << "\n" + + assert_equal expected, select_second(Time.mktime(2003, 8, 16, 8, 4, 18), :disabled => true) + end + def test_select_second_with_field_name_override expected = %(\n) + expected << %(\n\n\n) + expected << "\n" + + expected << %(\n" + + expected << %(\n" + + assert_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :disabled => true) + end + def test_select_date_with_no_start_year expected = %(