Add 'Default Filters' and 'Clear Filters' buttons to new grid filters form.
This commit is contained in:
parent
d2b065a8fc
commit
d57f5169b0
|
@ -155,9 +155,14 @@ class Grid(object):
|
||||||
settings['filter.{0}.verb'.format(filtr.key)] = filtr.default_verb
|
settings['filter.{0}.verb'.format(filtr.key)] = filtr.default_verb
|
||||||
settings['filter.{0}.value'.format(filtr.key)] = filtr.default_value
|
settings['filter.{0}.value'.format(filtr.key)] = filtr.default_value
|
||||||
|
|
||||||
|
# If request contains instruction to reset to default filters, then we
|
||||||
|
# can skip the rest of the request/session checks.
|
||||||
|
if self.request.GET.get('reset-to-default-filters') == 'true':
|
||||||
|
pass
|
||||||
|
|
||||||
# If request has filter settings, grab those, then grab sort/pager
|
# If request has filter settings, grab those, then grab sort/pager
|
||||||
# settings from request or session.
|
# settings from request or session.
|
||||||
if self.request_has_settings('filter'):
|
elif self.request_has_settings('filter'):
|
||||||
self.update_filter_settings(settings, 'request')
|
self.update_filter_settings(settings, 'request')
|
||||||
if self.request_has_settings('sort'):
|
if self.request_has_settings('sort'):
|
||||||
self.update_sort_settings(settings, 'request')
|
self.update_sort_settings(settings, 'request')
|
||||||
|
|
25
tailbone/static/js/jquery.ui.tailbone.js
vendored
25
tailbone/static/js/jquery.ui.tailbone.js
vendored
|
@ -19,11 +19,15 @@
|
||||||
this.filters = this.element.find('.newfilters');
|
this.filters = this.element.find('.newfilters');
|
||||||
this.add_filter = this.filters.find('#add-filter');
|
this.add_filter = this.filters.find('#add-filter');
|
||||||
this.apply_filters = this.filters.find('#apply-filters');
|
this.apply_filters = this.filters.find('#apply-filters');
|
||||||
|
this.default_filters = this.filters.find('#default-filters');
|
||||||
|
this.clear_filters = this.filters.find('#clear-filters');
|
||||||
this.grid = this.element.find('.newgrid');
|
this.grid = this.element.find('.newgrid');
|
||||||
|
|
||||||
// Enhance filters etc.
|
// Enhance filters etc.
|
||||||
this.filters.find('.filter').gridfilter();
|
this.filters.find('.filter').gridfilter();
|
||||||
this.apply_filters.button('option', 'icons', {primary: 'ui-icon-search'});
|
this.apply_filters.button('option', 'icons', {primary: 'ui-icon-search'});
|
||||||
|
this.default_filters.button('option', 'icons', {primary: 'ui-icon-home'});
|
||||||
|
this.clear_filters.button('option', 'icons', {primary: 'ui-icon-trash'});
|
||||||
if (! this.filters.find('.active:checked').length) {
|
if (! this.filters.find('.active:checked').length) {
|
||||||
this.apply_filters.button('disable');
|
this.apply_filters.button('disable');
|
||||||
}
|
}
|
||||||
|
@ -79,6 +83,27 @@
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// When user clicks Default Filters button, refresh page with
|
||||||
|
// instructions for the server to reset filters to default settings.
|
||||||
|
this.default_filters.click(function() {
|
||||||
|
var form = that.filters.find('form');
|
||||||
|
form.off('submit');
|
||||||
|
form.append('<input type="hidden" name="reset-to-default-filters" value="true" />');
|
||||||
|
that.element.mask("Refreshing data...");
|
||||||
|
form.submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
// When user clicks Clear Filters button, deactivate all filters
|
||||||
|
// and refresh the grid.
|
||||||
|
this.clear_filters.click(function() {
|
||||||
|
that.filters.find('.filter').each(function() {
|
||||||
|
if ($(this).gridfilter('active')) {
|
||||||
|
$(this).gridfilter('active', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
that.filters.find('form').submit();
|
||||||
|
});
|
||||||
|
|
||||||
// Refresh data when user clicks a sortable column header.
|
// Refresh data when user clicks a sortable column header.
|
||||||
this.element.on('click', 'thead th.sortable a', function() {
|
this.element.on('click', 'thead th.sortable a', function() {
|
||||||
var th = $(this).parent();
|
var th = $(this).parent();
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<option value="${filtr.key}"${' disabled="disabled"' if filtr.active else ''|n}>${filtr.label}</option>
|
<option value="${filtr.key}"${' disabled="disabled"' if filtr.active else ''|n}>${filtr.label}</option>
|
||||||
% endfor
|
% endfor
|
||||||
</select>
|
</select>
|
||||||
|
${form.tag('button', type='button', id='default-filters', c="Default Filters")}
|
||||||
|
${form.tag('button', type='button', id='clear-filters', c="Clear Filters")}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${form.end()}
|
${form.end()}
|
||||||
|
|
|
@ -71,6 +71,12 @@ class MasterView(View):
|
||||||
returns the full page.
|
returns the full page.
|
||||||
"""
|
"""
|
||||||
grid = self.make_grid()
|
grid = self.make_grid()
|
||||||
|
|
||||||
|
# If user just refreshed the page with a reset instruction, issue a
|
||||||
|
# redirect in order to clear out the query string.
|
||||||
|
if self.request.GET.get('reset-to-default-filters') == 'true':
|
||||||
|
return self.redirect(self.request.current_route_url(_query=None))
|
||||||
|
|
||||||
if self.request.params.get('partial'):
|
if self.request.params.get('partial'):
|
||||||
self.request.response.content_type = b'text/html'
|
self.request.response.content_type = b'text/html'
|
||||||
self.request.response.text = grid.render_grid()
|
self.request.response.text = grid.render_grid()
|
||||||
|
|
Loading…
Reference in a new issue