specify timezone in configuration (closes foodcoops#282)

This commit is contained in:
wvengen 2014-06-25 17:32:26 +02:00
parent daae87f6d5
commit 3fee071a10
6 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
after_filter :remove_controller
around_filter :set_time_zone
# Returns the controller handling the current request.
@ -167,5 +168,16 @@ class ApplicationController < ActionController::Base
def default_url_options(options = {})
{foodcoop: FoodsoftConfig.scope}
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

View File

@ -7,6 +7,7 @@ module Admin::ConfigsHelper
# @param options [Hash] Options passed to the form builder.
# @option options [Boolean] :required Wether field is shown as required (default not).
# @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)
return unless @cfg.allowed_key? key
options[:label] = config_input_label(form, key)
@ -21,6 +22,9 @@ module Admin::ConfigsHelper
elsif options[:collection] or options[:as] == :select
options[:selected] = options[:input_html].delete(:value)
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
form.input key, options, &block
end

View File

@ -1,3 +1,4 @@
= config_input form, :default_locale,
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, :time_zone, as: :time_zone, include_blank: true, input_html: {class: 'input-xlarge'}

View File

@ -37,6 +37,8 @@ default: &defaults
# 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.
#ignore_browser_locale: false
# Default timezone, e.g. UTC, Amsterdam, Berlin, etc.
#time_zone: Berlin
# price markup in percent
price_markup: 2.0

View File

@ -504,6 +504,7 @@ en:
pdf_font_size: Font size
pdf_page_size: Page size
pdf_add_page_breaks: Page breaks
time_zone: Time zone
deliveries:
add_stock_change:
how_many_units: 'How many units (%{unit}) to deliver? Stock article name: %{name}.'

View File

@ -487,6 +487,7 @@ nl:
pdf_font_size: Tekstgrootte
pdf_page_size: Paginaformaat
pdf_add_page_breaks: "Nieuwe pagina's"
time_zone: Tijdzone
deliveries:
add_stock_change:
how_many_units: 'Hoeveel eenheden (%{unit}) leveren? Voorraadartikel: %{name}.'