Skip to content

Instantly share code, notes, and snippets.

@edavis10
Forked from MischaTheEvil/gist:103483
Created April 29, 2009 01:04
Show Gist options
  • Save edavis10/103506 to your computer and use it in GitHub Desktop.
Save edavis10/103506 to your computer and use it in GitHub Desktop.
def menu_item_class(selected=false)
if selected
'alt-selected'
else
''
end
end
# Renders the global menu as an unordered list
# Returns a string containing the HTML for the global menu
def render_global_menu
returning '' do |menu|
menu << "<ul>\n"
# Global issues link
## Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == index && != :project_id == nil)
issues_selected = params[:controller] == 'issues' && params[:action] == 'index' && params[:project_id].nil?
menu << content_tag(:li, link_to(l(:label_issue_view_all), { :controller => 'issues', :id => nil } :class => menu_item_class(issues_selected)))
# Global activity link
## Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == projects && != :action == activity && != :id == nil)
activity_selected = params[:controller] == 'projects' && params[:action] == 'activity' && params[:id].nil?
menu << content_tag(:li, link_to(l(:label_overall_activity), { :controller => 'projects', :action => 'activity', :id => nil }, :class => menu_item_class(activity_selected)))
# Global calendar link
## Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == calendar && != :project_id == nil)
if User.current.allowed_to?(:view_calendar, @project, :global => true)
calendar_selected = params[:controller] == 'issues' && params[:action] == 'calendar' && params[:project_id].nil?
menu << content_tag(:li, link_to(l(:label_calendar), { :controller => 'issues', :action => 'calendar', :project_id => nil }, :class => menu_item_class(calendar_selected)))
end
# Global gantt link
## Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == gantt && != :project_id == nil)
if User.current.allowed_to?(:view_gantt, @project, :global => true)
gnatt_selected = params[:controller] == 'issues' && params[:action] == 'gantt' && params[:project_id].nil?
menu << content_tag(:li, link_to(l(:label_gantt), { :controller => 'issues', :action => 'gantt', :project_id => nil }, :class => menu_item_class(gnatt_selected)))
end
menu << "</ul>\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment