Class: AdminWidgets::FiltersWidget

Inherits:
BaseFormWidget show all
Defined in:
lib/admin_widgets/filters_widget.rb

Instance Attribute Summary

Attributes inherited from BaseFormWidget

#form

Instance Method Summary collapse

Methods inherited from BaseFormWidget

#around_form, #autofocus!, #autofocus_done?, #builder, #content

Methods inherited from BaseWidget

#capture, #content_block, #helper, #method_missing, #root

Methods included from Memoization

#memoize

Methods included from Delegation

#delegate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AdminWidgets::BaseWidget

Instance Method Details

#buttonsObject



48
49
50
51
52
53
54
55
56
# File 'lib/admin_widgets/filters_widget.rb', line 48

def buttons
  div :class => ['group', 'navform', 'wat-cf'] do
    rawtext helper.button_tag(:class => 'button', :name => 'filter', :value => as) {
      helper.image_tag('search-button.png') +
      helper.t('resources.actions.filter')
    }
    rawtext helper.link_to(helper.t('resources.actions.reset_filter'), cancel_url, :class => "text_button_padding link_button") if cancel_url
  end
end

#field(name, operator, options = {}) ⇒ Object

DSL methods



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/admin_widgets/filters_widget.rb', line 18

def field(name, operator, options = {})
  field_name = "#{name}_#{operator}"
  field_label = resource_class.human_attribute_name(name)
  field_value = params[as][field_name] rescue ''

  multiple = [:in, :all].include?(operator.to_sym)
  field_value = field_value.to_s.split(',') if multiple && field_value && !field_value.is_a?(Array)

  if options[:collection].present?
    value = nil
    selected = field_value
    include_blank = true
  else
    value = field_value
    selected = nil
    include_blank = nil
  end

  default_options = { :required => false, :label => field_label, :input_html => { :value => value, :multiple => multiple }, :selected => selected, :include_blank => include_blank, :hidden_field => false }
  rawtext form.input(field_name, default_options.merge(options))
end

#form_contentObject



10
11
12
13
14
# File 'lib/admin_widgets/filters_widget.rb', line 10

def form_content
  hidden_fields
  content_block
  buttons
end

#hidden_fieldsObject



40
41
42
43
44
45
46
# File 'lib/admin_widgets/filters_widget.rb', line 40

def hidden_fields
  div :class => ['hidden-fields'] do
    %w[scope sort_field sort_direction].each do |hidden_field|
      rawtext form.input(hidden_field, :input_html => { :name => hidden_field, :value => params[hidden_field] }, :as => :hidden)
    end
  end
end