Module: GoodSort::ViewHelpers
- Defined in:
- lib/good_sort/view_helpers.rb
Constant Summary collapse
- @@field_tag =
'__FIELD__'
Instance Method Summary collapse
- #sort_field_tag ⇒ Object
- #sort_header(f, text, options) ⇒ Object
- #sort_header_title(field, options) ⇒ Object
- #sort_headers_for(m, h, options = {}) ⇒ Object
- #sort_link(f, text, options) ⇒ Object
Instance Method Details
#sort_field_tag ⇒ Object
4 |
# File 'lib/good_sort/view_helpers.rb', line 4 def sort_field_tag; @@field_tag; end |
#sort_header(f, text, options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/good_sort/view_helpers.rb', line 50 def sort_header(f, text, ) params[:sort] ||= {} = [:header].dup if params[:sort][:field] == f.to_s [:class] ||= '' ([:class] += params[:sort][:down].blank? ? ' up' : ' down' ).strip! end content_tag( [:tag], sort_link(f, text, ), ) end |
#sort_header_title(field, options) ⇒ Object
70 71 72 |
# File 'lib/good_sort/view_helpers.rb', line 70 def sort_header_title( field, ) [:html][:title].gsub(sort_field_tag, field) end |
#sort_headers_for(m, h, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/good_sort/view_helpers.rb', line 5 def sort_headers_for( m, h, = {} ) id = m.to_s.singularize m = m.to_s.classify c = m.constantize .symbolize_keys! [:spinner] ||= :spinner [:tag] ||= :th [:header] ||= {} [:header].symbolize_keys! [:remote] ||= {} [:remote].symbolize_keys! [:remote][:update] ||= m.tableize [:remote][:before] = "$('#{[:spinner]}').show()" unless [:remote].has_key? :before [:remote][:complete] = "$('#{[:spinner]}').hide()" unless [:remote].has_key? :complete [:remote][:method] ||= :get # save these for pagination calls later in the request @remote_options = [:remote].dup [:html] ||= {} [:html].symbolize_keys! [:html][:title] ||= "Sort by #{sort_field_tag}" sf = c.sort_fields logger.warn "GoodSort: #{m} has not had any sort_on fields set" if sf.nil? h.each do |f| [:header][:id] = "#{id}_header_#{f}" text = yield(f) if block_given? text ||= f.to_s.titleize unless sf[f.to_sym] concat content_tag([:tag], text, [:header]) next end concat sort_header( f, text, ) end end |
#sort_link(f, text, options) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/good_sort/view_helpers.rb', line 61 def sort_link(f, text, ) s = { :field => f, :down => params[:sort][:field] == f.to_s && params[:sort][:down].blank? ? true : nil } ps = params.merge( :sort => s, :page => nil ) [:remote][:url] = [:html][:href] = url_for( :params => ps ) title = sort_header_title( text, ) link_to_remote(text, [:remote], [:html].merge( :title => title)) end |