Skip to content

Instantly share code, notes, and snippets.

@MischaTheEvil
Created April 28, 2009 23:50
Show Gist options
  • Save MischaTheEvil/103483 to your computer and use it in GitHub Desktop.
Save MischaTheEvil/103483 to your computer and use it in GitHub Desktop.
Global Menu Renderer helper
# Renders the global menu as an unordered list
# Returns a string containing the HTML for the global menu
def render_global_menu
s = ''
s << "<ul>\n"
# Global issues link
s << "<li>" +
# Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == index && != :project_id == nil)
if params[:controller] == 'issues' && params[:action] == 'index' && params[:project_id] == nil
link_to l(:label_issue_view_all), { :controller => 'issues', :id => nil }, :class => 'alt-selected'
else
link_to l(:label_issue_view_all), { :controller => 'issues', :id => nil }
end
s << "</li>\n"
# Global activity link
s << "<li>" +
# Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == projects && != :action == activity && != :id == nil)
if params[:controller] == 'projects' && params[:action] == 'activity' && params[:id] == nil
link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity', :id => nil }, :class => 'alt-selected'
else
link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity', :id => nil }
end
s << "</li>\n"
# Global calendar link
# s << "<li>" +
s << "<li>"
# Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == calendar && != :project_id == nil)
if params[:controller] == 'issues' && params[:action] == 'calendar' && params[:project_id] == nil
s << link_to(l(:label_calendar), { :controller => 'issues', :action => 'calendar', :project_id => nil }, :class => 'alt-selected') if User.current.allowed_to?(:view_calendar, @project, :global => true)
else
s << link_to(l(:label_calendar), { :controller => 'issues', :action => 'calendar', :project_id => nil }) if User.current.allowed_to?(:view_calendar, @project, :global => true)
end
s << "</li>\n"
# Global gantt link
# s << "<li>" +
s << "<li>"
# Add 'alt-selected'-class to the 'a'-element if on global level (!= :controller == issues && != :action == gantt && != :project_id == nil)
if params[:controller] == 'issues' && params[:action] == 'gantt' && params[:project_id] == nil
s << link_to(l(:label_gantt), { :controller => 'issues', :action => 'gantt', :project_id => nil }, :class => 'alt-selected') if User.current.allowed_to?(:view_gantt, @project, :global => true)
else
s << link_to(l(:label_gantt), { :controller => 'issues', :action => 'gantt', :project_id => nil }) if User.current.allowed_to?(:view_gantt, @project, :global => true)
end
s << "</li>\n"
s << "</ul>\n"
return s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment