Module: ActiveAdminDatetimepicker::Base

Included in:
ActiveAdmin::Inputs::DateTimePickerInput, ActiveAdmin::Inputs::Filters::DateTimeRangeInput
Defined in:
lib/active_admin_datetimepicker/base.rb

Instance Method Summary collapse

Instance Method Details

#datetime_picker_optionsObject



35
36
37
38
39
40
41
42
43
# File 'lib/active_admin_datetimepicker/base.rb', line 35

def datetime_picker_options
  @datetime_picker_options ||= begin
    # backport support both :datepicker_options AND :datetime_picker_options
    options = self.options.fetch(:datepicker_options, {})
    options = self.options.fetch(:datetime_picker_options, options)
    options = Hash[options.map { |k, v| [k.to_s.camelcase(:lower), v] }]
    _default_datetime_picker_options.merge(options)
  end
end

#html_classObject



11
12
13
# File 'lib/active_admin_datetimepicker/base.rb', line 11

def html_class
  'date-time-picker'
end

#input_html_dataObject



15
16
17
# File 'lib/active_admin_datetimepicker/base.rb', line 15

def input_html_data
  {}
end

#input_html_options(input_name = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/active_admin_datetimepicker/base.rb', line 19

def input_html_options(input_name = nil)
  options = {}
  options[:class] = [self.options[:class], html_class].compact.join(' ')
  options[:data] ||= input_html_data
  options[:data].merge!(datepicker_options: datetime_picker_options)
  options[:value] ||= input_value(input_name)
  options[:maxlength] = 19
  options
end

#input_value(input_name = nil) ⇒ Object



29
30
31
32
33
# File 'lib/active_admin_datetimepicker/base.rb', line 29

def input_value(input_name = nil)
  val = object.public_send(input_name || method)
  return DateTime.new(val.year, val.month, val.day, val.hour, val.min, val.sec).strftime(format) if val.is_a?(Time)
  val.to_s
end