Change date picker

This commit is contained in:
chris committed 2013-01-09 05:18:16 +08:00
1 parent 5b13c53ed9
commit fac4faad6c
12 files changed
+1534 -61

No files matched your search

+4
View File
@@ -254,6 +254,10 @@ module ApplicationHelper
object.strftime("%Y-%m-%d")
end
def display_time(object)
object.strftime("%H:%M")
end
def share_links(object, key)
content_tag :div, :class => 'fb' do
concat social_share_button_tag(object.title, :fb_url => generate_fb_url(object,key), :image => "http://#{request.env['HTTP_HOST']}#{object.image_url}")
+99
View File
@@ -0,0 +1,99 @@
module OrbitFormHelper
def self.included(base)
ActionView::Helpers::FormBuilder.send(:include, Orbit::FormBuilder)
end
def datetime_picker(object_name, method, options = {})
options[:icon_time] ||= 'icons-clock'
options[:icon_date] ||= 'icons-calendar'
options[:input_class] ||= 'input-large'
options[:value] ||= options[:object][method] if options[:object] && options[:object][method]
case options[:picker_type]
when 'date'
content_tag :div, :id => options[:id], :class => options[:class] do
date_picker(object_name, method, options)
end
when 'time'
content_tag :div, :id => options[:id], :class => options[:class] do
time_picker(object_name, method, options)
end
when 'separated'
options[:label] ||= I18n.t('datetime_picker.separated.label')
content_tag :div, :id => options[:id], :class => "separated_picker #{options[:class]}" do
concat label_tag options[:label] unless options[:no_label]
concat hidden_field(object_name, method)
concat separated_picker(object_name, method, options)
end
else
content_tag :div, :id => options[:id], :class => options[:class] do
default_picker(object_name, method, options)
end
end
end
def date_picker(object_name, method, options)
custom = {}
custom[:format] = 'yyyy-MM-dd'
custom[:value] = display_date(options[:value]) if options[:value]
custom[:picker_class] = 'date_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.date.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.date.placeholder')
picker(object_name, method, options.merge(custom))
end
def default_picker(object_name, method, options)
custom = {}
custom[:format] = 'yyyy-MM-dd hh:mm'
custom[:value] = display_date_time(options[:value]) if options[:value]
custom[:picker_class] = 'default_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.default.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.default.placeholder')
picker(object_name, method, options.merge(custom))
end
def time_picker(object_name, method, options)
custom = {}
custom[:format] = 'hh:mm'
custom[:value] = display_time(options[:value]) if options[:value]
custom[:picker_class] = 'time_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.time.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.time.placeholder')
picker(object_name, method, options.merge(custom))
end
def separated_picker(object_name, method, options)
custom = {}
custom[:no_label] = true
date_picker(nil, nil, options.merge(custom)) + time_picker(nil, nil, options.merge(custom))
end
def single_picker(object_name, method, options)
content_tag :div, :id => options[:id], :class => options[:class] do
picker(object_name, method, options)
end
end
def double_picker(object_name, method, options)
end
def picker(object_name, method, options)
content_tag :div, :class => "#{options[:picker_class]} input-append" do
concat label_tag options[:label] unless options[:no_label]
concat text_field object_name, method, :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value]
concat (content_tag :span, :class => 'add-on' do
content_tag :i, nil, 'data-time-icon' => options[:icon_time], 'data-date-icon' => options[:icon_date]
end)
end
end
end
module Orbit::FormBuilder
# ActionPack's metaprogramming would have done this for us, if FormHelper#labeled_input
# had been defined at load. Instead we define it ourselves here.
def datetime_picker(method, options = {})
@template.datetime_picker(@object_name, method, objectify_options(options))
end
end