0
@@ -17,6 +17,23 @@ module Mack
0
MINUTES << [(m < 10 ? "0#{m}" : m), m]
0
+ # This will create a series of select boxes that compromise a time object. By default boxes will be
0
+ # created for day/month/year hour:minute. You can optionally turn on or off any of these boxes, including
0
+ # seconds by setting them to true/false. For example:
0
+ # <%= date_time_select :some_time, :days => false %>
0
+ # will not produce a select box for days, and so on...
0
+ # You can pass in an array of arrays to represent the options for any of the boxes like such:
0
+ # <%= date_time_select :some_time, :day_options => [[1,"one"], [2,"two"]] %>
0
+ # Will produce a day select box with only two options. Alternatively you can pass in an array of values
0
+ # and the options will be done for you. Like such:
0
+ # <%= date_time_select :some_time, :day_values => 1..60 %>
0
+ # Will produce a day select box with 60 options whose values and keys will be the same.
0
+ # The separators for dates and times can be set with the date_separator and time_separator options. By
0
+ # :date_separator => '/'
0
+ # :time_separator => ':'
0
def date_time_select(name, *args)
0
var = instance_variable_get("@#{name}")
0
fe = FormElement.new(*args)
0
@@ -27,7 +44,7 @@ module Mack
0
(time.year - 5).upto(time.year + 5) { |y| years << [y, y]}
0
- options = {:years => true, :months => true, :days => true, :hours => true, :minutes => true, :seconds => false, :year_options => years, :month_options => MONTHS, :day_options => DAYS, :hour_options => HOURS, :minute_options => MINUTES, :second_options => MINUTES
}.merge(fe.options)
0
+ options = {:years => true, :months => true, :days => true, :hours => true, :minutes => true, :seconds => false, :year_options => years, :month_options => MONTHS, :day_options => DAYS, :hour_options => HOURS, :minute_options => MINUTES, :second_options => MINUTES
, :date_separator => '/', :time_separator => ':'}.merge(fe.options)
0
[:year, :month, :day, :hour, :minute, :second].each do |v|
0
if options["#{v}_values".to_sym]
0
@@ -51,18 +68,22 @@ module Mack
0
time_boxes << dt_select(:minute, name, fe, time.min, options[:minute_options]) if options[:minutes]
0
time_boxes << dt_select(:second, name, fe, time.sec, options[:second_options]) if options[:seconds]
0
- boxes = date_boxes.join(
"/")
0
+ boxes = date_boxes.join(
options[:date_separator])
0
unless time_boxes.empty?
0
- boxes << " " << time_boxes.join(
":")
0
+ boxes << " " << time_boxes.join(
options[:time_separator])
0
- # Used just like date_time_select, but it has hours, minutes, and seconds turned off.
0
+ # Used just like date_time_select, but it has hours, minutes, and seconds turned off. See date_time_select
0
+ # <%= :user.date_select :birth_date %>
0
+ # @some_time = Time.new
0
+ # <%= :date_select :some_time, :label => true %>
0
def date_select(name, *args)
0
fe = FormElement.new(*args)
0
date_time_select(name, fe.calling_method, {:hours => false, :minutes => false, :seconds => false}.merge(fe.options))