Module: TableSortable::ViewHelpers

Defined in:
lib/table_sortable/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#table_sortable_columns(record, html_options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/table_sortable/view_helpers.rb', line 57

def table_sortable_columns(record, html_options = {})
  controller.columns.map.with_index do |col, index|
    value = col.value(record)
    content = col.content(record)
    td_options = {}
    td_options['data-text'] = value if value != content
    td_options.merge!(html_options)
    view_path = "#{col.template_path || controller_path}/table_sortable/"
    view_filename = "#{col.template}_column.html"
    if Dir.glob(File.join(Rails.root, 'app', 'views', view_path, "_#{view_filename}.*")).any?
      render partial: File.join(view_path, view_filename),
             locals: {content: content,
                      value: value,
                      source: record,
                      column: col,
                      index: index}
    else
       :td, td_options do
        value
      end
    end
  end.join.html_safe
end

#table_sortable_headers(html_options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/table_sortable/view_helpers.rb', line 25

def table_sortable_headers(html_options = {})
  controller.columns.map.with_index do |col, index|
    label = col.label
    placeholder = col.placeholder
    filter = col.filter

    th_options = {}
    th_options['data-placeholder'] = placeholder if placeholder
    # th_options['data-priority'] = col.sort_priority if col.sort_priority
    th_options['data-filter'] = 'false' if filter.disabled?
    th_options['data-sorter'] = 'false' if col.sorter.disabled?
    unless filter.collection.blank?
      th_options['filter-select'] = true
      th_options['data-filter-options'] = filter.collection
    end
    th_options['data-value'] = filter.default_value if filter.default_value
    th_options.merge!(html_options)
    view_path = "#{col.template_path || controller_path}/table_sortable/"
    view_filename = "#{col.template}_header.html"
    if Dir.glob(File.join(Rails.root, 'app', 'views', view_path, "_#{view_filename}.*")).any?
      render partial: File.join(view_path, view_filename),
             locals: {label: label,
                      column: col,
                      index: index}
    else
       :th, th_options do
        label
      end
    end
  end.join.html_safe
end

#table_sortable_pager(*args) ⇒ Object



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

def table_sortable_pager(*args)
  options = args.extract_options!

  pagination_class =    options[:wrapper_class]       || 'pagination'
  page_display_class =  options[:page_display_class]  || 'pagedisplay'
  item_wrapper_class =  options[:item_wrapper_class]
  item_class =          options[:item_class]
  first_item =          options[:first]               || '<<'
  prev_item =           options[:prev]                || '<'
  next_item =           options[:next]                || '>'
  last_item =           options[:last]                || '>>'

   :ul, class:pagination_class do
    (:li, link_to(first_item,  '#', class: ([item_class] + ['first']).flatten.compact.join(' ')),            class: item_wrapper_class)+
    (:li, link_to(prev_item,   '#', class: ([item_class] + ['prev'] ).flatten.compact.join(' ')),            class: item_wrapper_class)+
    (:li, (:span,   nil, class: ([item_class] + [page_display_class]).flatten.compact.join(' ')), class: item_wrapper_class)+
    (:li, link_to(next_item,   '#', class: ([item_class] + ['next'] ).flatten.compact.join(' ')),            class: item_wrapper_class)+
    (:li, link_to(last_item,   '#', class: ([item_class] + ['last'] ).flatten.compact.join(' ')),            class: item_wrapper_class)
  end.html_safe
end