module ActiveAdminDatetimepicker::Base
Public Instance Methods
datetime_picker_options()
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 38 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_class()
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 8 def html_class 'date-time-picker' end
input_html_data()
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 12 def input_html_data {} end
input_html_options(input_name = nil, placeholder = nil)
click to toggle source
Calls superclass method
# File lib/active_admin_datetimepicker/base.rb, line 16 def input_html_options(input_name = nil, placeholder = nil) super().tap do |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[:placeholder] = placeholder unless placeholder.nil? end end
input_value(input_name = nil)
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 27 def input_value(input_name = nil) val = object.public_send(input_name || method) val.is_a?(Date) ? val : parse_datetime(val) end
parse_datetime(val)
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 32 def parse_datetime(val) DateTime.parse(val.to_s).strftime(format) rescue ArgumentError nil end
Protected Instance Methods
_default_datetime_picker_options()
click to toggle source
# File lib/active_admin_datetimepicker/base.rb, line 50 def _default_datetime_picker_options res = default_datetime_picker_options.map do |k, v| if v.respond_to?(:call) || v.is_a?(Proc) [k, v.call] else [k, v] end end Hash[res] end