From 48f8fbde7ff6c6e060f67b67fd44f4ef228c8a39 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 7 May 2012 00:53:52 +0800 Subject: [PATCH] Fix site_locale_default_head and active for current locale --- app/controllers/application_controller.rb | 14 ++++++++++++-- app/helpers/admin/ad_images_helper.rb | 4 ---- app/helpers/application_helper.rb | 10 ++++------ app/views/admin/ad_images/_form.html.erb | 8 ++++---- .../announcement/back_end/bulletins/_form.html.erb | 4 ++-- .../news/back_end/news_bulletins/_form.html.erb | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 68f49e3b..494b497e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/helpers/admin/ad_images_helper.rb b/app/helpers/admin/ad_images_helper.rb index 1f2422fc..b09bd263 100644 --- a/app/helpers/admin/ad_images_helper.rb +++ b/app/helpers/admin/ad_images_helper.rb @@ -1,7 +1,3 @@ module Admin::AdImagesHelper - def active_when_default_locale_eq locale - locale.to_sym == I18n.default_locale ? 'active': '' - end - end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c36a420f..c59f16c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index cd04b4fe..be5f2b47 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -130,14 +130,14 @@
<%= 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%>
<%= f.fields_for :title,@ad_image.title do |f| %> <%= f.text_field locale,:class=>"ad_image-title post-title",:placeholder => "輸入標題"%> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 23557206..59cfa538 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -126,7 +126,7 @@ @@ -134,7 +134,7 @@
<%# @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| %>
"> diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb index ce00b63f..38c2db31 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb @@ -126,7 +126,7 @@ @@ -134,7 +134,7 @@
<%# @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| %>
">