Class: DrgcmsFormFields::DatetimePicker

Inherits:
DrgcmsField show all
Defined in:
app/models/drgcms_form_fields.rb

Overview

options: ‘step: 60’

Instance Attribute Summary

Attributes inherited from DrgcmsField

#html, #js

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DrgcmsField

#hash_to_options, #initialize, #record_text_for, #ro_standard, #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.



1125
1126
1127
1128
# File 'app/models/drgcms_form_fields.rb', line 1125

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

#renderObject

Render date_time_picker field html code



1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
# File 'app/models/drgcms_form_fields.rb', line 1097

def render
  value = (@record and @record[@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'] ||= 14
  @yaml['html']['value'] = value if @record[@yaml['name']]
#
  @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 << <<EOJS
$(document).ready(function() {
  $("##{record}_#{@yaml['name']}").datetimepicker( {
    #{hash_to_options(@yaml['options'])}
  });
});
EOJS
  
  self
end