Module: BootstrapForm::Datetimepicker
- Defined in:
- lib/bootstrap_form/datetimepicker.rb,
lib/bootstrap_form/datetimepicker/version.rb
Constant Summary collapse
- STRFTIME_MOMENTJS =
{ "a" => "ddd", "A" => "dddd", "b" => "MMM", "B" => "MMMM", "d" => "DD", "H" => "HH", "I" => "hh", "j" => "DDDD", "m" => "MM", "M" => "mm", "p" => "A", "S" => "ss", "Z" => "z", "z" => "ZZ", "w" => "d", "y" => "YY", "Y" => "YYYY", }
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.datetimepicker_format ⇒ Object
Returns the value of attribute datetimepicker_format.
-
.format ⇒ Object
Returns the value of attribute format.
Instance Method Summary collapse
Class Attribute Details
.datetimepicker_format ⇒ Object
Returns the value of attribute datetimepicker_format.
79 80 81 |
# File 'lib/bootstrap_form/datetimepicker.rb', line 79 def datetimepicker_format @datetimepicker_format end |
.format ⇒ Object
Returns the value of attribute format.
79 80 81 |
# File 'lib/bootstrap_form/datetimepicker.rb', line 79 def format @format end |
Instance Method Details
#config ⇒ Object
74 75 76 |
# File 'lib/bootstrap_form/datetimepicker.rb', line 74 def config ::BootstrapForm::Datetimepicker end |
#datetime_picker(method, options = {}) ⇒ Object
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 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bootstrap_form/datetimepicker.rb', line 29 def datetime_picker(method, = {}) datetimepicker_class = .delete(:datetimepicker_class) || "bootstrap_form-datetimepicker" format = .delete(:format) || config.format if format format = Time::DATE_FORMATS[format] if Time::DATE_FORMATS.has_key?(format) else format = "%Y-%m-%d %H:%M:%S %z" end initial_value = object.send(method) if format.respond_to?(:call) [:value] = format.call(initial_value) elsif initial_value.try(:acts_like_time?) [:value] = initial_value.strftime(format) else [:value] = initial_value end datetimepicker_format = .delete(:datetimepicker_format) || config.datetimepicker_format if datetimepicker_format # do nothing elsif format.is_a?(String) datetimepicker_format = strftime2momentjs(format) else datetimepicker_format = "YYYY-MM-DD HH:mm:ss ZZ" end form_group_builder(method, ) do prepend_and_append_input() do input_tag = @template.text_field(object_name, method, ) span_tag = content_tag :span, :class => "input-group-addon" do content_tag :span, "", :class => "glyphicon glyphicon-calendar" end content_tag :div, input_tag.concat(span_tag), :class => "#{datetimepicker_class} input-group date", :data => { "date-format" => datetimepicker_format } end end end |