Class: Anjlab::Widgets::DateTimeInput

Inherits:
SimpleForm::Inputs::DateTimeInput
  • Object
show all
Defined in:
lib/anjlab-widgets/simple_form.rb

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/anjlab-widgets/simple_form.rb', line 9

def input(wrapper_options)
  time = options[:value] || @builder.object.send(attribute_name)

  html = ''.html_safe

  allow_blank = !options[:required]
  source_options = merge_wrapper_options(input_html_options, wrapper_options)

  date_data = {
    "data-widget" => "datepicker",
    "data-rails" => true,
    "data-date-allow-blank" => allow_blank,
    :value => Widgets::format_date(time),
    :required => source_options[:required],
    :class => "#{source_options[:date_class] || 'input-small'}",
    :placeholder => "#{source_options[:date_placeholder]}"
  }.merge(source_options)

  time_data = {
    "data-widget" => "timepicker",
    "data-rails" => true,
    :value => Widgets::format_time(time),
    :required => source_options[:required],
    :class => "#{source_options[:time_class] || 'input-small'}",
    :placeholder => "#{source_options[:time_placeholder]}"
  }.merge(source_options)

  case input_type
  when :datetime, :anjlab_datetime
    html << @builder.text_field(attribute_name, date_data)
    html << '&nbsp;&nbsp;&nbsp;'.html_safe
    html << @builder.text_field(attribute_name, time_data)
    values = time ? [time.year, time.month, time.day, time.hour, time.min] : [''] * 5
  when :date, :anjlab_date
    html << @builder.text_field(attribute_name, date_data)
    values = time ? [time.year, time.month, time.day] : [''] * 3
  when :time, :anjlab_time
    html << @builder.text_field(attribute_name, time_data)
    now = Time.now
    default_parts = [now.year, now.month, now.day, '', '']
    values = time ? [time.year, time.month, time.day, time.hour, time.min] : default_parts
  end

  values.each_with_index do |v, index|
    i = index + 1
    html << @builder.hidden_field("#{attribute_name}(#{i}i)", value: v,  class: "js-aw-#{i}i")
  end
  html
end

#label_targetObject



5
6
7
# File 'lib/anjlab-widgets/simple_form.rb', line 5

def label_target
  attribute_name
end