DataetimepickerInJuty
This commit is contained in:
66
app/inputs/date_picker_input.rb
Normal file
66
app/inputs/date_picker_input.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
class DatePickerInput < SimpleForm::Inputs::StringInput
|
||||
def input(wrapper_options)
|
||||
set_html_options
|
||||
set_value_html_option
|
||||
|
||||
template.content_tag :div, class: 'input-group date datetimepicker' do
|
||||
input = super(wrapper_options) # leave StringInput do the real rendering
|
||||
input + input_button
|
||||
end
|
||||
end
|
||||
|
||||
def input_html_classes
|
||||
super.push '' # 'form-control'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def input_button
|
||||
template.content_tag :span, class: 'input-group-btn' do
|
||||
template.content_tag :button, class: 'btn btn-default', type: 'button' do
|
||||
template.content_tag :span, '', class: 'fa fa-calendar'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_html_options
|
||||
input_html_options[:type] = 'text'
|
||||
input_html_options[:data] ||= {}
|
||||
input_html_options[:data].merge!(date_options: date_options)
|
||||
end
|
||||
|
||||
def set_value_html_option
|
||||
return unless value.present?
|
||||
input_html_options[:value] ||= I18n.localize(value, format: display_pattern)
|
||||
end
|
||||
|
||||
def value
|
||||
object.send(attribute_name) if object.respond_to? attribute_name
|
||||
end
|
||||
|
||||
def display_pattern
|
||||
I18n.t('datepicker.dformat', default: '%d/%m/%Y')
|
||||
end
|
||||
|
||||
def picker_pattern
|
||||
I18n.t('datepicker.pformat', default: 'DD/MM/YYYY')
|
||||
end
|
||||
|
||||
def date_view_header_format
|
||||
I18n.t('dayViewHeaderFormat', default: 'MMMM YYYY')
|
||||
end
|
||||
|
||||
def date_options_base
|
||||
{
|
||||
locale: I18n.locale.to_s,
|
||||
format: picker_pattern,
|
||||
dayViewHeaderFormat: date_view_header_format
|
||||
}
|
||||
end
|
||||
|
||||
def date_options
|
||||
custom_options = input_html_options[:data][:date_options] || {}
|
||||
date_options_base.merge!(custom_options)
|
||||
end
|
||||
|
||||
end
|
||||
13
app/inputs/datetime_picker_input.rb
Normal file
13
app/inputs/datetime_picker_input.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class DatetimePickerInput < DatePickerInput
|
||||
private
|
||||
|
||||
def display_pattern
|
||||
I18n.t('datepicker.dformat', default: '%d/%m/%Y') + ' ' +
|
||||
I18n.t('timepicker.dformat', default: '%R')
|
||||
end
|
||||
|
||||
def picker_pattern
|
||||
I18n.t('datepicker.pformat', default: 'DD/MM/YYYY') + ' ' +
|
||||
I18n.t('timepicker.pformat', default: 'HH:mm')
|
||||
end
|
||||
end
|
||||
15
app/inputs/time_picker_input.rb
Normal file
15
app/inputs/time_picker_input.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class TimePickerInput < DatePickerInput
|
||||
private
|
||||
|
||||
def display_pattern
|
||||
I18n.t('timepicker.dformat', default: '%R')
|
||||
end
|
||||
|
||||
def picker_pattern
|
||||
I18n.t('timepicker.pformat', default: 'HH:mm')
|
||||
end
|
||||
|
||||
def date_options
|
||||
date_options_base
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user