From 60aebec298723d5b34db8596d4aafdad80cf8c4f Mon Sep 17 00:00:00 2001 From: legac <renaud.legac@free.fr> Date: Sun, 9 Feb 2014 15:41:54 +0100 Subject: [PATCH] Add the ComboBowUserReset. --- modules/plugin_dbui/converter.py | 3 +- .../src/form/field/ComboBoxUserReset.js | 86 +++++++++++++++++++ static/plugin_dbui/src/grid/Filter.js | 8 ++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 static/plugin_dbui/src/form/field/ComboBoxUserReset.js diff --git a/modules/plugin_dbui/converter.py b/modules/plugin_dbui/converter.py index f484b924..30e2b84a 100644 --- a/modules/plugin_dbui/converter.py +++ b/modules/plugin_dbui/converter.py @@ -532,9 +532,10 @@ def to_gridFilter(table, **kwargs): if cfg['xtype'] == 'xtextarea': cfg['xtype'] = 'xtextfield' - # empty text for combobox + # combobox can be reset individually if cfg['xtype'] == 'xcombobox': cfg['emptyText']= T('select...') + cfg['xtype'] = 'xcomboboxuserreset' # prepare the name for the where close [table.field] cfg['name'] = name diff --git a/static/plugin_dbui/src/form/field/ComboBoxUserReset.js b/static/plugin_dbui/src/form/field/ComboBoxUserReset.js new file mode 100644 index 00000000..a0a81002 --- /dev/null +++ b/static/plugin_dbui/src/form/field/ComboBoxUserReset.js @@ -0,0 +1,86 @@ +/** + * The App.form.field.ComboBoxUserReset is a Ext.form.field.ComboBox + * with a mechanism to reset it when the user select a dedicated row. + * This row is the first one and contains the emptyText. + * + * @since 0.6.0.6 + * + */ +Ext.define('App.form.field.ComboBoxUserReset', { + + extend: 'App.form.field.ComboBoxMaster', + alias: 'widget.xcomboboxuserreset', + + /** + * @cfg {String} emptyText (required) + * Define the value used to reset the ComboBox. + */ + + // private method requires by the ExtJs component model + initComponent: function () { + + // define the reference store required by the base class + this.refStore = this.store; + + // initialise the base class + this.callParent(arguments); + + this.on('select', this.onSelect); + }, + + // private method requires by the ExtJs component model + beforeDestroy: function () { + + this.un('select', this.onSelect); + this.callParent(arguments); + }, + + /** + * Reset the comBox when the selected row is the one + * with the emptyText value. + * + * @param {App.form.field.ComboBoxUserReset} combo + * @param {Array} records + * @param {Object} eOpts + */ + onSelect: function (combo, records, eOpts) { + + "use strict"; + + if (!records[0].get(combo.valueField)) { + combo.reset(); + } + }, + + /** + * Create the local store and to load the data + * from the reference store. + * + * @param {Ext.data.Model[]} records + * + */ + onCreate: function (records) { + + "use strict"; + + var data = [[this.emptyText, null]], + i, + keys = [], + master, + value; + + for (i = 0; i < records.length; i += 1) { + + master = records[i].get(this.displayField); + + if (keys.indexOf(master) === -1) { + keys.push(master); + value = records[i].get(this.valueField); + data.push([master, value]); + } + } + + // clear the store and load new data + this.store.loadData(data, false); + } +}); \ No newline at end of file diff --git a/static/plugin_dbui/src/grid/Filter.js b/static/plugin_dbui/src/grid/Filter.js index 5a62b336..bc6e2b17 100644 --- a/static/plugin_dbui/src/grid/Filter.js +++ b/static/plugin_dbui/src/grid/Filter.js @@ -63,6 +63,10 @@ Ext.define('App.grid.Filter', { item.on('select', this.onChange, this); break; + case 'xcomboboxuserreset': + item.on('select', this.onChange, this); + break; + // catch a change of date case 'datefield': item.on('select', this.onChange, this); @@ -102,6 +106,10 @@ Ext.define('App.grid.Filter', { item.un('select', this.onChange, this); break; + case 'xcomboboxuserreset': + item.un('select', this.onChange, this); + break; + // catch a change of date case 'datefield': item.un('select', this.onChange, this); -- GitLab