Updated with some locale fixes in site preferences

This commit is contained in:
saurabhbhatia 2013-10-18 15:24:28 +08:00
parent 7b1b1fa2d3
commit 14fea3638f
7 changed files with 47 additions and 20 deletions

View File

@ -140,21 +140,23 @@ class ApplicationController < ActionController::Base
# update session if passed # update session if passed
session[:locale] = params[:locale] if params[:locale] session[:locale] = params[:locale] if params[:locale]
browser_locale = condition = nil browser_locale = condition = nil
default_locale = @site.default_locale if @site.default_locale.present? default_locale = condition = nil
# check if locale is valid for non site pages
# check if locale is valid for non site pages
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s)
condition = VALID_LOCALES.include?(session[:locale]) condition = VALID_LOCALES.include?(session[:locale])
elsif session[:locale] #check if the default locale is present or not
condition = @site.in_use_locales.include?(session[:locale])
elsif @site.default_locale.present? elsif @site.default_locale.present?
default_locale = @site.default_locale default_locale = @site.default_locale
condition = @site.valid_locales.include?(default_locale) condition = @site.in_use_locales.include?(default_locale)
else elsif !@site.enable_language_detection
#check enable langauge detection
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil
condition = @site.in_use_locales.include?(browser_locale) condition = @site.in_use_locales.include?(browser_locale)
elsif session[:locale]
condition = @site.in_use_locales.include?(session[:locale])
end 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 I18n.locale = session[:locale].to_sym
@site_in_use_locales = site_locales_default_head(@site.in_use_locales) @site_in_use_locales = site_locales_default_head(@site.in_use_locales)
@site_valid_locales = site_locales_default_head(@site.valid_locales) @site_valid_locales = site_locales_default_head(@site.valid_locales)

View File

@ -7,6 +7,7 @@ class Site
field :in_use_locales, :type => Array field :in_use_locales, :type => Array
field :valid_locales, :type => Array field :valid_locales, :type => Array
field :enable_locales, :type => Array
field :roaming_id field :roaming_id
field :private_key, :type => Binary field :private_key, :type => Binary
@ -17,6 +18,7 @@ class Site
field :desktop_closed, :type => Boolean, :default => false field :desktop_closed, :type => Boolean, :default => false
field :sitemap_menu_in_header, :type => Boolean, :default => false field :sitemap_menu_in_header, :type => Boolean, :default => false
field :enable_terms_of_use, :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 :title_always_on, :type => Boolean, :default => false
field :dashbroad_allow_visitor, :type => Boolean, :default => false field :dashbroad_allow_visitor, :type => Boolean, :default => false
@ -44,6 +46,21 @@ class Site
belongs_to :design belongs_to :design
has_many :site_metas, :autosave => true, :dependent => :destroy 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 def generate_keys
private_key = OpenSSL::PKey::RSA.generate(2048) private_key = OpenSSL::PKey::RSA.generate(2048)

View File

@ -1,4 +1,3 @@
<%= Rails.logger.info"@@@@@@@@@@@@@@@@"+design.inspect%>
<tr class="with_action"> <tr class="with_action">
<td class="span1"><%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %></td> <td class="span1"><%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %></td>
<td class="span2"> <td class="span2">

View File

@ -17,7 +17,6 @@
<fieldset> <fieldset>
<!-- Input Area --> <!-- Input Area -->
<div class="input-area"> <div class="input-area">
<div class="nav-name"><strong>Classification</strong></div> <div class="nav-name"><strong>Classification</strong></div>
@ -127,7 +126,7 @@
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label muted">Disable personal desktop</label> <label class="control-label muted"><%= I18n.t('site.enable_personal_desktop')%></label>
<div class="controls"> <div class="controls">
<%= f.check_box :desktop_closed , :class=>"toggle-check" %> <%= f.check_box :desktop_closed , :class=>"toggle-check" %>
</div> </div>
@ -143,23 +142,29 @@
<input type="checkbox" class="toggle-check" data-disabled="true"> <input type="checkbox" class="toggle-check" data-disabled="true">
</div> </div>
</div> --> </div> -->
<!-- Terms of Use -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted">Default Language</label> <label class="control-label muted">Enable User Language Detection
</label>
<div class="controls"> <div class="controls">
<%= @site_in_use_locales %> <%= f.check_box :enable_language_detection, :class => "toggle-check" %>
</div>
</div>
<% @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 %>
</div>
</div>
<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_valid_locales.each do |valid_locale| %> <% @site_valid_locales.each do |valid_locale| %>
<%= check_box_tag "site[in_use_locales][]", locale, @site.valid_locales.include?(locale), :class=>"toggle-check" %> <%= check_box_tag "site[enable_locales][]", locale, @site.valid_locales.include?(locale), :class=>"toggle-check", :data => { :title => "#{I18nVariable.from_locale(locale)}" } %>
<%= I18nVariable.from_locale(valid_locale) %> <% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Default Language</label>
<div class="controls">
<% @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 %> <% end %>
</div> </div>
</div> </div>

View File

@ -21,11 +21,13 @@
</li> </li>
<!-- Desktop --> <!-- Desktop -->
<% if !@site.desktop_closed%>
<li id="orbit-desktop"> <li id="orbit-desktop">
<a href="<%= desktop_path %>" role="button"> <a href="<%= desktop_path %>" role="button">
<i class="icons-screen"></i> <span class="hide"><%= t(:desktop) %></span> <i class="icons-screen"></i> <span class="hide"><%= t(:desktop) %></span>
</a> </a>
</li> </li>
<% end %>
</ul> </ul>
<% if @site.default_image.present?%> <% if @site.default_image.present?%>

View File

@ -391,6 +391,7 @@ en:
footer_help: Footer Guide footer_help: Footer Guide
frontend_closed: Frontend Closed frontend_closed: Frontend Closed
frontend_open: Frontend Open frontend_open: Frontend Open
enable_personal_desktop: Enable Personal Desktop
header: Site header header: Site header
info: Site information info: Site information
keywords: Site keywords keywords: Site keywords

View File

@ -385,8 +385,9 @@ zh_tw:
thumbnail: 縮圖 thumbnail: 縮圖
site: site:
frontend_closed: 前台關閉? frontend_closed: 前台關閉?
frontend_open: 前台關閉 ? frontend_open: 開啟前台
backend_openness_on: 開啟開放式後台(訪客可遊覽) backend_openness_on: 開啟開放式後台(訪客可遊覽)
enable_personal_desktop: 開啟個人桌面
default_image: 預設圖像 default_image: 預設圖像
description: 網站描述 description: 網站描述
description_help: 網站描述說明 description_help: 網站描述說明