Class: ActiveAdmin::Inputs::FilterNumericInput
- Inherits:
-
Formtastic::Inputs::NumberInput
- Object
- Formtastic::Inputs::NumberInput
- ActiveAdmin::Inputs::FilterNumericInput
show all
- Includes:
- FilterBase
- Defined in:
- lib/active_admin/inputs/filter_numeric_input.rb
Instance Method Summary
collapse
Methods included from FilterBase
#collection_from_options, #humanized_method_name, #input_wrapping, #reflection_for, #required?, #wrapper_html_options
Instance Method Details
#current_filter ⇒ Object
Returns the scope for which we are currently searching. If no search is available it returns the first scope
38
39
40
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 38
def current_filter
filters[1..-1].inject(filters.first){|a,b| @object.send(b[1].to_sym) ? b : a }[1]
end
|
#default_filters ⇒ Object
48
49
50
51
52
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 48
def default_filters
[ [I18n.t('active_admin.equal_to'), 'eq'],
[I18n.t('active_admin.greater_than'), 'gt'],
[I18n.t('active_admin.less_than'), 'lt'] ]
end
|
#filters ⇒ Object
42
43
44
45
46
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 42
def filters
(options[:filters] || default_filters).collect do |scope|
[scope[0], [method, scope[1]].join("_")]
end
end
|
16
17
18
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 16
def input_html
builder.text_field current_filter, input_html_options
end
|
20
21
22
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 20
def input_html_options
{ :size => 10, :id => "#{method}_numeric" }
end
|
#select_html ⇒ Object
24
25
26
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 24
def select_html
template.select_tag '', select_options, select_html_options
end
|
#select_html_options ⇒ Object
32
33
34
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 32
def select_html_options
{ :onchange => "document.getElementById('#{method}_numeric').name = 'q[' + this.value + ']';" }
end
|
#select_options ⇒ Object
28
29
30
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 28
def select_options
template.options_for_select(filters, current_filter)
end
|
#to_html ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/active_admin/inputs/filter_numeric_input.rb', line 6
def to_html
input_wrapping do
[ label_html,
select_html,
" ",
input_html
].join("\n").html_safe
end
end
|