Updated Site Preferences with language fix

This commit is contained in:
saurabhbhatia 2013-10-21 16:47:36 +08:00
parent ace582be0c
commit e42cf8720e
3 changed files with 21 additions and 6 deletions

View File

@ -158,7 +158,7 @@ class ApplicationController < ActionController::Base
end end
session[:locale] = condition ? (default_locale || browser_locale || session[: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 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) @site_valid_locales = site_locales_default_head(@site.valid_locales)
end end
@ -203,6 +203,7 @@ class ApplicationController < ActionController::Base
def site_locales_default_head(locales) def site_locales_default_head(locales)
if locales[0].eql? I18n.locale.to_s if locales[0].eql? I18n.locale.to_s
Rails.logger.info
locales locales
else else
a = Array.new(locales) a = Array.new(locales)

View File

@ -29,6 +29,7 @@ class Site
field :school field :school
field :department field :department
field :default_locale
mount_uploader :default_image, ImageUploader mount_uploader :default_image, ImageUploader
mount_uploader :favicon, ImageUploader mount_uploader :favicon, ImageUploader
@ -40,7 +41,6 @@ class Site
field :sub_menu, localize: true field :sub_menu, localize: true
field :terms_of_use, localize: true field :terms_of_use, localize: true
field :google_analytics field :google_analytics
field :default_locale
field :mobile_on, :type => Boolean, :default => false field :mobile_on, :type => Boolean, :default => false
@ -58,7 +58,7 @@ class Site
def maximum_enabled_locales def maximum_enabled_locales
size = self.in_use_locales.length size = self.in_use_locales.length
if size >= 2 if size >= 2
errors.add(:size, "Max 2 ") errors.add(:size, "Max 2 values allowed")
end end
end end

View File

@ -154,8 +154,11 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted">Enable Language</label> <label class="control-label muted">Enable Language</label>
<div class="controls"> <div class="controls">
<% @site.in_use_locales.each do |locale|%>
<%= locale %>
<% end %>
<% @site_valid_locales.each do |valid_locale| %> <% @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 %> <% end %>
</div> </div>
</div> </div>
@ -164,7 +167,7 @@
<label class="control-label muted">Default Language</label> <label class="control-label muted">Default Language</label>
<div class="controls"> <div class="controls">
<% @site_in_use_locales.each do |locale| %> <% @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 %> <% end %>
</div> </div>
</div> </div>
@ -238,3 +241,14 @@
</fieldset> </fieldset>
<%end%> <%end%>
<script type="text/javascript">
$(document).ready(function(){
$( ".in_use_locales" ).each( function(){
if( $( this ).val() != "" ){
$( this ).parent( "div.togglebox" ).removeClass( "disabled" );
}
})
})
</script>