Skip to content

Commit d1ca3e0

Browse files
author
Gena Maly
committed
Move default_datetime_picker_options and format to mattr_accessor for easy override
1 parent 3a2de53 commit d1ca3e0

File tree

1 file changed

+23
-4
lines changed
  • lib/active_admin_datetimepicker

1 file changed

+23
-4
lines changed

lib/active_admin_datetimepicker/base.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
module ActiveAdminDatetimepicker
22
module Base
3-
def html_class
4-
'date-time-picker'
3+
mattr_accessor :default_datetime_picker_options do
4+
{}
55
end
66

7-
def format
7+
mattr_accessor :format do
88
'%Y-%m-%d %H:%M'
99
end
1010

11+
def html_class
12+
'date-time-picker'
13+
end
14+
1115
def input_html_data
1216
{}
1317
end
@@ -33,8 +37,23 @@ def datetime_picker_options
3337
# backport support both :datepicker_options AND :datetime_picker_options
3438
options = self.options.fetch(:datepicker_options, {})
3539
options = self.options.fetch(:datetime_picker_options, options)
36-
Hash[options.map { |k, v| [k.to_s.camelcase(:lower), v] }]
40+
options = Hash[options.map { |k, v| [k.to_s.camelcase(:lower), v] }]
41+
_default_datetime_picker_options.merge(options)
42+
end
43+
end
44+
45+
protected
46+
47+
def _default_datetime_picker_options
48+
res = default_datetime_picker_options.map do |k, v|
49+
if v.respond_to?(:call) || v.is_a?(Proc)
50+
[k, v.call]
51+
else
52+
[k, v]
53+
end
3754
end
55+
Hash[res]
3856
end
3957
end
4058
end
59+

0 commit comments

Comments
 (0)