Module: SortOut::Helpers

Defined in:
lib/sort_out/helpers.rb

Instance Method Summary collapse

Instance Method Details

#sortable(column, title = nil, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sort_out/helpers.rb', line 4

def sortable(column, title = nil, options = {})
  options.reverse_merge! default: false, direction: true, params: {}
  title ||= column.titleize
  direction = nil
  if column.to_s == SortOut.sort || (options[:default] and SortOut.sort.blank?)
    if SortOut.direction.blank?
      if options[:default].to_s == 'desc' and SortOut.sort.blank?
        title << '' if options[:direction]
      else
        direction = "desc"
        title << '' if options[:direction]
      end
    else
      title << '' if options[:direction]
    end
  end
  #▴ ▾ ▼ ▲
  link_to title, params.merge({ sort: column, direction: direction }.merge(options[:params]))
end

#sortable_current(columns, default, options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sort_out/helpers.rb', line 31

def sortable_current(columns, default, options)
  options.reverse_merge! model_name: controller_name.singularize

  column = if SortOut.sort.present? and columns.include? SortOut.sort.to_sym
    SortOut.sort.to_sym
  else
    default.first
  end

  title = tl("#{options[:model_name]}.#{column.to_s}")

  if SortOut.direction.blank?
    if default[1].to_s == 'desc' and SortOut.sort.blank?
      title << ''
    else
      title << ''
    end
  else
    title << ''
  end
end

#sortable_fieldsObject



24
25
26
27
28
29
# File 'lib/sort_out/helpers.rb', line 24

def sortable_fields
  html = "".html_safe
  html << hidden_field_tag(:sort, SortOut.sort) if SortOut.sort.present?
  html << hidden_field_tag(:direction, SortOut.direction) if SortOut.direction.present?
  html
end