Adaptive display of "Per page" links (#7720).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9664 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-05-10 18:51:11 +00:00
parent 0bb937152b
commit 5bd90548b0
2 changed files with 31 additions and 4 deletions
+16 -4
View File
@@ -399,7 +399,7 @@ module ApplicationHelper
unless count.nil?
html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
if per_page_links != false && links = per_page_links(paginator.items_per_page)
if per_page_links != false && links = per_page_links(paginator.items_per_page, count)
html << " | #{links}"
end
end
@@ -407,11 +407,23 @@ module ApplicationHelper
html.html_safe
end
def per_page_links(selected=nil)
links = Setting.per_page_options_array.collect do |n|
def per_page_links(selected=nil, item_count=nil)
values = Setting.per_page_options_array
if item_count && values.any?
if item_count > values.first
max = values.detect {|value| value >= item_count} || item_count
else
max = item_count
end
values = values.select {|value| value <= max || value == selected}
end
if values.empty? || (values.size == 1 && values.first == selected)
return nil
end
links = values.collect do |n|
n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
end
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
l(:label_display_per_page, links.join(', '))
end
def reorder_links(name, url, method = :post)