Class: Symphonia::ModelFilters::SelectFilter
- Inherits:
-
StringFilter
- Object
- Base
- StringFilter
- Symphonia::ModelFilters::SelectFilter
- Defined in:
- lib/symphonia/model_filters/select_filter.rb
Instance Attribute Summary collapse
-
#available_values ⇒ Object
Returns the value of attribute available_values.
Attributes inherited from Base
#caption, #name, #operator, #options, #query, #type, #value
Instance Method Summary collapse
- #apply(scope) ⇒ Object
- #form_field(_c) ⇒ Object
-
#initialize(name, query, options = {}) ⇒ SelectFilter
constructor
A new instance of SelectFilter.
- #operator=(o) ⇒ Object
- #value=(q) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(name, query, options = {}) ⇒ SelectFilter
Returns a new instance of SelectFilter.
6 7 8 9 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 6 def initialize(name, query, = {}) super @operator = 'in' end |
Instance Attribute Details
#available_values ⇒ Object
Returns the value of attribute available_values.
4 5 6 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 4 def available_values @available_values end |
Instance Method Details
#apply(scope) ⇒ Object
34 35 36 37 38 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 34 def apply(scope) Rails.logger.debug("Apply filter #{name} '#{operator}' #{value}") t = scope.arel_table scope.where(t[name].send(operator, value)) end |
#form_field(_c) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 40 def form_field(_c) selected = Array(@query.active_filters[name]) _c.content_tag(:div, class: 'input-group') do _c.content_tag(:div, class: 'input-group-prepend') do _c.content_tag(:span, _c.check_box_tag("o[#{form_field_name}]", '!', operator == 'not_in', title: 'Not In'), class: "input-group-text") end + _c.select_tag("#{form_field_name}[]", _c.(available_values, selected), class: 'form-control', include_blank: true, multiple: selected.size > 1) + _c.content_tag(:div, _c.link_to(_c.fa_icon('plus-square-o'), 'javascript:void(0)', onclick: "toggleMultiSelect($(this).closest('.input-group').find('select'))", title: I18n.t(:title_toggle_multiselect), class: "input-group-text"), class: 'input-group-append') end end |
#operator=(o) ⇒ Object
28 29 30 31 32 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 28 def operator=(o) if o == '!' @operator = 'not_in' end end |
#value=(q) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/symphonia/model_filters/select_filter.rb', line 20 def value=(q) @value = if q.is_a?(Array) q else q.to_s.split("|") end end |