aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-12-29 14:38:54 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2008-12-29 14:38:54 -0800
commit276ec16007b03d0a527fb0b83a7ee0b81e460fa1 (patch)
tree224491aa1948d613a551189028746d73400fccce /actionpack/lib/action_view/helpers
parent2e053aec9bafa8735d70886f36dea06ea10dc4ce (diff)
parent490c26c8433a6d278bc61118782da360e8889646 (diff)
downloadrails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.tar.gz
rails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.tar.bz2
rails-276ec16007b03d0a527fb0b83a7ee0b81e460fa1.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb75
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb10
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb11
3 files changed, 82 insertions, 14 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index a04bb8c598..4305617ac8 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.
# * <tt>:default</tt> - Set a default date if the affected date isn't set or is nil.
# * <tt>:disabled</tt> - Set to true if you want show the select fields as disabled.
+ # * <tt>:prompt</tt> - Set to true (for a generic prompt), a prompt string or a hash of prompt strings
+ # for <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:minute</tt> and <tt>:second</tt>.
+ # 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
@@ -764,11 +820,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')
+ # => "<option value="">Select month</option>"
+ 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 = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale])
+ end
+
+ prompt ? content_tag(:option, prompt, :value => '') : ''
+ end
+
# Builds hidden input tag for date part and value
# build_hidden(:year, 2008)
# => "<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="2008" />"
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
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.
- # <tt>:on</tt>:: 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
# <em>Common options</em> 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