From 40247a8cbb1ec735ccd4d8490043345b86af31cc Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Sun, 21 Dec 2008 12:12:42 +0000 Subject: Remove observe_field :on option as prototype no longer supports it [#1088 state:resolved] --- actionpack/lib/action_view/helpers/prototype_helper.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 7fab3102e7..18a209dcea 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -531,11 +531,6 @@ module ActionView # is shorthand for # :with => "'name=' + value" # This essentially just changes the key of the parameter. - # :on:: Specifies which event handler to observe. By default, - # it's set to "changed" for text fields and areas and - # "click" for radio buttons and checkboxes. With this, - # you can specify it instead to be "blur" or "focus" or - # any other event. # # Additionally, you may specify any of the options documented in the # Common options section at the top of this document. @@ -548,11 +543,6 @@ module ActionView # :url => 'http://example.com/books/edit/1', # :with => 'title' # - # # Sends params: {:book_title => 'Title of the book'} when the focus leaves - # # the input field. - # observe_field 'book_title', - # :url => 'http://example.com/books/edit/1', - # :on => 'blur' # def observe_field(field_id, options = {}) if options[:frequency] && options[:frequency] > 0 @@ -1094,7 +1084,6 @@ module ActionView javascript << "#{options[:frequency]}, " if options[:frequency] javascript << "function(element, value) {" javascript << "#{callback}}" - javascript << ", '#{options[:on]}'" if options[:on] javascript << ")" javascript_tag(javascript) end -- cgit v1.2.3 From 389534c38c3baaa63ce5cc2ba3bd169415419167 Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Sun, 21 Dec 2008 19:46:33 +0000 Subject: Added prompt options to date helpers [#561 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_view/helpers/date_helper.rb | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index a04bb8c598..84ba5f0a8c 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -136,6 +136,10 @@ module ActionView # dates. # * :default - Set a default date if the affected date isn't set or is nil. # * :disabled - Set to true if you want show the select fields as disabled. + # * :prompt - Set to true (for a generic prompt), a prompt string or a hash of prompt strings + # for :year, :month, :day, :hour, :minute and :second. + # Setting this option prepends a select option with a generic prompt (Day, Month, Year, Hour, Minute, Seconds) + # or the given prompt string. # # If anything is passed in the +html_options+ hash it will be applied to every select tag in the set. # @@ -171,6 +175,9 @@ module ActionView # # that will have a default day of 20. # date_select("credit_card", "bill_due", :default => { :day => 20 }) # + # # Generates a date select with custom prompts + # date_select("post", "written_on", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) + # # The selects are prepared for multi-parameter assignment to an Active Record object. # # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that @@ -210,6 +217,11 @@ module ActionView # # You can set the :minute_step to 15 which will give you: 00, 15, 30 and 45. # time_select 'game', 'game_time', {:minute_step => 15} # + # # Creates a time select tag with a custom prompt. Use :prompt => true for generic prompts. + # time_select("post", "written_on", :prompt => {:hour => 'Choose hour', :minute => 'Choose minute', :second => 'Choose seconds'}) + # time_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours + # time_select("post", "written_on", :prompt => true) # generic prompts for all + # # The selects are prepared for multi-parameter assignment to an Active Record object. # # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that @@ -241,6 +253,11 @@ module ActionView # # as the written_on attribute. # datetime_select("post", "written_on", :discard_type => true) # + # # Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts. + # datetime_select("post", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) + # datetime_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours + # datetime_select("post", "written_on", :prompt => true) # generic prompts for all + # # The selects are prepared for multi-parameter assignment to an Active Record object. def datetime_select(object_name, method, options = {}, html_options = {}) InstanceTag.new(object_name, method, self, options.delete(:object)).to_datetime_select_tag(options, html_options) @@ -285,6 +302,11 @@ module ActionView # # prefixed with 'payday' rather than 'date' # select_datetime(my_date_time, :prefix => 'payday') # + # # Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts. + # select_datetime(my_date_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) + # select_datetime(my_date_time, :prompt => {:hour => true}) # generic prompt for hours + # select_datetime(my_date_time, :prompt => true) # generic prompts for all + # def select_datetime(datetime = Time.current, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_datetime end @@ -321,6 +343,11 @@ module ActionView # # prefixed with 'payday' rather than 'date' # select_date(my_date, :prefix => 'payday') # + # # Generates a date select with a custom prompt. Use :prompt=>true for generic prompts. + # select_date(my_date, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) + # select_date(my_date, :prompt => {:hour => true}) # generic prompt for hours + # select_date(my_date, :prompt => true) # generic prompts for all + # def select_date(date = Date.current, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_date end @@ -352,6 +379,11 @@ module ActionView # # separated by ':' and includes an input for seconds # select_time(my_time, :time_separator => ':', :include_seconds => true) # + # # Generates a time select with a custom prompt. Use :prompt=>true for generic prompts. + # select_time(my_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) + # select_time(my_time, :prompt => {:hour => true}) # generic prompt for hours + # select_time(my_time, :prompt => true) # generic prompts for all + # def select_time(datetime = Time.current, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_time end @@ -373,6 +405,10 @@ module ActionView # # that is named 'interval' rather than 'second' # select_second(my_time, :field_name => 'interval') # + # # Generates a select field for seconds with a custom prompt. Use :prompt=>true for a + # # generic prompt. + # select_minute(14, :prompt => 'Choose seconds') + # def select_second(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_second end @@ -395,6 +431,10 @@ module ActionView # # that is named 'stride' rather than 'second' # select_minute(my_time, :field_name => 'stride') # + # # Generates a select field for minutes with a custom prompt. Use :prompt=>true for a + # # generic prompt. + # select_minute(14, :prompt => 'Choose minutes') + # def select_minute(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_minute end @@ -416,6 +456,10 @@ module ActionView # # that is named 'stride' rather than 'second' # select_hour(my_time, :field_name => 'stride') # + # # Generates a select field for hours with a custom prompt. Use :prompt => true for a + # # generic prompt. + # select_hour(13, :prompt =>'Choose hour') + # def select_hour(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_hour end @@ -437,6 +481,10 @@ module ActionView # # that is named 'due' rather than 'day' # select_day(my_time, :field_name => 'due') # + # # Generates a select field for days with a custom prompt. Use :prompt => true for a + # # generic prompt. + # select_day(5, :prompt => 'Choose day') + # def select_day(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_day end @@ -475,6 +523,10 @@ module ActionView # # will use keys like "Januar", "Marts." # select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...)) # + # # Generates a select field for months with a custom prompt. Use :prompt => true for a + # # generic prompt. + # select_month(14, :prompt => 'Choose month') + # def select_month(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_month end @@ -502,6 +554,10 @@ module ActionView # # has ascending year values # select_year(2006, :start_year => 2000, :end_year => 2010) # + # # Generates a select field for years with a custom prompt. Use :prompt => true for a + # # generic prompt. + # select_year(14, :prompt => 'Choose year') + # def select_year(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_year end @@ -516,6 +572,10 @@ module ActionView :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }.freeze unless const_defined?('POSITION') + DEFAULT_PROMPTS = { + :year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds' + }.freeze unless const_defined?('DEFAULT_PROMPTS') + def initialize(datetime, options = {}, html_options = {}) @options = options.dup @html_options = html_options.dup @@ -764,11 +824,30 @@ module ActionView select_html = "\n" select_html << content_tag(:option, '', :value => '') + "\n" if @options[:include_blank] + select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt] select_html << select_options_as_html.to_s content_tag(:select, select_html, select_options) + "\n" end + # Builds a prompt option tag with supplied options or from default options + # prompt_option_tag(:month, :prompt => 'Select month') + # => "" + def prompt_option_tag(type, options) + default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false} + + case options + when Hash + prompt = default_options.merge(options)[type.to_sym] + when String + prompt = options + else + prompt = ActionView::Helpers::DateTimeSelector::DEFAULT_PROMPTS[type.to_sym] + end + + prompt ? content_tag(:option, prompt, :value => '') : '' + end + # Builds hidden input tag for date part and value # build_hidden(:year, 2008) # => "" -- cgit v1.2.3 From 70456aed31ae64b36563fc5d32ac114e0a095231 Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Mon, 22 Dec 2008 11:41:47 +0000 Subject: Use I18n for date/time select helpers prompt text [#561 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_view/helpers/date_helper.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 84ba5f0a8c..4305617ac8 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -572,10 +572,6 @@ module ActionView :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }.freeze unless const_defined?('POSITION') - DEFAULT_PROMPTS = { - :year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds' - }.freeze unless const_defined?('DEFAULT_PROMPTS') - def initialize(datetime, options = {}, html_options = {}) @options = options.dup @html_options = html_options.dup @@ -842,10 +838,10 @@ module ActionView when String prompt = options else - prompt = ActionView::Helpers::DateTimeSelector::DEFAULT_PROMPTS[type.to_sym] + prompt = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale]) end - prompt ? content_tag(:option, prompt, :value => '') : '' + prompt ? content_tag(:option, prompt, :value => '') : '' end # Builds hidden input tag for date part and value -- cgit v1.2.3 From a2270ef2594b97891994848138614657363f2806 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Dec 2008 19:48:05 +0000 Subject: Inline code comments for class_eval/module_eval [#1657 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_view/helpers/form_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 621e2946b5..a85751c657 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -737,9 +737,13 @@ module ActionView (field_helpers - %w(label check_box radio_button fields_for)).each do |selector| src = <<-end_src - def #{selector}(method, options = {}) - @template.send(#{selector.inspect}, @object_name, method, objectify_options(options)) - end + def #{selector}(method, options = {}) # def text_field(method, options = {}) + @template.send( # @template.send( + #{selector.inspect}, # "text_field", + @object_name, # @object_name, + method, # method, + objectify_options(options)) # objectify_options(options)) + end # end end_src class_eval src, __FILE__, __LINE__ end -- cgit v1.2.3