Fixed items_per_page helper.

This commit is contained in:
benni 2011-06-10 12:03:32 +02:00
parent a47d4b1f0e
commit 689cfcfe01
2 changed files with 8 additions and 20 deletions

View file

@ -28,7 +28,7 @@ module ApplicationHelper
next_label = "Nächste" + ' »' next_label = "Nächste" + ' »'
# Merge other url-options for will_paginate # Merge other url-options for will_paginate
params = params.merge({:per_page => per_page}) params = params.merge({:per_page => per_page})
will_paginate collection, :params => params, 'data-remote' => remote, will_paginate collection, :params => params, 'data-remote' => true,
:previous_label => previous_label, :next_label => next_label :previous_label => previous_label, :next_label => next_label
end end
@ -36,23 +36,13 @@ module ApplicationHelper
def items_per_page(options = {}) def items_per_page(options = {})
per_page_options = options[:per_page_options] || [20, 50, 100] per_page_options = options[:per_page_options] || [20, 50, 100]
current = options[:current] || @per_page current = options[:current] || @per_page
action = options[:action] || controller.action_name params = params || {}
update = options[:update] || nil
links = [] links = per_page_options.map do |per_page|
per_page_options.each do |per_page| params.merge!({:per_page => per_page})
unless per_page == current per_page == current ? per_page : link_to(per_page, params, :remote => true)
links << link_to_remote(
per_page,
{ :url => { :action => action, :params => {:per_page => per_page}},
:before => "Element.show('loader')",
:success => "Element.hide('loader')",
:method => :get, :update => update } )
else
links << per_page
end
end end
return "Pro Seite: " + links.join(" ") "Pro Seite: #{links.join(" ")}".html_safe
end end
def sort_td_class_helper(param) def sort_td_class_helper(param)
@ -63,7 +53,6 @@ module ApplicationHelper
def sort_link_helper(text, key, options = {}) def sort_link_helper(text, key, options = {})
per_page = options[:per_page] || 10 per_page = options[:per_page] || 10
action = options[:action] || "list"
remote = options[:remote].nil? ? true : options[:remote] remote = options[:remote].nil? ? true : options[:remote]
key += "_reverse" if params[:sort] == key key += "_reverse" if params[:sort] == key
url = url_for(:sort => key, :page => nil, :per_page => per_page) url = url_for(:sort => key, :page => nil, :per_page => per_page)

View file

@ -2,10 +2,9 @@
%table{:style => "width:100%"} %table{:style => "width:100%"}
%tr %tr
%td %td
= pagination_links_remote @ordergroups, { :update => "ordergroups" } = pagination_links_remote @ordergroups
%td{:style => "text-align:right"} %td{:style => "text-align:right"}
- if @ordergroups.size > 20 = items_per_page
= items_per_page :update => "ordergroups"
%table.list %table.list
%thead %thead
%tr %tr