Speeds up WikiHelper#wiki_page_options_for_select.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5080 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ef189164bf
commit
28feb58754
|
@ -18,14 +18,17 @@
|
|||
module WikiHelper
|
||||
|
||||
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
|
||||
pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
|
||||
s = ''
|
||||
pages.select {|p| p.parent == parent}.each do |page|
|
||||
attrs = "value='#{page.id}'"
|
||||
attrs << " selected='selected'" if selected == page
|
||||
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
||||
|
||||
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
|
||||
wiki_page_options_for_select(pages, selected, page, level + 1)
|
||||
if pages.has_key?(parent)
|
||||
pages[parent].each do |page|
|
||||
attrs = "value='#{page.id}'"
|
||||
attrs << " selected='selected'" if selected == page
|
||||
indent = (level > 0) ? (' ' * level * 2 + '» ') : nil
|
||||
|
||||
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
|
||||
wiki_page_options_for_select(pages, selected, page, level + 1)
|
||||
end
|
||||
end
|
||||
s
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue