From 8a3f0b9bdc84d8a62f8de1ad01ccda6e74ac0021 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 7 May 2012 15:47:14 +0800 Subject: [PATCH] Add menu_enabled_for: the page can be shown even if there's no link in the menu --- app/models/item.rb | 3 ++- app/views/admin/pages/_form.html.erb | 8 ++++++++ config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/item.rb b/app/models/item.rb index 8cd8bec0..c8b7812c 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -8,6 +8,7 @@ class Item field :position, :type => Integer field :is_published, :type => Boolean, :default => false, :index => true field :enabled_for, :type => Array, :default => nil + field :menu_enabled_for, :type => Array, :default => nil validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ validates :name, :exclusion => { :in => LIST[:forbidden_item_names] } @@ -46,7 +47,7 @@ class Item a = [] if objects objects.each do |object| - a << object if object.enabled_for.nil? ? true : object.enabled_for.include?(I18n.locale.to_s) + a << object if object.menu_enabled_for.nil? ? true : object.menu_enabled_for.include?(I18n.locale.to_s) end end a diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index e06afbc9..7aae7c00 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -33,6 +33,14 @@ <%= f.label :is_published, "#{t('admin.is_published')} ?" %> <%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No

+

+ <%= f.label :menu_enabled_for, "#{t('admin.menu_enabled_for')}:" %> + <% @site_valid_locales.each do |valid_locale| %> + <%= check_box_tag 'page[menu_enabled_for][]', valid_locale, (@item.menu_enabled_for.nil? ? true : @item.menu_enabled_for.include?(valid_locale)) %> + <%= I18nVariable.from_locale(valid_locale) %> + <% end %> + <%= hidden_field_tag 'page[menu_enabled_for][]', '' %> +

<%= f.label :enabled_for, "#{t('admin.enabled_for')}:" %> <% @site_valid_locales.each do |valid_locale| %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 862ccf13..4713415f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -163,6 +163,7 @@ en: list_infos: User information list list_roles: User roles list member: Member + menu_enabled_for: Menu enabled for module: authorization: Module Authorization move_down: Move down diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 27f4a2f6..8e454ec6 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -160,6 +160,7 @@ zh_tw: list_infos: 用戶資料列表 list_roles: 用戶身份列表 member: 會員 + menu_enabled_for: 選單啟用 module: authorization: 模組授權 move_down: 往下移