Module: Opale::SortableHelper

Defined in:
lib/helpers/sortables_helper.rb

Instance Method Summary collapse

Instance Method Details

#search_form_fields(table_name = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/helpers/sortables_helper.rb', line 3

def search_form_fields(table_name = nil, &block)
  searching_field  = hidden_field_tag :searching, true
  table_name_field = hidden_field_tag :table_name, table_name unless table_name.nil?
  sort_field       = hidden_field_tag :sort, params[:sort] || :updated_at
  direction_field  = hidden_field_tag :direction, params[:direction] || :desc

  searching_field.concat(sort_field)
  searching_field.concat(direction_field)
  searching_field.concat(table_name_field)

  searching_field
end

#th(options, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/helpers/sortables_helper.rb', line 16

def th(options, &block)
  css_class = options[:table_name] == sort_column ? "current #{sort_direction}" : nil
  # direction = options[:table_name] == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'

   :th, class: options[:class], style: options[:style] do
    link_to '#', { class: css_class, onclick: "sortable(event, '#{options[:table_name]}')" } do
      block.call unless block.nil?
    end
  end
end