Revision 1172
Added by Jean-Philippe Lang over 17 years ago
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
trunk/extra/sample_plugin/init.rb | ||
---|---|---|
21 | 21 |
end |
22 | 22 |
|
23 | 23 |
# A new item is added to the project menu |
24 |
menu :project_menu, :label_plugin_example, :controller => 'example', :action => 'say_hello'
|
|
24 |
menu :project_menu, :sample_plugin, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample'
|
|
25 | 25 |
end |
trunk/lib/redmine/menu_manager.rb | ||
---|---|---|
122 | 122 |
|
123 | 123 |
class MenuItem |
124 | 124 |
include GLoc |
125 |
attr_reader :name, :url, :param, :condition, :caption, :html_options
|
|
125 |
attr_reader :name, :url, :param, :condition, :html_options |
|
126 | 126 |
|
127 | 127 |
def initialize(name, url, options) |
128 | 128 |
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) |
... | ... | |
131 | 131 |
@url = url |
132 | 132 |
@condition = options[:if] |
133 | 133 |
@param = options[:param] || :id |
134 |
@caption = options[:caption] || (l_has_string?("label_#{name}".to_sym) ? "label_#{name}".to_sym : name.to_s.humanize)
|
|
134 |
@caption_key = options[:caption]
|
|
135 | 135 |
@html_options = options[:html] || {} |
136 | 136 |
end |
137 |
|
|
138 |
def caption |
|
139 |
# check if localized string exists on first render (after GLoc strings are loaded) |
|
140 |
@caption ||= (@caption_key || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize)) |
|
141 |
end |
|
137 | 142 |
end |
138 | 143 |
end |
139 | 144 |
end |
trunk/lib/redmine/plugin.rb | ||
---|---|---|
66 | 66 |
|
67 | 67 |
# Adds an item to the given +menu+. |
68 | 68 |
# The +id+ parameter (equals to the project id) is automatically added to the url. |
69 |
# menu :project_menu, :label_plugin_example, :controller => 'example', :action => 'say_hello'
|
|
69 |
# menu :project_menu, :plugin_example, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample'
|
|
70 | 70 |
# |
71 |
# Currently, only the project menu can be extended. Thus, the +name+ parameter must be +:project_menu+ |
|
72 |
def menu(name, label, url) |
|
73 |
Redmine::MenuManager.map(name) {|menu| menu.push label, url} |
|
71 |
# +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu |
|
72 |
# |
|
73 |
def menu(name, item, url, options={}) |
|
74 |
Redmine::MenuManager.map(name) {|menu| menu.push item, url, options} |
|
74 | 75 |
end |
75 | 76 |
|
76 | 77 |
# Defines a permission called +name+ for the given +actions+. |
Also available in: Unified diff