Module: FilterFu::ViewHelper

Defined in:
lib/search_fu/view_helper.rb

Instance Method Summary collapse

Instance Method Details



51
52
53
54
55
56
# File 'lib/search_fu/view_helper.rb', line 51

def filter_footer(add_apply_button_class)
  (:tr) do
    (:td, link_to("Add", "#", id: "search_fu_add", class: add_apply_button_class) +
    submit_tag("Apply", class: add_apply_button_class, disable_with: "Searching..."), colspan: 3)
  end
end

#filter_headerObject



44
45
46
47
48
49
# File 'lib/search_fu/view_helper.rb', line 44

def filter_header
  (:tr) do
    (:td, "Filter") +
    (:td, "Value", colspan: 2)
  end
end

#filter_table(model_klass, button_class) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/search_fu/view_helper.rb', line 23

def filter_table(model_klass, button_class)
  (:table, id: 'search_fu_table') do
    (:thead, filter_header, id: "search_fu_thead") +
    (:tbody, render_fields(model_klass, button_class[:remove]), id: "search_fu_tbody") +
    (:tfoot, filter_footer(button_class[:add_apply]), id: "search_fu_tfoot")
  end
end


17
18
19
20
# File 'lib/search_fu/view_helper.rb', line 17

def link_to_more(text, element, options={})
  (:span, "", id: "search_fu_more_span") +
  link_to(text, '#', options.merge(id: "search_fu_more_link", element: element))
end

#render_fields(model_klass, remove_button_class) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/search_fu/view_helper.rb', line 31

def render_fields(model_klass, remove_button_class)
  html = ""
  (session["#{model_klass.name.underscore}_search_fu"] || params[:search_fu] || {}).each do |k,v|
    rand_id = (DateTime.now.to_i * rand * 100).to_i
    html << (:tr, id: "search_fu_row_new_#{rand_id}", class: "search_fu_rows") do
      (:td, select_tag("search_fu[_new_#{rand_id}][name]", options_for_select(model_klass.search_fu_names, v[:name]))) +
      (:td, text_field_tag("search_fu[_new_#{rand_id}][value]", v[:value])) +
      (:td, link_to("X", "#", class: "search_fu_remove #{remove_button_class}"))
    end
  end
  html.html_safe
end

#search_fields_blueprint(model_klass, remove_button_class) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/search_fu/view_helper.rb', line 58

def search_fields_blueprint(model_klass, remove_button_class)
  (:table, style: "display:none") do
    (:tbody, id: "hidden_search_fields") do
      (:tr, id: "search_fu_row_NEW_", class: "search_fu_rows") do
        (:td, select_tag("search_fu[_NEW_][name]", options_for_select(model_klass.search_fu_names))) +
        (:td, text_field_tag("search_fu[_NEW_][value]")) +
        (:td, link_to("X", "#", class: "search_fu_remove #{remove_button_class}"))
      end
    end
  end
end

#search_fu_form_for(model_klass, element = "#content", options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/search_fu/view_helper.rb', line 6

def search_fu_form_for(model_klass, element="#content", options={})
  button_class = options.delete(:button_class)
  button_class ||= {}
  button_class[:remove] ||= ""
  button_class[:add_apply] ||= ""
  search_fields_blueprint(model_klass, button_class[:remove]) +
  form_tag(polymorphic_path(model_klass), options.merge(method: :get, remote: true, id: 'search_fu_form', element: element)) do
    filter_table model_klass, button_class
  end
end