Module: Redmine::MenuManager::MenuController

Included in:
ApplicationController
Defined in:
lib/redmine/menu_manager.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



24
25
26
27
28
29
# File 'lib/redmine/menu_manager.rb', line 24

def self.included(base)
  base.class_attribute :main_menu
  base.main_menu = true

  base.extend(ClassMethods)
end

Instance Method Details

#current_menu(project) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/redmine/menu_manager.rb', line 57

def current_menu(project)
  if project && !project.new_record?
    :project_menu
  elsif self.class.main_menu
    :application_menu
  end
end

#current_menu_itemObject

Returns the menu item name according to the current action



66
67
68
69
# File 'lib/redmine/menu_manager.rb', line 66

def current_menu_item
  @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
                           menu_items[controller_name.to_sym][:default]
end


53
54
55
# File 'lib/redmine/menu_manager.rb', line 53

def menu_items
  self.class.menu_items
end

#redirect_to_project_menu_item(project, name) ⇒ Object

Redirects user to the menu item of the given project Returns false if user is not authorized



73
74
75
76
77
78
79
80
# File 'lib/redmine/menu_manager.rb', line 73

def redirect_to_project_menu_item(project, name)
  item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s}
  if item && item.allowed?(User.current, project)
    redirect_to({item.param => project}.merge(item.url))
    return true
  end
  false
end