Module: RailsBootstrapWidgets::FiltersHelper
- Defined in:
- app/helpers/rails-bootstrap-widgets/filters_helper.rb
Instance Method Summary collapse
-
#filters_widget(items, options = {}) ⇒ Object
To create html header for filtering, ordering and paging a list of items call
filters_widget(items, options = {})
with parameters: filters_widget ( @items, # list of items (required) filters: { published: :Published, unpublished: :Unpublished}, # list of filters to select from in a format { key: :name } filter: ‘published’, # key of the current filter to apply to items orders: { tree: :Tree, feed: :Feed }, # list of types of items ordering to select from order: ‘tree’ # key of the current order type ). -
#pagination_widget(items, options = {}) ⇒ Object
To add pager to a view call
pagination_widget(items, options = {})
with parameters:.
Instance Method Details
#filters_widget(items, options = {}) ⇒ Object
To create html header for filtering, ordering and paging a list of items call filters_widget(items, options = {})
with parameters:
filters_widget (
@items, # list of items (required)
filters: { published: :Published, unpublished: :Unpublished}, # list of filters to select from in a format { key: :name }
filter: 'published', # key of the current filter to apply to items
orders: { tree: :Tree, feed: :Feed }, # list of types of items ordering to select from
order: 'tree' # key of the current order type
)
This will provide html, that contains:
-
Input field to select filter from those are available
-
Input field to select order from those are available
-
Hidden button to reset filter values (it will authomatically displayed via js)
-
Button to reload the page with new filter values (it will authomatically removed via js)
-
Items pager
<b>Use only one such a call on the page</p>
For example, the call of the code above will provide html:
<form accept-charset="UTF-8" action="/" class="span8" id="filters" method="get">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
</div>
<div class="input-prepend">
<span class="add-on">
<i class="icon-filter"></i>
</span>
<select id="filter" name="filter">
<option value="published" selected="selected">Published</option>
<option value="unpublished">Unpublished</option>
</select>
</div>
<div class="input-prepend">
<span class="add-on">
<i class="icon-order"></i>
</span>
<select id="order" name="order">
<option value="tree" selected="selected">Tree</option>
<option value="feed">Feed</option>
</select>
</div>
<a href="#" class="btn add-on hide" id="reset">
<i class="icon-reset"></i>
</a>
<div class="input-prepend" id="reload">
<span class="add-on">
<i class="icon-reload"></i>
</span>
<input class="btn" name="commit" type="submit" value="Reload" />
</div>
</form>
<aside class="span4">
<!-- Standard result of 'will_paginate(items, inner_window: 0, outer_window: 0)' call -->
</aside>
This code provides basic html functionality for browsers with js suppord disabled. For those with js support is enabled, the file app/assets/javascripts/rails-bootstrap-widgets/filters.js.coffee
turns on extended ajax behavior.
81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/rails-bootstrap-widgets/filters_helper.rb', line 81 def (items, = {}) if ( = _prepare()).present? form_tag(url_for("/"), method: :get, id: :filters, class: :span8) do (_selector(:filter, [:filters], [:filter]) << _selector(:order, [:orders], [:order]) << _reset << _reload).html_safe end else "" end << (items, class: :span4) end |
#pagination_widget(items, options = {}) ⇒ Object
To add pager to a view call pagination_widget(items, options = {})
with parameters:
items, class: 'class name'
This will simply wrap standard pagination from the ‘will-paginate’ gem into <aside class='class name'>
tag
<aside class='class name'>
<!-- Standard result of 'will_paginate(items, inner_window: 0, outer_window: 0)' call -->
</aside>
14 15 16 17 18 19 20 |
# File 'app/helpers/rails-bootstrap-widgets/filters_helper.rb', line 14 def (items, = {}) if items.present? content_tag(:aside, ([:class].to_s.present? ? { class: [:class] } : {})) do will_paginate(items, inner_window: 0, outer_window: 0).html_safe end end end |