Class: Hellobase::Formtastic::Inputs::DatepickerWithTimeInput
- Inherits:
-
Object
- Object
- Hellobase::Formtastic::Inputs::DatepickerWithTimeInput
- Includes:
- Formtastic::Inputs::Base
- Defined in:
- lib/hellobase/formtastic/inputs/datepicker_with_time_input.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.define_virtual_attributes(klass, base) ⇒ Object
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 58 59 60 |
# File 'lib/hellobase/formtastic/inputs/datepicker_with_time_input.rb', line 13 def self.define_virtual_attributes(klass, base) attrs = virtual_attributes(base) ivars = attrs.map {|a| :"@#{a}" } method = :"_dpwt_set_#{base}" klass.class_eval do define_method attrs[0] do send(base)&.strftime('%Y-%m-%d') end define_method attrs[1] do send(base)&.strftime('%H') end define_method attrs[2] do send(base)&.strftime('%M') end define_method attrs[3] do send(base)&.strftime('%Z') end attrs.each_with_index do |a, i| define_method :"#{a}=" do |val| instance_variable_set ivars[i], val send(method) val end end define_method method do send :"#{base}=", ivars.any? {|v| instance_variable_get(v).blank? } ? nil : [ instance_variable_get(ivars[0]), [ instance_variable_get(ivars[1]), instance_variable_get(ivars[2]) ].join(':'), instance_variable_get(ivars[3]), ].join(' ') end private method end end |
.virtual_attributes(base) ⇒ Object
9 10 11 |
# File 'lib/hellobase/formtastic/inputs/datepicker_with_time_input.rb', line 9 def self.virtual_attributes(base) [:"_dpwt_#{base}_d", :"_dpwt_#{base}_h", :"_dpwt_#{base}_m", :"_dpwt_#{base}_z"] end |
Instance Method Details
#to_html ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hellobase/formtastic/inputs/datepicker_with_time_input.rb', line 62 def to_html datepicker_html = ::ActiveAdmin::Inputs::DatepickerInput.new(builder, template, object, object_name, :"_dpwt_#{method}_d", ).to_html hour_select_html = ::Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_h", ).to_html minute_select_html = ::Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_m", ).to_html timezone = [:timezone] || 'UTC' timezone_span_html = template.content_tag(:span, timezone, id: "#{object_name}__dpwt_#{method}_timezone") timezone_hidden_input_html = template.hidden_field_tag("#{object_name}[_dpwt_#{method}_z]", timezone, :id => "#{object_name}__dpwt_#{method}_z") wrapper_contents = [ replace_li_tag(datepicker_html), replace_li_tag(hour_select_html), replace_li_tag(minute_select_html), timezone_span_html, timezone_hidden_input_html, error_html, hint_html, ].compact.join("\n").html_safe template.content_tag(:li, wrapper_contents, ) end |