From e42cf8720e448bf09ba23f8b8fe4b9f81b4ed196 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Mon, 21 Oct 2013 16:47:36 +0800 Subject: [PATCH] Updated Site Preferences with language fix --- app/controllers/application_controller.rb | 3 ++- app/models/site.rb | 4 ++-- app/views/admin/sites/preference.html.erb | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f8f55c64..6067c64d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -158,7 +158,7 @@ class ApplicationController < ActionController::Base end 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_in_use_locales = @site.in_use_locales @site_valid_locales = site_locales_default_head(@site.valid_locales) end @@ -203,6 +203,7 @@ class ApplicationController < ActionController::Base def site_locales_default_head(locales) if locales[0].eql? I18n.locale.to_s + Rails.logger.info locales else a = Array.new(locales) diff --git a/app/models/site.rb b/app/models/site.rb index 32ea8835..609fb44d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -29,6 +29,7 @@ class Site field :school field :department + field :default_locale mount_uploader :default_image, ImageUploader mount_uploader :favicon, ImageUploader @@ -40,7 +41,6 @@ class Site field :sub_menu, localize: true field :terms_of_use, localize: true field :google_analytics - field :default_locale field :mobile_on, :type => Boolean, :default => false @@ -58,7 +58,7 @@ class Site def maximum_enabled_locales size = self.in_use_locales.length if size >= 2 - errors.add(:size, "Max 2 ") + errors.add(:size, "Max 2 values allowed") end end diff --git a/app/views/admin/sites/preference.html.erb b/app/views/admin/sites/preference.html.erb index 670c4222..fc05a602 100644 --- a/app/views/admin/sites/preference.html.erb +++ b/app/views/admin/sites/preference.html.erb @@ -154,8 +154,11 @@
+ <% @site.in_use_locales.each do |locale|%> + <%= locale %> + <% end %> <% @site_valid_locales.each do |valid_locale| %> - <%= check_box_tag "site[enable_locales][]", locale, @site.valid_locales.include?(locale), :class=>"toggle-check", :data => { :title => "#{I18nVariable.from_locale(locale)}" } %> + <%= check_box_tag "site[in_use_locales][]", valid_locale, @site.in_use_locales.include?(valid_locale), :class=>"toggle-check in_use_locales", :data => { :title => "#{I18nVariable.from_locale(valid_locale)}" } %> <% end %>
@@ -164,7 +167,7 @@
<% @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)}" } %> + <%= radio_button_tag "site[default_locale]", locale, @locale == locale ,:class=>"toggle-check in_use_locales", :data => { :title => "#{I18nVariable.from_locale(locale)}" } %> <% end %>
@@ -237,4 +240,15 @@ -<%end%> \ No newline at end of file +<%end%> + \ No newline at end of file