Makes the project jump box work.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/work@2159 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2008-12-21 08:03:24 +00:00
parent 1f75a1f957
commit 2891ba2933
3 changed files with 29 additions and 13 deletions
@@ -147,6 +147,34 @@ module ApplicationHelper
end
content
end
# Renders the project quick-jump box
def render_project_jump_box
# Retrieve them now to avoid a COUNT query
projects = User.current.projects.all
if projects.any?
s = '<select onchange="if (this.value != '') { window.location = this.value; }">' +
"<option selected='selected'>#{ l(:label_jump_to_a_project) }</option>" +
'<option disabled="disabled">---</option>'
ancestors = []
project_tree(projects) do |project, level|
s << content_tag('option', ('&#187; ' * level) + h(project), :value => url_for(:controller => 'projects', :action => 'show', :id => project))
end
s << '</select>'
end
end
# Yields the given block for each project with its level in the tree
def project_tree(projects, &block)
ancestors = []
projects.sort_by(&:lft).each do |project|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
ancestors.pop
end
yield project, ancestors.size
ancestors << project
end
end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)