Module: SearchFu::ViewHelper

Defined in:
lib/search_fu/view_helper.rb

Instance Method Summary collapse

Instance Method Details



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

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", name: "search_fu_commit", class: add_apply_button_class, disable_with: "Searching..."), colspan: 3)
  end
end

#filter_headerObject



38
39
40
41
42
43
# File 'lib/search_fu/view_helper.rb', line 38

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

#filter_table(model_klass, button_class) ⇒ Object



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

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

#render_fields(model_klass, remove_button_class) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/search_fu/view_helper.rb', line 25

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_view_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



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/search_fu/view_helper.rb', line 52

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_view_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