Class: DateTimePickerInput

Inherits:
ActiveAdminAddons::InputBase show all
Defined in:
app/inputs/date_time_picker_input.rb

Overview

The MIT License (MIT)

Copyright © 2015 Igor Fedoronchuk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Instance Method Summary collapse

Methods inherited from ActiveAdminAddons::InputBase

#concat, #input_html_options, #load_input_class, #parts, #parts_to_html, #render_custom_input, #to_html

Methods included from ActiveAdminAddons::InputHtmlHelpers

#build_hidden_control, #build_separator, #empty_input_id, #method_to_input_array_name, #method_to_input_id, #method_to_input_name, #prefixed_method, #selected_values_id

Methods included from ActiveAdminAddons::InputMethods

#association_name, #build_virtual_attr, #input_association_value, #input_related_items, #input_value, #method_model, #model_name, #object_class, #tableize_method, #translated_method, #url_from_method, #valid_method, #valid_object

Methods included from ActiveAdminAddons::InputOptionsHandler

#attr_options, #control_attributes, #css_classes, #data_attr_options, #get_data_attr_value, #load_attr, #load_class, #load_data_attr

Instance Method Details

#datetime_picker_optionsObject



44
45
46
47
48
49
# File 'app/inputs/date_time_picker_input.rb', line 44

def datetime_picker_options
  @datetime_picker_options ||= begin
    opts = default_picker_options.merge(options.fetch(:picker_options, {}))
    Hash[opts.map { |k, v| [k.to_s.camelcase(:lower), v] }]
  end
end

#formatted_input_valueObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/inputs/date_time_picker_input.rb', line 32

def formatted_input_value
  v = input_value

  if v.is_a?(Time)
    return DateTime.new(v.year, v.month, v.day, v.hour, v.min, v.sec).strftime(
      ActiveadminAddons.datetime_picker_input_format
    )
  end

  v.to_s
end

#load_control_attributesObject



24
25
26
27
28
29
30
# File 'app/inputs/date_time_picker_input.rb', line 24

def load_control_attributes
  load_class(@options[:class])
  load_data_attr(:picker_options, value: datetime_picker_options)
  load_attr(:maxlength, value: 19)
  load_attr(:autocomplete, value: 'off')
  load_attr(:value, value: formatted_input_value)
end