require File.join(File.dirname(__FILE__), '12_hour_time')
module UnobtrusiveDatePicker
DATEPICKER_DEFAULT_NAME_ID_SUFFIXES = { :year => {:id => '', :name => 'year'},
:month => {:id => 'mm', :name => 'month'},
:day => {:id => 'dd', :name => 'day'} }
DATEPICKER_DAYS_OF_WEEK = { :Monday => '0',
:Tuesday => '1',
:Wednesday => '2',
:Thursday => '3',
:Friday => '4',
:Saturday => '5',
:Sunday => '6'}
DATEPICKER_DIVIDERS = { 'slash' => '/',
'dash' => '-',
'dot' => '.',
'space' => ' ' }
RANGE_DATE_FORMAT = '%Y-%m-%d'
# == Unobtrusive Date-Picker Helper
#
# This Module helps to create date and date-time fields that use the
# Unobtrusive Date-Picker Javascript Widget.
#
# They also use the 12-hour AM/PM time format.
#
module UnobtrusiveDatePickerHelper
##
# Creates the date picker with the calendar widget.
#
def unobtrusive_date_picker(object_name, method, options = {}, html_options = {})
ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_datepicker_date_select_tag(options, html_options)
end
##
# Creates the date-time picker with the calendar widget, and AM/PM select.
#
def unobtrusive_datetime_picker(object_name, method, options = {}, html_options = {})
ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_datepicker_datetime_select_tag(options, html_options)
end
##
# Creates the date picker with the calendar widget.
#
def unobtrusive_date_text_picker(object_name, method, options = {}, html_options = {})
ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_datepicker_text_tag(options, html_options)
end
def unobtrusive_datetime_picker_tags(datetime = Time.current, options = {}, html_options = {})
datetime ||= Time.current
DateTimePickerSelector.new(datetime, options.merge(:twelve_hour => true), html_options).select_datetime
end
def unobtrusive_date_picker_tags(date = Date.current, options = {}, html_options = {})
date ||= Date.current
DateTimePickerSelector.new(date, options, html_options).select_date
end
##
# Creates the text field based date picker with the calendar widget without a model object.
#
def unobtrusive_date_text_picker_tag(name, date = Date.current, options = {}, html_options = {})
date ||= Date.current
options = merge_defaults_for_text_picker(options)
DateTimePickerSelector.new(date, options, html_options).text_date_picker(name)
end
private
def merge_defaults_for_text_picker(options)
defaults = {:format => 'm-d-y', :divider => 'slash'}
options = defaults.merge(options)
end
end
module AssetTagHelper
##
# This will add the necessary and