Module: ActiveScaffold::Bridges::DatePickerBridge
- Defined in:
- lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb
Defined Under Namespace
Modules: DatepickerColumnHelpers, FormColumnHelpers, SearchColumnHelpers
Constant Summary collapse
- DATE_FORMAT_CONVERSION =
{ '%a' => 'D', '%A' => 'DD', '%b' => 'M', '%B' => 'MM', '%d' => 'dd', '%e' => 'd', '%j' => 'oo', '%m' => 'mm', '%y' => 'y', '%Y' => 'yy', '%H' => 'HH', # options ampm => false '%I' => 'hh', # options ampm => true '%M' => 'mm', '%p' => 'tt', '%S' => 'ss' }
Class Method Summary collapse
- .date_options(locale) ⇒ Object
- .date_options_for_locales ⇒ Object
- .datetime_options(locale) ⇒ Object
- .datetime_options_for_locales ⇒ Object
- .localization ⇒ Object
- .split_datetime_format(datetime_format) ⇒ Object
- .to_datepicker_format(rails_format) ⇒ Object
Class Method Details
.date_options(locale) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 78 def self.(locale) begin = I18n.translate! 'date', :locale => locale = { :closeText => as_(:close), :prevText => as_(:previous), :nextText => as_(:next), :currentText => as_(:today), :monthNames => [:month_names][1, ([:month_names].length - 1)], :monthNamesShort => [:abbr_month_names][1, ([:abbr_month_names].length - 1)], :dayNames => [:day_names], :dayNamesShort => [:abbr_day_names], :dayNamesMin => [:abbr_day_names], :changeYear => true, :changeMonth => true, } begin = I18n.translate! 'active_scaffold.date_picker_options' .merge!() if .is_a? Hash rescue Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{locale}" end unless [:buttonImage].nil? [:buttonImage] = asset_path([:buttonImage]) end js_format = self.to_datepicker_format([:formats][:default]) [:dateFormat] = js_format unless js_format.nil? rescue if locale == I18n.locale raise else nil end end end |
.date_options_for_locales ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 67 def self. I18n.available_locales.collect do |locale| = (locale) if "$.datepicker.regional['#{locale}'] = #{.to_json};" else nil end end.compact.join('') end |
.datetime_options(locale) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 128 def self.(locale) begin rails_time_format = I18n.translate! 'time.formats.default', :locale => locale = I18n.translate! 'datetime.prompts', :locale => locale = {:ampm => false, :hourText => [:hour], :minuteText => [:minute], :secondText => [:second], } begin = I18n.translate! 'active_scaffold.datetime_picker_options' .merge!() if .is_a? Hash rescue Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{locale}" end date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) [:dateFormat] = date_format unless date_format.nil? unless time_format.nil? [:timeFormat] = time_format [:ampm] = true if rails_time_format.include?('%I') end rescue if locale == I18n.locale raise else nil end end end |
.datetime_options_for_locales ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 117 def self. I18n.available_locales.collect do |locale| = (locale) if "$.timepicker.regional['#{locale}'] = #{.to_json};" else nil end end.compact.join('') end |
.localization ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 54 def self.localization "jQuery(function($){ if (typeof($.datepicker) === 'object') { #{} $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); } if (typeof($.timepicker) === 'object') { #{} $.timepicker.setDefaults($.timepicker.regional['#{I18n.locale}']); } });\n" end |
.split_datetime_format(datetime_format) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 175 def self.split_datetime_format(datetime_format) date_format = datetime_format time_format = nil time_start_indicators = %w{HH hh mm tt ss} unless datetime_format.nil? start_indicator = time_start_indicators.detect {|indicator| datetime_format.include?(indicator)} unless start_indicator.nil? pos_time_format = datetime_format.index(start_indicator) date_format = datetime_format.to(pos_time_format - 1) date_format.strip! time_format = datetime_format.from(pos_time_format) end end return date_format, time_format end |
.to_datepicker_format(rails_format) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb', line 161 def self.to_datepicker_format(rails_format) return nil if rails_format.nil? if rails_format =~ /%[cUWwxXZz]/ Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker]") nil else js_format = rails_format.dup DATE_FORMAT_CONVERSION.each do |key, value| js_format.gsub!(Regexp.new("#{key}"), value) end js_format end end |