Fix site_locale_default_head and active for current locale

This commit is contained in:
Christophe Vilayphiou 2012-05-07 00:53:52 +08:00
parent 51f87e7212
commit 48f8fbde7f
6 changed files with 24 additions and 20 deletions

View File

@ -128,8 +128,8 @@ class ApplicationController < ActionController::Base
# set site if exist or create site
@site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
session[:site] = @site.id
@site_in_use_locales = @site.in_use_locales
@site_valid_locales = @site.valid_locales
@site_in_use_locales = site_locales_default_head(@site.in_use_locales)
@site_valid_locales = site_locales_default_head(@site.valid_locales)
end
def set_current_item
@ -164,4 +164,14 @@ class ApplicationController < ActionController::Base
end
end
def site_locales_default_head(locales)
if locales[0].eql? I18n.locale.to_s
locales
else
a = Array.new(locales)
shift_out = a.delete(I18n.locale.to_s)
[shift_out] + a
end
end
end

View File

@ -1,7 +1,3 @@
module Admin::AdImagesHelper
def active_when_default_locale_eq locale
locale.to_sym == I18n.default_locale ? 'active': ''
end
end

View File

@ -2,12 +2,6 @@ module ApplicationHelper
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def site_valid_locales_default_head
index = @site_valid_locales.rindex I18n.default_locale.to_s
shift_out = @site_valid_locales.shift(index)
@site_valid_locales += shift_out
end
def colorize_in_use_locale(locale)
@site_in_use_locales.include?(locale)? 'green' : 'red'
end
@ -147,4 +141,8 @@ module ApplicationHelper
javascripts
end
def active_when_current_locale_eq(locale)
locale.to_sym == I18n.locale ? 'active': ''
end
end

View File

@ -130,14 +130,14 @@
<div id="post-body">
<div id="post-body-content" class="clear">
<ul class="nav nav-tabs">
<% site_valid_locales_default_head.each do |locale|%>
<%= content_tag :li,link_to(I18nVariable.from_locale(locale),"##{locale}",:data=>{:toggle => "tab"}),:class=> (active_when_default_locale_eq locale) %>
<% @site_valid_locales.each do |locale|%>
<%= content_tag :li,link_to(I18nVariable.from_locale(locale),"##{locale}",:data=>{:toggle => "tab"}),:class=> (active_when_current_locale_eq locale) %>
<% end %>
</ul>
<div class="tab-content">
<%= select_tag 'ad_banner[id]',options_from_collection_for_select(AdBanner.all, "id", "title",params[:ad_banner_id]) , :class=>"input-medium", %>
<% site_valid_locales_default_head.each do |locale|%>
<%= content_tag :div,:class => "tab-pane #{active_when_default_locale_eq locale}",:id=>"#{locale}" do%>
<% @site_valid_locales.each do |locale|%>
<%= content_tag :div,:class => "tab-pane #{active_when_current_locale_eq locale}",:id=>"#{locale}" do%>
<div class="title">
<%= f.fields_for :title,@ad_image.title do |f| %>
<%= f.text_field locale,:class=>"ad_image-title post-title",:placeholder => "輸入標題"%>

View File

@ -126,7 +126,7 @@
<ul class="nav nav-tabs">
<%# @site_valid_locales.each_with_index do |locale, i| %>
<% site_valid_locales_default_head.each_with_index do |locale, i| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? " class='active'" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
@ -134,7 +134,7 @@
<div class="tab-content">
<%# @site_valid_locales.each_with_index do |locale, i| %>
<% site_valid_locales_default_head.each_with_index do |locale, i| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">

View File

@ -126,7 +126,7 @@
<ul class="nav nav-tabs">
<%# @site_valid_locales.each_with_index do |locale, i| %>
<% site_valid_locales_default_head.each_with_index do |locale, i| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? " class='active'" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
@ -134,7 +134,7 @@
<div class="tab-content">
<%# @site_valid_locales.each_with_index do |locale, i| %>
<% site_valid_locales_default_head.each_with_index do |locale, i| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">