Class: Godmin::FormBuilders::FilterFormBuilder

Inherits:
BootstrapForm::FormBuilder
  • Object
show all
Defined in:
lib/godmin/helpers/filters.rb

Instance Method Summary collapse

Instance Method Details

#apply_filters_buttonObject



60
61
62
# File 'lib/godmin/helpers/filters.rb', line 60

def apply_filters_button
  submit @template.translate_scoped("filters.buttons.apply")
end

#clear_filters_buttonObject



64
65
66
67
68
69
70
71
72
# File 'lib/godmin/helpers/filters.rb', line 64

def clear_filters_button
  @template.link_to(
    @template.translate_scoped("filters.buttons.clear"),
    @template.url_for(
      @template.params.slice(:scope, :order)
    ),
    class: "btn btn-default"
  )
end

#filter_field(name, options, html_options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/godmin/helpers/filters.rb', line 14

def filter_field(name, options, html_options = {})
  case options[:as]
  when :string
    string_filter_field(name, options, html_options)
  when :select
    select_filter_field(name, options, html_options)
  when :multiselect
    multiselect_filter_field(name, options, html_options)
  end
end

#multiselect_filter_field(name, options, html_options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/godmin/helpers/filters.rb', line 48

def multiselect_filter_field(name, options, html_options = {})
  filter_select(
    name, options, {
      name: "filter[#{name}][]",
      multiple: true,
      data: {
        placeholder: @template.translate_scoped("filters.select.placeholder.many")
      }
    }.deep_merge(html_options)
  )
end

#select_filter_field(name, options, html_options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/godmin/helpers/filters.rb', line 37

def select_filter_field(name, options, html_options = {})
  filter_select(
    name, options, {
      name: "filter[#{name}]",
      data: {
        placeholder: @template.translate_scoped("filters.select.placeholder.one")
      }
    }.deep_merge(html_options)
  )
end

#string_filter_field(name, _options, html_options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/godmin/helpers/filters.rb', line 25

def string_filter_field(name, _options, html_options = {})
  text_field(
    name, {
      name: "filter[#{name}]",
      label: @template.translate_scoped("filters.labels.#{name}", default: name.to_s.titleize),
      value: default_filter_value(name),
      placeholder: @template.translate_scoped("filters.labels.#{name}", default: name.to_s.titleize),
      wrapper_class: "filter"
    }.deep_merge(html_options)
  )
end