Module: JqueryDatetimepick_instance

Included in:
JqueryDatetimepick::InstanceTag
Defined in:
lib/jquery_datetimepick/form_helper.rb

Constant Summary collapse

FORMAT_REPLACEMENTES =
{ "yy" => "%Y", "mm" => "%m", "dd" => "%d", "d" => "%-d", "m" => "%-m", "y" => "%y", "M" => "%b", "hh" => "%H", "h" => "%I", "MM" => "%M"}

Instance Method Summary collapse

Instance Method Details

#available_datetimepicker_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jquery_datetimepick/form_helper.rb', line 55

def available_datetimepicker_options
  [ :altField, :altFormat, :appendText, :autoSize, :alwaysSetTime, :altFieldTimeOnly, :altTimeFormat, :altSeparator,
    :altTimeSuffix, :addSliderAccess,
    :buttonImage, :buttonImageOnly, :buttonText,
    :calculateWeek, :changeMonth, :changeYear, :closeText, :constrainInput, :currentText, :controlType,
    :disabled, :dateFormat, :dayNames, :dayNamesMin, :dayNamesShort, :defaultDate, :duration, :defaultValue,
    :firstDay,
    :gotoCurrent,
    :hideIfNoPrevNext, :hourMin, :hourMax, :hourGrid,
    :isRTL,
    :maxDate, :minDate, :monthNames, :monthNamesShort, :minuteMin, :millisecMin, :microsecMin, :minuteMax, :millisecMax, :microsecMax,
    :minuteGrid, :millisecGrid, :microsecGrid, :minDateTime, :maxDateTime,
    :navigationAsDateFormat, :nextText, :numberOfMonths,
    :prevText,
    :selectOtherMonths, :shortYearCutoff, :showAnim, :showButtonPanel, :showCurrentAtPos,
    :showMonthAfterYear, :showOn, :showOptions, :showOtherMonths, :showWeek, :stepMonths,
    :showHour, :showMinute, :showSecond, :showMilliSecond, :showMicrosec, :showTimewone,
    :showTime,:stepHour, :stepMinute, :stepSecond, :stepMillisec, :stepMicrosec, :secondMin, :secondMax,
    :secondGrid, :separator, :showTimepicker,
    :timeOnly, :timezonelist,
    :weekHeader,
    :yearRange, :yearSuffix]
end

#format_datetime(tb_formatted, format) ⇒ Object



84
85
86
87
# File 'lib/jquery_datetimepick/form_helper.rb', line 84

def format_datetime(tb_formatted, format)
  new_format = translate_format(format)
  DateTime.parse(tb_formatted).strftime(new_format)
end

#get_name_and_id(options = {}) ⇒ Object

Extending ActionView::Helpers::InstanceTag module to make Rails build the name and id Just returns the options before generate the HTML in order to use the same id and name (see to_input_field_tag mehtod)



50
51
52
53
# File 'lib/jquery_datetimepick/form_helper.rb', line 50

def get_name_and_id(options = {})
  add_default_name_and_id(options)
  options
end

#split_options(options) ⇒ Object



79
80
81
82
# File 'lib/jquery_datetimepick/form_helper.rb', line 79

def split_options(options)
  tf_options = options.slice!(*available_datetimepicker_options)
  return options, tf_options
end

#translate_format(format) ⇒ Object

Method that translates the datepicker date formats, defined in (docs.jquery.com/UI/Datepicker/formatDate) to the ruby standard format (www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime). This gem is not going to support all the options, just the most used.



93
94
95
# File 'lib/jquery_datetimepick/form_helper.rb', line 93

def translate_format(format)
  format.gsub!(/#{FORMAT_REPLACEMENTES.keys.join("|")}/) { |match| FORMAT_REPLACEMENTES[match] }
end