@@ -21,5 +21,5 Redmine::Plugin.register :sample_plugin do | |||||
21 | end |
|
21 | end | |
22 |
|
22 | |||
23 | # A new item is added to the project menu |
|
23 | # A new item is added to the project menu | |
24 |
menu :project_menu, :l |
|
24 | menu :project_menu, :sample_plugin, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample' | |
25 | end |
|
25 | end |
@@ -122,7 +122,7 module Redmine | |||||
122 |
|
122 | |||
123 | class MenuItem |
|
123 | class MenuItem | |
124 | include GLoc |
|
124 | include GLoc | |
125 |
attr_reader :name, :url, :param, :condition, |
|
125 | attr_reader :name, :url, :param, :condition, :html_options | |
126 |
|
126 | |||
127 | def initialize(name, url, options) |
|
127 | def initialize(name, url, options) | |
128 | raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) |
|
128 | raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) | |
@@ -131,9 +131,14 module Redmine | |||||
131 | @url = url |
|
131 | @url = url | |
132 | @condition = options[:if] |
|
132 | @condition = options[:if] | |
133 | @param = options[:param] || :id |
|
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 | @html_options = options[:html] || {} |
|
135 | @html_options = options[:html] || {} | |
136 | end |
|
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 | end |
|
142 | end | |
138 | end |
|
143 | end | |
139 | end |
|
144 | end |
@@ -66,11 +66,12 module Redmine #:nodoc: | |||||
66 |
|
66 | |||
67 | # Adds an item to the given +menu+. |
|
67 | # Adds an item to the given +menu+. | |
68 | # The +id+ parameter (equals to the project id) is automatically added to the url. |
|
68 | # The +id+ parameter (equals to the project id) is automatically added to the url. | |
69 |
# menu :project_menu, : |
|
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+ |
|
71 | # +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu | |
72 | def menu(name, label, url) |
|
72 | # | |
73 | Redmine::MenuManager.map(name) {|menu| menu.push label, url} |
|
73 | def menu(name, item, url, options={}) | |
|
74 | Redmine::MenuManager.map(name) {|menu| menu.push item, url, options} | |||
74 | end |
|
75 | end | |
75 |
|
76 | |||
76 | # Defines a permission called +name+ for the given +actions+. |
|
77 | # Defines a permission called +name+ for the given +actions+. |
General Comments 0
You need to be logged in to leave comments.
Login now