Class: DrgcmsFormFields::DatetimePicker
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::DatetimePicker
- Defined in:
- app/models/drgcms_form_fields/datetime_picker.rb
Overview
Implementation of date_time_picker DRG CMS form field with help of jQuery DateTimePicker plugin
Form options:
-
type:
datetime_picker (required) -
name:
Field name (required) -
options:
options which apply to date_picker field. All options can be found here xdsoft.net/jqplugins/datetimepicker/ .
Options can be defined in single line like:
-
options: ‘step: 15,inline: true,lang: “sl”’ or
-
options:
-
step: 15
-
inline: true
-
lang: ‘“sl”’
-
-
html:
html options which apply to date_time_picker field (optional)
Form example:
10:
name: valid_to
type: datetime_picker
options: 'step: 60'
Instance Attribute Summary
Attributes inherited from DrgcmsField
Class Method Summary collapse
-
.get_data(params, name) ⇒ Object
DateTimePicker get_data method.
Instance Method Summary collapse
-
#render ⇒ Object
Render date_time_picker field html code.
Methods inherited from DrgcmsField
#__css_code, #hash_to_options, #html, #initialize, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Class Method Details
.get_data(params, name) ⇒ Object
DateTimePicker get_data method.
83 84 85 86 |
# File 'app/models/drgcms_form_fields/datetime_picker.rb', line 83 def self.get_data(params, name) t = params['record'][name] ? params['record'][name].to_datetime : nil t ? Time.zone.local(t.year, t.month, t.day, t.hour, t.min) : nil end |
Instance Method Details
#render ⇒ Object
Render date_time_picker field html code
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/drgcms_form_fields/datetime_picker.rb', line 53 def render value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].localtime) : nil #return ro_standard( @parent.dc_format_value(value)) if @readonly @yaml['options'] ||= {} set_initial_value @yaml['html']['size'] ||= @yaml['size'] || 14 @yaml['html']['value'] ||= value if @record[@yaml['name']] @yaml['html']['autocomplete'] ||= 'off' @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker' @yaml['options']['lang'] ||= "'#{I18n.locale}'" @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'" record = record_text_for(@yaml['name']) @html << @parent.text_field(record, @yaml['name'], @yaml['html']) @js << %Q[ $(document).ready(function() { $("##{record}_#{@yaml['name']}").datetimepicker( { #{(@yaml['options'])} }); }); ] unless @readonly self end |