Class: MightyGrid::FilterRenderer
- Inherits:
-
Object
- Object
- MightyGrid::FilterRenderer
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- lib/mighty_grid/filter_renderer.rb
Instance Method Summary collapse
-
#check_box(name, value = '1', checked = false, options = {}) ⇒ Object
Get
checkbox
. -
#initialize(grid, view) ⇒ FilterRenderer
constructor
A new instance of FilterRenderer.
-
#label(name, content_or_options = nil, options = nil, &block) ⇒ Object
Get
label
HTML tag. -
#reset(content = nil, options = {}, &block) ⇒ Object
Get button for Reset filter changes.
-
#select(name, options = {}) ⇒ Object
Get
select
HTML tag. -
#submit(content = nil, options = {}, &block) ⇒ Object
Get button for Apply filter changes.
-
#text_field(name, options = {}) ⇒ Object
Get
input
HTML tag.
Constructor Details
#initialize(grid, view) ⇒ FilterRenderer
Returns a new instance of FilterRenderer.
6 7 8 |
# File 'lib/mighty_grid/filter_renderer.rb', line 6 def initialize(grid, view) @grid = grid end |
Instance Method Details
#check_box(name, value = '1', checked = false, options = {}) ⇒ Object
Get checkbox
40 41 42 43 44 |
# File 'lib/mighty_grid/filter_renderer.rb', line 40 def check_box(name, value = '1', checked = false, = {}) checked = true if get_filter_param(name) check_box_tag(@grid.get_filter_name(name), value, checked, ) end |
#label(name, content_or_options = nil, options = nil, &block) ⇒ Object
Get label
HTML tag
11 12 13 14 15 16 |
# File 'lib/mighty_grid/filter_renderer.rb', line 11 def label(name, = nil, = nil, &block) = if .is_a?(Hash) human_name = (.is_a?(Hash) || .nil?) ? @grid.klass.human_attribute_name(name) : label_tag(get_filter_id(name), human_name, , &block) end |
#reset(content = nil, options = {}, &block) ⇒ Object
Get button for Reset filter changes
59 60 61 62 63 64 65 66 67 |
# File 'lib/mighty_grid/filter_renderer.rb', line 59 def reset(content = nil, = {}, &block) content = I18n.t('mighty_grid.filters.reset', default: 'Reset changes') if content.blank? .merge!(type: :reset) if block_given? content_tag(:button, nil, , &block) else content_tag(:button, content, ) end end |
#select(name, options = {}) ⇒ Object
Get select
HTML tag
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mighty_grid/filter_renderer.rb', line 24 def select(name, = {}) = @grid.filters[name].collection selected = nil if .key?(:selected) selected = .delete(:selected) @grid.add_filter_param(name, selected) end selected = get_filter_param(name) if get_filter_param(name) opts = (, selected) select_tag(@grid.get_filter_name(name), opts, ) end |
#submit(content = nil, options = {}, &block) ⇒ Object
Get button for Apply filter changes
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mighty_grid/filter_renderer.rb', line 47 def submit(content = nil, = {}, &block) content = I18n.t('mighty_grid.filters.submit', default: 'Apply changes') if content.blank? .merge!(type: :submit) if block_given? content_tag(:button, nil, , &block) else content_tag(:button, content, ) end end |
#text_field(name, options = {}) ⇒ Object
Get input
HTML tag
19 20 21 |
# File 'lib/mighty_grid/filter_renderer.rb', line 19 def text_field(name, = {}) text_field_tag(@grid.get_filter_name(name), get_filter_param(name), ) end |