Changes in datetimepicker to accepts formats in options

This commit is contained in:
chris 2013-08-17 19:45:37 +08:00
parent 897ed49d2e
commit d24bd176cc
3 changed files with 14 additions and 10 deletions

View File

@ -34,8 +34,8 @@ module OrbitFormHelper
def date_picker(object_name, method, options) def date_picker(object_name, method, options)
custom = {} custom = {}
custom[:format] = 'yyyy-MM-dd' custom[:format] = options[:format] || 'yyyy/MM'
custom[:value] = display_date(options[:value]) if options[:value] custom[:value] = format_value(options[:value], custom[:format]) if options[:value]
custom[:picker_class] = 'date_picker' custom[:picker_class] = 'date_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.date.label') custom[:label] = options[:label] || I18n.t('datetime_picker.date.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.date.placeholder') custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.date.placeholder')
@ -44,8 +44,8 @@ module OrbitFormHelper
def default_picker(object_name, method, options) def default_picker(object_name, method, options)
custom = {} custom = {}
custom[:format] = 'yyyy-MM-dd hh:mm' custom[:format] = options[:format] || 'yyyy/MM/dd hh:mm'
custom[:value] = display_date_time(options[:value]) if options[:value] custom[:value] = format_value(options[:value], custom[:format]) if options[:value]
custom[:picker_class] = 'default_picker' custom[:picker_class] = 'default_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.default.label') custom[:label] = options[:label] || I18n.t('datetime_picker.default.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.default.placeholder') custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.default.placeholder')
@ -54,8 +54,8 @@ module OrbitFormHelper
def time_picker(object_name, method, options) def time_picker(object_name, method, options)
custom = {} custom = {}
custom[:format] = 'hh:mm' custom[:format] = options[:format] || 'hh:mm'
custom[:value] = display_time(options[:value]) if options[:value] custom[:value] = format_value(options[:value], custom[:format]) if options[:value]
custom[:picker_class] = 'time_picker' custom[:picker_class] = 'time_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.time.label') custom[:label] = options[:label] || I18n.t('datetime_picker.time.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.time.placeholder') custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.time.placeholder')
@ -93,6 +93,10 @@ module OrbitFormHelper
end end
end end
def format_value(value, format)
value.strftime(format.gsub('yyyy', '%Y').gsub('MM', '%m').gsub('dd', '%d').gsub('hh', '%H').gsub('mm', '%M'))
end
end end
module Orbit::FormBuilder module Orbit::FormBuilder

View File

@ -3,10 +3,10 @@ en:
datetime_picker: datetime_picker:
date: date:
label: Date label: Date
placeholder: "YYYY-MM-DD" placeholder: "YYYY/MM/DD"
default: default:
label: Date and time label: Date and time
placeholder: "YYYY-MM-DD HH:MM" placeholder: "YYYY/MM/DD HH:MM"
separated: separated:
label: Date and time label: Date and time
time: time:

View File

@ -3,10 +3,10 @@ zh_tw:
datetime_picker: datetime_picker:
date: date:
label: 日期 label: 日期
placeholder: "YYYY-MM-DD" placeholder: "YYYY/MM/DD"
default: default:
label: 日期和時間 label: 日期和時間
placeholder: "YYYY-MM-DD HH:MM" placeholder: "YYYY/MM/DD HH:MM"
separated: separated:
label: 日期和時間 label: 日期和時間
time: time: