From 6866ac763c24d4c1a550879f97ef62c0826f3f42 Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <legac@cppm.in2p3.fr> Date: Mon, 10 Dec 2012 17:05:23 +0100 Subject: [PATCH] Replace the private attribute initialFilterConditions by the initialWhere attribute of the store. Use the method store.restoreWhere as well. --- static/plugin_dbui/src/gridfilter.js | 59 +++++++++------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/static/plugin_dbui/src/gridfilter.js b/static/plugin_dbui/src/gridfilter.js index e10b0860..29c1c1b0 100644 --- a/static/plugin_dbui/src/gridfilter.js +++ b/static/plugin_dbui/src/gridfilter.js @@ -14,16 +14,10 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { /** * Private - * Dictionary with additional where clause + * Dictionary with where clause related to the filter resquest */ filterConditions: {}, - - /** - * Private - * Initial where clause - */ - initialFilterConditions: [], - + /** * Private * Reference to the paging toolBar @@ -32,7 +26,7 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { /** * Private - * a reference to the grid store + * Reference to the grid store */ store: null, @@ -96,22 +90,14 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { this.pagingToolbar = grid.getBottomToolbar(); } - // initial filter conditions - baseParams = this.store.baseParams; - if ('where' in baseParams) { - for (i = 0; i < baseParams.where.length; i += 1) { - this.initialFilterConditions.push(baseParams.where[i]); - } - } - - // reset filter when the store emit the clear event - // NOTE: require when the pGridBasicMenu reset the store. - // In that case, the filter avec to be reset too. - this.store.on('clear', this.reset, this); + // reset filter when receiving resetgrid event + // The main user case is when the pGridExpertMenu is triggered + // to reset the grid. In that case, the filter avec to be reset too. + grid.on('resetgrid', this.reset, this); }, /** - * Handler to catch a change in field value + * Handler to catch a change in field value and to filter the store */ onChange: function (field) { @@ -123,19 +109,22 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { }, /** - * Handler to reset the filter + * Handler to reset the filter and the store content */ onReset: function () { // reset field values and filter conditions this.reset(); - + + // restore initial where condition of the store + this.store.restoreWhere(); + // update the store this.updateStore(); }, /** - * Reset the filter + * Reset the filter conditions */ reset: function () { @@ -149,22 +138,10 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { // reset filter conditions this.filterConditions = {}; - - if (this.initialFilterConditions.length > 0) { - this.store.baseParams.where = this.initialFilterConditions; - - } else { - delete this.store.baseParams.where; - } - - // reset the page size to the default value - if (this.pagingToolbar) { - this.pagingToolbar.pageSize = 10; - } }, /** - * Setup condition + * Setup filter conditions * @param {Ext.form.Field} */ setupCondition: function (field) { @@ -197,8 +174,10 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { } // build the complete where clause - for (i = 0; i < this.initialFilterConditions.length; i += 1) { - conditions.push(this.initialFilterConditions[i]); + if (this.store.initialWhere) { + for (i = 0; i < this.store.initialWhere.length; i += 1) { + conditions.push(this.store.initialWhere[i]); + } } for (k in this.filterConditions) { -- GitLab