Modified sort_link helper method to allo non ajax links.

This commit is contained in:
Benjamin Meichsner 2009-04-03 17:16:39 +02:00
parent 45c7e29ebb
commit 8fb4334610
3 changed files with 17 additions and 9 deletions

View file

@ -58,10 +58,13 @@ module ApplicationHelper
return result return result
end end
def sort_link_helper(text, param, per_page = (@per_page || 10), action = "list" ) def sort_link_helper(text, key, options = {})
key = param per_page = options[:per_page] || 10
key += "_reverse" if params[:sort] == param action = options[:action] || "list"
options = { remote = options[:remote].nil? ? true : options[:remote]
key += "_reverse" if params[:sort] == key
link_options = {
:url => url_for(:params => params.merge({:sort => key, :page => nil, :per_page => per_page})), :url => url_for(:params => params.merge({:sort => key, :page => nil, :per_page => per_page})),
:before => "Element.show('loader')", :before => "Element.show('loader')",
:success => "Element.hide('loader')", :success => "Element.hide('loader')",
@ -71,7 +74,12 @@ module ApplicationHelper
:title => _("Nach #{text} sortieren"), :title => _("Nach #{text} sortieren"),
:href => url_for(:action => action, :params => params.merge({:sort => key, :page => nil, :per_page => per_page})) :href => url_for(:action => action, :params => params.merge({:sort => key, :page => nil, :per_page => per_page}))
} }
link_to_remote(text, options, html_options)
if remote
link_to_remote(text, link_options, html_options)
else
link_to(text, link_options[:url], html_options)
end
end end
# Generates a link to the top of the website # Generates a link to the top of the website

View file

@ -7,9 +7,9 @@
%thead %thead
%tr %tr
%th[sort_td_class_helper "name"]{:colspan => "1"} %th[sort_td_class_helper "name"]{:colspan => "1"}
= sort_link_helper "Artikel", "name", 1000, "new" = sort_link_helper "Artikel", "name", :action => "new", :remote => false
%th[sort_td_class_helper "order_number"] %th[sort_td_class_helper "order_number"]
= sort_link_helper "Nr.", "order_number", 1000, "new" = sort_link_helper "Nr.", "order_number", :action => "new", :remote => false
%th Menge %th Menge
%th GebGr * Einheit %th GebGr * Einheit
%th Netto %th Netto

View file

@ -12,9 +12,9 @@
%table.list %table.list
%thead %thead
%tr %tr
%th= sort_link_helper "Name", "name", @per_page %th= sort_link_helper "Name", "name", :per_page => @per_page
%th Kontakt %th Kontakt
%th= sort_link_helper "Kontostand", "account_balance", @per_page %th= sort_link_helper "Kontostand", "account_balance", :per_page => @per_page
%th %th
%tbody %tbody
- for group in @groups - for group in @groups