alert for page not available in language

This commit is contained in:
nccu 2014-11-13 16:24:30 +08:00
parent 7dd20cafa0
commit e1a716f81d
3 changed files with 48 additions and 6 deletions

View File

@ -469,3 +469,23 @@ $orbit-bar-bgc-lighter: lighten($orbit-bar-bgc, 20%) !default;
} }
} }
} }
// Page doesn't exist error message
.modal {
.modal-title {
font-weight: bold;
}
.modal-dialog {
width: 300px;
margin: 130px auto;
}
.modal-footer {
margin: 0;
padding: 10px 10px 10px;
}
p {
font-size: 16px;
}
}

View File

@ -347,12 +347,16 @@ module ApplicationHelper
def switch_language(loc) def switch_language(loc)
url = request.original_fullpath url = request.original_fullpath
locale = url.include?("zh_cn") ? :zh_cn : I18n.locale locale = url.include?("zh_cn") ? :zh_cn : I18n.locale
url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/") url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/")
url = url.gsub("locale=#{locale.to_s}","locale=#{loc.to_s}") if url == request.original_fullpath url = url.gsub("locale=#{locale.to_s}","locale=#{loc.to_s}") if url == request.original_fullpath
url = url + "#{url.include?("?") ? "&" : "?"}locale=#{loc.to_s}" if url == request.original_fullpath and (!url.include?('/'+locale.to_s) or !url.include?(locale.to_s+'=')) url = url + "#{url.include?("?") ? "&" : "?"}locale=#{loc.to_s}" if url == request.original_fullpath and (!url.include?('/'+locale.to_s) or !url.include?(locale.to_s+'='))
if params["page_id"]
page = Page.where(:page_id => params["page_id"]).first rescue nil
if !page.nil?
url = "#language_alert" if !page.enabled_for.include? loc.to_s
end
end
url url
end end

View File

@ -112,11 +112,11 @@
<ul> <ul>
<% @site_in_use_locales.each do |l| %> <% @site_in_use_locales.each do |l| %>
<li class="<%= (l == I18n.locale and !session['zh_cn']) ? "active" : "" %>"> <li class="<%= (l == I18n.locale and !session['zh_cn']) ? "active" : "" %>">
<a href="<%= switch_language(l) %>"><%= t((l==:zh_tw ? :zh_tw_ : :_locale ), :locale => l) %></a> <a href="<%= switch_language(l) %>" data-toggle="modal" ><%= t((l==:zh_tw ? :zh_tw_ : :_locale ), :locale => l) %></a>
</li> </li>
<% if current_site.enable_zh_cn and l == :zh_tw and !request.path.include?("/admin/") %> <% if current_site.enable_zh_cn and l == :zh_tw and !request.path.include?("/admin/") %>
<li class="<%= locale==:zh_cn ? "active" : "" %>"> <li class="<%= locale==:zh_cn ? "active" : "" %>">
<a href="<%= switch_language(:zh_cn) %>"><%= t(:zh_cn, :locale => :zh_tw) %></a> <a href="<%= switch_language(:zh_cn) %>" data-toggle="modal" ><%= t(:zh_cn, :locale => :zh_tw) %></a>
</li> </li>
<% end %> <% end %>
<% end %> <% end %>
@ -144,3 +144,21 @@
</ul> </ul>
</div> </div>
</div> </div>
<% if params[:controller] == "pages" %>
<div class="modal fade" id="language_alert">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">We are sorry.</h4>
</div>
<div class="modal-body">
<p>This page is not available in this language.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<% end %>