Add "Save Defaults" button so user can save personal defaults for any new grid.
This commit is contained in:
parent
d57f5169b0
commit
2b1bdec2f8
3 changed files with 88 additions and 24 deletions
32
tailbone/static/js/jquery.ui.tailbone.js
vendored
32
tailbone/static/js/jquery.ui.tailbone.js
vendored
|
@ -17,10 +17,12 @@
|
|||
|
||||
// Snag some element references.
|
||||
this.filters = this.element.find('.newfilters');
|
||||
this.filters_form = this.filters.find('form');
|
||||
this.add_filter = this.filters.find('#add-filter');
|
||||
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.save_defaults = this.filters.find('#save-defaults');
|
||||
this.grid = this.element.find('.newgrid');
|
||||
|
||||
// Enhance filters etc.
|
||||
|
@ -28,6 +30,7 @@
|
|||
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'});
|
||||
this.save_defaults.button('option', 'icons', {primary: 'ui-icon-disk'});
|
||||
if (! this.filters.find('.active:checked').length) {
|
||||
this.apply_filters.button('disable');
|
||||
}
|
||||
|
@ -56,11 +59,12 @@
|
|||
});
|
||||
|
||||
// Intercept filters form submittal, and submit via AJAX instead.
|
||||
this.filters.find('form').on('submit', function() {
|
||||
var form = $(this);
|
||||
|
||||
this.filters_form.on('submit', function() {
|
||||
var settings = {filter: true, partial: true};
|
||||
form.find('.filter').each(function() {
|
||||
if (that.filters_form.find('input[name="save-current-filters-as-defaults"]').val() == 'true') {
|
||||
settings['save-current-filters-as-defaults'] = true;
|
||||
}
|
||||
that.filters.find('.filter').each(function() {
|
||||
|
||||
// currently active filters will be included in form data
|
||||
if ($(this).gridfilter('active')) {
|
||||
|
@ -74,7 +78,7 @@
|
|||
});
|
||||
|
||||
// if no filters are visible, disable submit button
|
||||
if (! form.find('.filter:visible').length) {
|
||||
if (! that.filters.find('.filter:visible').length) {
|
||||
that.apply_filters.button('disable');
|
||||
}
|
||||
|
||||
|
@ -86,11 +90,19 @@
|
|||
// 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.filters_form.off('submit');
|
||||
that.filters_form.find('input[name="reset-to-default-filters"]').val('true');
|
||||
that.element.mask("Refreshing data...");
|
||||
form.submit();
|
||||
that.filters_form.submit();
|
||||
});
|
||||
|
||||
// When user clicks Save Defaults button, refresh the grid as with
|
||||
// Apply Filters, but add an instruction for the server to save
|
||||
// current settings as defaults for the user.
|
||||
this.save_defaults.click(function() {
|
||||
that.filters_form.find('input[name="save-current-filters-as-defaults"]').val('true');
|
||||
that.filters_form.submit();
|
||||
that.filters_form.find('input[name="save-current-filters-as-defaults"]').val('false');
|
||||
});
|
||||
|
||||
// When user clicks Clear Filters button, deactivate all filters
|
||||
|
@ -101,7 +113,7 @@
|
|||
$(this).gridfilter('active', false);
|
||||
}
|
||||
});
|
||||
that.filters.find('form').submit();
|
||||
that.filters_form.submit();
|
||||
});
|
||||
|
||||
// Refresh data when user clicks a sortable column header.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue