| Module | Opensteam::Helper::ConfigurableTableController::InstanceMethods |
| In: |
lib/opensteam/helper/configurable_table.rb
|
before_filter: if params[:sort] is set, it gets the current sort-column from the configured_table class variable
# File lib/opensteam/helper/configurable_table.rb, line 29
29: def set_sort_column
30: if params[:sort]
31: model = params[:model].demodulize.classify.constantize rescue nil
32: @sort_column = model.configured_table.get_column( params[:sort] ) || model.configured_table.default_sort
33: end
34: end
# File lib/opensteam/helper/configurable_table.rb, line 36
36: def sort
37: if params[:sort]
38: self.class.to_s =~ /^(.+)Controller/
39: model = $1.demodulize.classify.constantize rescue nil
40: @result = sort_model( model, @sort_column )
41: end
42: render :action => :sort
43:
44: end
sort the current model by column finds all entries for current model (including all associations) sort entries either by "ORDER" SQL or by a ruby sort-block (depending on the configuration or wether the column is an association)
# File lib/opensteam/helper/configurable_table.rb, line 51
51: def sort_model( model, column, conditions = nil, includes = nil )
52: finder_args = {}
53: finder_args[:conditions] = conditions if conditions
54: finder_args[:include] = includes if includes
55:
56: if column.order_ruby?
57: result = model.find( :all, finder_args )
58: result.sort!(&column.order)
59: else
60: finder_args[:order] = column.order
61: result = model.find(:all, finder_args )
62: end
63: toggle_sorted( model.to_s.demodulize )
64: result.reverse! if sorted?( model.to_s.demodulize )
65: result
66: end
if model is currently sorted ascending
# File lib/opensteam/helper/configurable_table.rb, line 69
69: def sorted?(model)
70: session["#{model}_sorted".to_sym] ? true : false ;
71: end