diff --git a/models/widgets_grids.py b/models/widgets_grids.py index 362288b1b144cd112f0c1acb3c6c628e1dad433a..5ce40d7bd01bca25b1133fb29624edd3e9154b00 100644 --- a/models/widgets_grids.py +++ b/models/widgets_grids.py @@ -8,7 +8,7 @@ dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete', 'pGridRowEditorContextMenu', 'pGridRowEditorDblClick', - 'pGridExport']) + 'pGridExpertMenu']) # # Polish categories grid # diff --git a/static/plugin_dbui/src/gridfilter.js b/static/plugin_dbui/src/gridfilter.js index c3de8b083b0ff6fe49a46948f2a32874dea72723..e10b0860a81170f468a47e84d9bb0dc864f4d792 100644 --- a/static/plugin_dbui/src/gridfilter.js +++ b/static/plugin_dbui/src/gridfilter.js @@ -48,7 +48,7 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { }, /** - * private method requests by the component model of Ext JS + * private method requests by the component model of ExtJS */ initComponent: function () { @@ -56,7 +56,7 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { fields, i; - // initialize the underlying class. + // initialise the underlying class. App.grid.GridFilter.superclass.initComponent.call(this); // associate handlers to fields @@ -103,13 +103,23 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { 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); }, /** * Handler to catch a change in field value */ onChange: function (field) { + + // setup the filter conditions this.setupCondition(field); + + // update the store + this.updateStore(); }, /** @@ -117,15 +127,26 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { */ onReset: function () { - var fields, - i; + // reset field values and filter conditions + this.reset(); + + // update the store + this.updateStore(); + }, + + /** + * Reset the filter + */ + reset: function () { - // reset the field value - fields = this.findByType('field'); + var fields = this.findByType('field'), + i; + + // reset the field values for (i = 0; i < fields.length; i += 1) { fields[i].reset(); } - + // reset filter conditions this.filterConditions = {}; @@ -140,11 +161,8 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { if (this.pagingToolbar) { this.pagingToolbar.pageSize = 10; } - - // update the store - this.updateStore(); }, - + /** * Setup condition * @param {Ext.form.Field} @@ -191,9 +209,6 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { // push new condition in the where clause of the store this.store.baseParams.where = conditions; - - // update the store - this.updateStore(); }, /** diff --git a/static/plugin_dbui/src/pgridexpertmenu.js b/static/plugin_dbui/src/pgridexpertmenu.js new file mode 100644 index 0000000000000000000000000000000000000000..fe837fe9154aac497e8b48f8f15d222aaa5dccb1 --- /dev/null +++ b/static/plugin_dbui/src/pgridexpertmenu.js @@ -0,0 +1,64 @@ +/** + * The grid expert menu plugin for toolbar + * The ptype of this component is pGridExpertMenu. + * + */ +Ext.namespace('App.grid'); + +App.grid.ExpertMenu = Ext.extend(Object, { + + /** + * Private parameter identifying the type of plugin + */ + ptype: 'pGridExpertMenu', + + /** + * Private attribute for internationalisation + */ + textExport: 'Export to CSV file', + textReset: 'Reset', + + /** + * Plugin initialisation + */ + init: function(grid){ + + var bbar = grid.getBottomToolbar(), + menu; + + menu = new Ext.Toolbar.SplitButton({ + menu:{ + items: [{ + listeners: {click: this.onReset, scope: grid}, + text: this.textReset + + }, { + href: App.csvUrl + '?tableName=' + App.getTableName(grid.store), + text: this.textExport + }] + } + }); + + bbar.add('->', menu); + }, + + /** + * Handler to reset filter and to reload the underlying data store + */ + onReset: function () { + + var grid = this, + store = this.getStore(); + + // remove gridFilter conditions + delete store.baseParams.where; + + // send the clear signal in order to reset gridFilter + store.fireEvent('clear'); + + // load the store with fresh data + store.load(); + } +}); + +Ext.preg('pGridExpertMenu', App.grid.ExpertMenu); diff --git a/static/plugin_dbui/src/pgridexport.js b/static/plugin_dbui/src/pgridexport.js deleted file mode 100644 index 2785dc721d77c76def3c0354571e30a135aa4868..0000000000000000000000000000000000000000 --- a/static/plugin_dbui/src/pgridexport.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * The grid export plugin for toolbar - * The ptype of this component is pGridExport. - * - * @version - * - */ -Ext.namespace('App.grid'); - -App.grid.Export = Ext.extend(Object, { - - /** - * Private parameter identifying the type of plugin - */ - ptype: 'pGridExport', - - /** - * Private attribute for internationalization - */ - textExport: 'Export to CSV file', - - /** - * Plugin initialization - */ - init: function(grid){ - var bbar = grid.getBottomToolbar() - bbar.add( - '->', { - xtype: 'xbuttondownload', - iconCls: 'xaction-export', - tooltip: this.textExport, - url: App.csvUrl + '?tableName=' + App.getTableName(grid.store) - } - ); - } -}); - -Ext.preg('pGridExport', App.grid.Export);