Class: UnobtrusiveDatePicker::DateTimePickerSelector

Inherits:
ActionView::Helpers::DateTimeSelector
  • Object
show all
Includes:
ActionView::Helpers::FormTagHelper, OptionParser
Defined in:
lib/unobtrusive_date_picker.rb

Constant Summary collapse

POSITION =
{
  :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5,
  :second => 6, :ampm => 7
}
AM =

We give them negative values so can differentiate between normal date/time values. The way the multi param stuff works, from what I can see, results in a variable number of fields (if you tell it to include seconds, for example). So we expect the AM/PM field, if present, to be last and have a negative value.

-1
PM =
-2

Instance Method Summary collapse

Instance Method Details

#select_ampmObject



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/unobtrusive_date_picker.rb', line 246

def select_ampm
  selected = hour < 12 ? AM : PM

  # XXX i18n? 
  label = { AM => 'AM', PM => 'PM' }
  ampm_options = []
  [AM, PM].each do |meridiem|
    option = { :value => meridiem }
    option[:selected] = "selected" if selected == meridiem
    ampm_options << (:option, label[meridiem], option) + "\n"
  end
  build_select(:ampm, ampm_options.join)
end

#select_hour_with_ampmObject



232
233
234
235
236
237
238
239
240
241
242
# File 'lib/unobtrusive_date_picker.rb', line 232

def select_hour_with_ampm
  unless @options[:twelve_hour]
    return select_hour_without_ampm
  end

  if @options[:use_hidden] || @options[:discard_hour]
    build_hidden(:hour, hour12)
  else
    build_options_and_select(:hour, hour12, :start => 1, :end => 12)
  end
end

#text_date_picker(name) ⇒ Object



226
227
228
229
230
# File 'lib/unobtrusive_date_picker.rb', line 226

def text_date_picker(name)
  value = format_date_value_for_text_field(@datetime, @options[:format], @options[:divider])
  @html_options[:class] = get_html_classes_for_datepicker(@options, @html_options[:class])
  text_field_tag(name, value, @html_options)
end