specify timezone in configuration (closes foodcoops#282)
This commit is contained in:
parent
daae87f6d5
commit
3fee071a10
6 changed files with 22 additions and 1 deletions
|
@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
|
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
|
||||||
after_filter :remove_controller
|
after_filter :remove_controller
|
||||||
|
around_filter :set_time_zone
|
||||||
|
|
||||||
|
|
||||||
# Returns the controller handling the current request.
|
# Returns the controller handling the current request.
|
||||||
|
@ -168,4 +169,15 @@ class ApplicationController < ActionController::Base
|
||||||
{foodcoop: FoodsoftConfig.scope}
|
{foodcoop: FoodsoftConfig.scope}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set timezone according to foodcoop preference.
|
||||||
|
# @see http://stackoverflow.com/questions/4362663/timezone-with-rails-3
|
||||||
|
# @see http://archives.ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones
|
||||||
|
def set_time_zone
|
||||||
|
old_time_zone = Time.zone
|
||||||
|
Time.zone = FoodsoftConfig[:time_zone] if FoodsoftConfig[:time_zone]
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Time.zone = old_time_zone
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ module Admin::ConfigsHelper
|
||||||
# @param options [Hash] Options passed to the form builder.
|
# @param options [Hash] Options passed to the form builder.
|
||||||
# @option options [Boolean] :required Wether field is shown as required (default not).
|
# @option options [Boolean] :required Wether field is shown as required (default not).
|
||||||
# @return [String] Form input for configuration key.
|
# @return [String] Form input for configuration key.
|
||||||
|
# @todo find way to pass current value to time_zone input without using default
|
||||||
def config_input(form, key, options = {}, &block)
|
def config_input(form, key, options = {}, &block)
|
||||||
return unless @cfg.allowed_key? key
|
return unless @cfg.allowed_key? key
|
||||||
options[:label] = config_input_label(form, key)
|
options[:label] = config_input_label(form, key)
|
||||||
|
@ -21,6 +22,9 @@ module Admin::ConfigsHelper
|
||||||
elsif options[:collection] or options[:as] == :select
|
elsif options[:collection] or options[:as] == :select
|
||||||
options[:selected] = options[:input_html].delete(:value)
|
options[:selected] = options[:input_html].delete(:value)
|
||||||
return form.input key, options, &block
|
return form.input key, options, &block
|
||||||
|
elsif options[:as] == :time_zone
|
||||||
|
options[:default] = options[:input_html].delete(:value)
|
||||||
|
return form.input key, options, &block
|
||||||
end
|
end
|
||||||
form.input key, options, &block
|
form.input key, options, &block
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
= config_input form, :default_locale,
|
= config_input form, :default_locale,
|
||||||
collection: I18n.available_locales.map {|l| [t("simple_form.options.settings.profile.language.#{l}"), l]}
|
collection: I18n.available_locales.map {|l| [t("simple_form.options.settings.profile.language.#{l}"), l]}
|
||||||
= config_input form, :ignore_browser_locale, as: :boolean
|
= config_input form, :ignore_browser_locale, as: :boolean
|
||||||
|
= config_input form, :time_zone, as: :time_zone, include_blank: true, input_html: {class: 'input-xlarge'}
|
||||||
|
|
|
@ -37,6 +37,8 @@ default: &defaults
|
||||||
# In case you really want foodsoft in a certain language by default, set this to true.
|
# In case you really want foodsoft in a certain language by default, set this to true.
|
||||||
# When members are logged in, the language from their profile settings is still used.
|
# When members are logged in, the language from their profile settings is still used.
|
||||||
#ignore_browser_locale: false
|
#ignore_browser_locale: false
|
||||||
|
# Default timezone, e.g. UTC, Amsterdam, Berlin, etc.
|
||||||
|
#time_zone: Berlin
|
||||||
|
|
||||||
# price markup in percent
|
# price markup in percent
|
||||||
price_markup: 2.0
|
price_markup: 2.0
|
||||||
|
|
|
@ -504,6 +504,7 @@ en:
|
||||||
pdf_font_size: Font size
|
pdf_font_size: Font size
|
||||||
pdf_page_size: Page size
|
pdf_page_size: Page size
|
||||||
pdf_add_page_breaks: Page breaks
|
pdf_add_page_breaks: Page breaks
|
||||||
|
time_zone: Time zone
|
||||||
deliveries:
|
deliveries:
|
||||||
add_stock_change:
|
add_stock_change:
|
||||||
how_many_units: 'How many units (%{unit}) to deliver? Stock article name: %{name}.'
|
how_many_units: 'How many units (%{unit}) to deliver? Stock article name: %{name}.'
|
||||||
|
|
|
@ -487,6 +487,7 @@ nl:
|
||||||
pdf_font_size: Tekstgrootte
|
pdf_font_size: Tekstgrootte
|
||||||
pdf_page_size: Paginaformaat
|
pdf_page_size: Paginaformaat
|
||||||
pdf_add_page_breaks: "Nieuwe pagina's"
|
pdf_add_page_breaks: "Nieuwe pagina's"
|
||||||
|
time_zone: Tijdzone
|
||||||
deliveries:
|
deliveries:
|
||||||
add_stock_change:
|
add_stock_change:
|
||||||
how_many_units: 'Hoeveel eenheden (%{unit}) leveren? Voorraadartikel: %{name}.'
|
how_many_units: 'Hoeveel eenheden (%{unit}) leveren? Voorraadartikel: %{name}.'
|
||||||
|
|
Loading…
Reference in a new issue