Module: SortableTable::App::Helpers::ApplicationHelper::InstanceMethods

Defined in:
lib/sortable_table/app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details



52
53
54
55
56
57
58
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 52

def link_sort_order(opts)
  if re_sort? opts
    reverse_order params[:order]
  else
    reverse_order sortable_table_direction
  end
end

#re_sort?(opts) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 40

def re_sort?(opts)
  params[:sort] == opts[:sort]
end

#reverse_order(order) ⇒ Object



44
45
46
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 44

def reverse_order(order)
  order == 'ascending' ? 'descending' : 'ascending'
end

#sortable_table_header(opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 13

def sortable_table_header(opts = {})
  raise ArgumentError if opts[:name].nil? || opts[:sort].nil?
  anchor = opts[:anchor].blank? ? "" : "##{opts[:anchor]}"
   :th, 
    link_to(opts[:name], 
      sortable_url(opts) + anchor, 
      :title => opts[:title]),
    :class => sortable_table_header_classes(opts)
end

#sortable_table_header_class(opts) ⇒ Object



30
31
32
33
34
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 30

def sortable_table_header_class(opts)
  if re_sort?(opts) || sorting_default?(opts)
    sortable_table_direction
  end
end

#sortable_table_header_classes(opts) ⇒ Object



23
24
25
26
27
28
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 23

def sortable_table_header_classes(opts)
  class_names = []
  class_names << sortable_table_header_class(opts) 
  class_names << opts[:class]
  class_names.compact.blank? ? nil : class_names.compact.join(" ")
end

#sortable_url(opts) ⇒ Object



48
49
50
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 48

def sortable_url(opts)
  url_for(params.merge(:sort => opts[:sort], :order => link_sort_order(opts), :page => 1))
end

#sorting_default?(opts) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 36

def sorting_default?(opts)
  params[:sort].nil? && opts[:sort] == default_sort_column
end