Adds a css class on menu items in order to apply item specific styles (eg. icons).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2059 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang committed 2008-11-27 18:04:48 +00:00
1 parent 7a441c1bc4
commit 546b98a118
4 files changed
+32 -17

No files matched your search

+9 -9
View File
@@ -106,18 +106,18 @@ Redmine::AccessControl.map do |map|
end
Redmine::MenuManager.map :top_menu do |menu|
menu.push :home, :home_path, :html => { :class => 'home' }
menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }, :last => true
menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }, :last => true
menu.push :home, :home_path
menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
menu.push :help, Redmine::Info.help_url, :last => true
end
Redmine::MenuManager.map :account_menu do |menu|
menu.push :login, :signin_path, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
menu.push :logout, :signout_path, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
end
Redmine::MenuManager.map :application_menu do |menu|
+14 -2
View File
@@ -72,7 +72,7 @@ module Redmine
links = []
menu_items_for(menu, project) do |item, caption, url, selected|
links << content_tag('li',
link_to(h(caption), url, (selected ? item.html_options.merge(:class => 'selected') : item.html_options)))
link_to(h(caption), url, item.html_options(:selected => selected)))
end
links.empty? ? nil : content_tag('ul', links.join("\n"))
end
@@ -168,7 +168,7 @@ module Redmine
class MenuItem
include GLoc
attr_reader :name, :url, :param, :condition, :html_options
attr_reader :name, :url, :param, :condition
def initialize(name, url, options)
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
@@ -179,6 +179,8 @@ module Redmine
@param = options[:param] || :id
@caption = options[:caption]
@html_options = options[:html] || {}
# Adds a unique class to each menu item based on its name
@html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
end
def caption(project=nil)
@@ -191,6 +193,16 @@ module Redmine
@caption_key ||= (@caption || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize))
end
end
def html_options(options={})
if options[:selected]
o = @html_options.dup
o[:class] += ' selected'
o
else
@html_options
end
end
end
end
end