From 14fea3638f2ec092bea5c8426bb18582b2118c23 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Fri, 18 Oct 2013 15:24:28 +0800 Subject: [PATCH] Updated with some locale fixes in site preferences --- app/controllers/application_controller.rb | 16 ++++++++------ app/models/site.rb | 17 ++++++++++++++ app/views/admin/designs/_design.html.erb | 1 - app/views/admin/sites/preference.html.erb | 27 ++++++++++++++--------- app/views/layouts/_left_menu.html.erb | 2 ++ config/locales/en.yml | 1 + config/locales/zh_tw.yml | 3 ++- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 778a7927..f8f55c64 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -140,21 +140,23 @@ class ApplicationController < ActionController::Base # update session if passed session[:locale] = params[:locale] if params[:locale] browser_locale = condition = nil - default_locale = @site.default_locale if @site.default_locale.present? - # check if locale is valid for non site pages + default_locale = condition = nil + # check if locale is valid for non site pages if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) condition = VALID_LOCALES.include?(session[:locale]) - elsif session[:locale] - condition = @site.in_use_locales.include?(session[:locale]) + #check if the default locale is present or not elsif @site.default_locale.present? default_locale = @site.default_locale - condition = @site.valid_locales.include?(default_locale) - else + condition = @site.in_use_locales.include?(default_locale) + elsif !@site.enable_language_detection + #check enable langauge detection browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil condition = @site.in_use_locales.include?(browser_locale) + elsif session[:locale] + condition = @site.in_use_locales.include?(session[:locale]) end - session[:locale] = condition ? ( browser_locale || session[:locale] || default_locale) : I18n.default_locale.to_s + session[:locale] = condition ? (default_locale || browser_locale || session[:locale]) : I18n.default_locale.to_s I18n.locale = session[:locale].to_sym @site_in_use_locales = site_locales_default_head(@site.in_use_locales) @site_valid_locales = site_locales_default_head(@site.valid_locales) diff --git a/app/models/site.rb b/app/models/site.rb index 5304a9d4..32ea8835 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -7,6 +7,7 @@ class Site field :in_use_locales, :type => Array field :valid_locales, :type => Array + field :enable_locales, :type => Array field :roaming_id field :private_key, :type => Binary @@ -17,6 +18,7 @@ class Site field :desktop_closed, :type => Boolean, :default => false field :sitemap_menu_in_header, :type => Boolean, :default => false field :enable_terms_of_use, :type => Boolean, :default => false + field :enable_language_detection, :type => Boolean, :default => false field :title_always_on, :type => Boolean, :default => false field :dashbroad_allow_visitor, :type => Boolean, :default => false @@ -44,6 +46,21 @@ class Site belongs_to :design has_many :site_metas, :autosave => true, :dependent => :destroy + validate :in_use_locales, :minimum_enabled_locales + + def minimum_enabled_locales + size = self.in_use_locales.length + if size < 1 + errors.add(:size, "Needs at least one language in use") + end + end + + def maximum_enabled_locales + size = self.in_use_locales.length + if size >= 2 + errors.add(:size, "Max 2 ") + end + end def generate_keys private_key = OpenSSL::PKey::RSA.generate(2048) diff --git a/app/views/admin/designs/_design.html.erb b/app/views/admin/designs/_design.html.erb index 3b557d5e..24c99b41 100644 --- a/app/views/admin/designs/_design.html.erb +++ b/app/views/admin/designs/_design.html.erb @@ -1,4 +1,3 @@ -<%= Rails.logger.info"@@@@@@@@@@@@@@@@"+design.inspect%> <%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %> diff --git a/app/views/admin/sites/preference.html.erb b/app/views/admin/sites/preference.html.erb index cad47e6c..670c4222 100644 --- a/app/views/admin/sites/preference.html.erb +++ b/app/views/admin/sites/preference.html.erb @@ -17,7 +17,6 @@
-
@@ -127,7 +126,7 @@
- +
<%= f.check_box :desktop_closed , :class=>"toggle-check" %>
@@ -143,27 +142,33 @@
--> +
- +
- <%= @site_in_use_locales %> - - <% @site_in_use_locales.each do |locale| %> - <%= check_box_tag :default_locale, locale, (@site.enabled_for.nil?), :class=>"toggle-check" %> - <%= I18nVariable.from_locale(locale) %> - <% end %> + <%= f.check_box :enable_language_detection, :class => "toggle-check" %>
+
<% @site_valid_locales.each do |valid_locale| %> - <%= check_box_tag "site[in_use_locales][]", locale, @site.valid_locales.include?(locale), :class=>"toggle-check" %> - <%= I18nVariable.from_locale(valid_locale) %> + <%= check_box_tag "site[enable_locales][]", locale, @site.valid_locales.include?(locale), :class=>"toggle-check", :data => { :title => "#{I18nVariable.from_locale(locale)}" } %> <% end %>
+
+ +
+ <% @site_in_use_locales.each do |locale| %> + <%= check_box_tag :default_locale, locale, (@site.default_locale.nil?), :class=>"toggle-check", :data => { :title => "#{I18nVariable.from_locale(locale)}" } %> + <% end %> +
+
+ diff --git a/app/views/layouts/_left_menu.html.erb b/app/views/layouts/_left_menu.html.erb index 772f3389..3117786c 100644 --- a/app/views/layouts/_left_menu.html.erb +++ b/app/views/layouts/_left_menu.html.erb @@ -21,11 +21,13 @@ + <% if !@site.desktop_closed%>
  • <%= t(:desktop) %>
  • + <% end %> <% if @site.default_image.present?%> diff --git a/config/locales/en.yml b/config/locales/en.yml index fd47024f..c51d7fc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -391,6 +391,7 @@ en: footer_help: Footer Guide frontend_closed: Frontend Closed frontend_open: Frontend Open + enable_personal_desktop: Enable Personal Desktop header: Site header info: Site information keywords: Site keywords diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index cc2c92ed..562e7ec4 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -385,8 +385,9 @@ zh_tw: thumbnail: 縮圖 site: frontend_closed: 前台關閉? - frontend_open: 前台關閉 ? + frontend_open: 開啟前台 backend_openness_on: 開啟開放式後台(訪客可遊覽) + enable_personal_desktop: 開啟個人桌面 default_image: 預設圖像 description: 網站描述 description_help: 網站描述說明