Menus items:
* fixed broken translation when a plugin is installed (closes #649) * small fix to the plugin API: options parameter added to Redmine::Plugin#menu git-svn-id: http://redmine.rubyforge.org/svn/trunk@1172 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b0bb41ad35
commit
792b7f30e3
|
@ -21,5 +21,5 @@ Redmine::Plugin.register :sample_plugin do
|
||||||
end
|
end
|
||||||
|
|
||||||
# A new item is added to the project menu
|
# A new item is added to the project menu
|
||||||
menu :project_menu, :label_plugin_example, :controller => 'example', :action => 'say_hello'
|
menu :project_menu, :sample_plugin, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample'
|
||||||
end
|
end
|
||||||
|
|
|
@ -122,7 +122,7 @@ module Redmine
|
||||||
|
|
||||||
class MenuItem
|
class MenuItem
|
||||||
include GLoc
|
include GLoc
|
||||||
attr_reader :name, :url, :param, :condition, :caption, :html_options
|
attr_reader :name, :url, :param, :condition, :html_options
|
||||||
|
|
||||||
def initialize(name, url, options)
|
def initialize(name, url, options)
|
||||||
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
|
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
|
||||||
|
@ -131,9 +131,14 @@ module Redmine
|
||||||
@url = url
|
@url = url
|
||||||
@condition = options[:if]
|
@condition = options[:if]
|
||||||
@param = options[:param] || :id
|
@param = options[:param] || :id
|
||||||
@caption = options[:caption] || (l_has_string?("label_#{name}".to_sym) ? "label_#{name}".to_sym : name.to_s.humanize)
|
@caption_key = options[:caption]
|
||||||
@html_options = options[:html] || {}
|
@html_options = options[:html] || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def caption
|
||||||
|
# check if localized string exists on first render (after GLoc strings are loaded)
|
||||||
|
@caption ||= (@caption_key || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,11 +66,12 @@ module Redmine #:nodoc:
|
||||||
|
|
||||||
# Adds an item to the given +menu+.
|
# Adds an item to the given +menu+.
|
||||||
# The +id+ parameter (equals to the project id) is automatically added to the url.
|
# The +id+ parameter (equals to the project id) is automatically added to the url.
|
||||||
# menu :project_menu, :label_plugin_example, :controller => 'example', :action => 'say_hello'
|
# menu :project_menu, :plugin_example, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample'
|
||||||
#
|
#
|
||||||
# Currently, only the project menu can be extended. Thus, the +name+ parameter must be +:project_menu+
|
# +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu
|
||||||
def menu(name, label, url)
|
#
|
||||||
Redmine::MenuManager.map(name) {|menu| menu.push label, url}
|
def menu(name, item, url, options={})
|
||||||
|
Redmine::MenuManager.map(name) {|menu| menu.push item, url, options}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines a permission called +name+ for the given +actions+.
|
# Defines a permission called +name+ for the given +actions+.
|
||||||
|
|
Loading…
Reference in New Issue