From 4b029132329ed2ba3c9cbf6b782c29060b2a2cad Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <legac@cppm.in2p3.fr> Date: Fri, 21 Nov 2014 18:34:49 +0100 Subject: [PATCH] Add the userReset functionality in the ComboBoxMster class. Modify hte ComboBoxSlave and ComboBoxUserReset accordingly. --- static/plugin_dbui/CHANGELOG | 3 + .../src/form/field/ComboBoxMaster.js | 38 ++++++++++++ .../src/form/field/ComboBoxSlave.js | 16 +++-- .../src/form/field/ComboBoxUserReset.js | 61 +------------------ 4 files changed, 51 insertions(+), 67 deletions(-) diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG index 8c438a06..0c62b869 100644 --- a/static/plugin_dbui/CHANGELOG +++ b/static/plugin_dbui/CHANGELOG @@ -1,6 +1,9 @@ --------------------------------- CHANGE LOG ---------------------------------- HEAD + - Add the user reset functionality in the ComboBoxMaster class. + Modify ComboBoxSlave and ComboBoxUserReset accordingly. + In addition the first value of the store is load in the ComboBoxSlave. 0.6.1.10 (Nov 2014) - Add the plugin App.grid.plugin.Export. diff --git a/static/plugin_dbui/src/form/field/ComboBoxMaster.js b/static/plugin_dbui/src/form/field/ComboBoxMaster.js index a7e6ec3c..32b34dd4 100644 --- a/static/plugin_dbui/src/form/field/ComboBoxMaster.js +++ b/static/plugin_dbui/src/form/field/ComboBoxMaster.js @@ -39,6 +39,14 @@ Ext.define('App.form.field.ComboBoxMaster', { */ refStore: null, + /** + * @cfg {Boolean} userReset + * When true, the user can reset the comboBox by selecting + * the row containing the emptyText. + * + */ + userReset: false, + // Predefined setting // Works in auto completion mode when the user type value. // In any case the value should belongs to the list. @@ -78,6 +86,11 @@ Ext.define('App.form.field.ComboBoxMaster', { this.refStore.on('remove', this.createLocalStore, this); this.refStore.on('update', this.createLocalStore, this); this.refStore.on('write', this.createLocalStore, this); + + // user reset + if (this.userReset) { + this.on('select', this.onSelect); + } }, // private method requires by the ExtJs component model @@ -87,6 +100,10 @@ Ext.define('App.form.field.ComboBoxMaster', { this.refStore.un('update', this.createLocalStore, this); this.refStore.un('write', this.createLocalStore, this); + if (this.userReset) { + this.un('select', this.onSelect); + } + this.callParent(arguments); }, @@ -132,6 +149,10 @@ Ext.define('App.form.field.ComboBoxMaster', { master, value; + if (this.userReset) { + data = [[this.emptyText, null]]; + } + for (i = 0; i < records.length; i += 1) { master = records[i].get(this.displayField); @@ -145,5 +166,22 @@ Ext.define('App.form.field.ComboBoxMaster', { // clear the store and load new data this.store.loadData(data, false); + }, + + /** + * Reset the comBox when the selected row contains the emptyText value. + * + * @param {App.form.field.ComboBoxUserReset} combo + * @param {Array} records + * @param {Object} eOpts + */ + onSelect: function (combo, records, eOpts) { + + "use strict"; + + // the value is null when the emptyText is selected + if (!records[0].get(combo.valueField)) { + combo.reset(); + } } }); \ No newline at end of file diff --git a/static/plugin_dbui/src/form/field/ComboBoxSlave.js b/static/plugin_dbui/src/form/field/ComboBoxSlave.js index c820c721..c20e0093 100644 --- a/static/plugin_dbui/src/form/field/ComboBoxSlave.js +++ b/static/plugin_dbui/src/form/field/ComboBoxSlave.js @@ -174,9 +174,7 @@ Ext.define('App.form.field.ComboBoxSlave', { }, /** - * Select the authorized slave values. - * When the number of authorized value is equal to 1, the - * value is loaded in the slave. + * Select the authorized slave values and load the firs one. * * @param {Ext.form.field.ComboBox} combo * @param {Ext.data.Model[]} records @@ -195,13 +193,13 @@ Ext.define('App.form.field.ComboBoxSlave', { // filter the local store this.store.filter(this.masterValueField, value); - // enable the widget - this.setDisabled(false); + // enable the widget when the master value is not null. + // By construction the master value is null + // when the user reset the comboBox + this.setDisabled(value === null); - // load the value when there is only one - if (this.store.getCount() === 1) { - this.setValue(this.store.getAt(0).get(this.valueField)); - } + // load the first value + this.setValue(this.store.getAt(0).get(this.valueField)); }, /** diff --git a/static/plugin_dbui/src/form/field/ComboBoxUserReset.js b/static/plugin_dbui/src/form/field/ComboBoxUserReset.js index a0a81002..cd6ffbe1 100644 --- a/static/plugin_dbui/src/form/field/ComboBoxUserReset.js +++ b/static/plugin_dbui/src/form/field/ComboBoxUserReset.js @@ -22,65 +22,10 @@ Ext.define('App.form.field.ComboBoxUserReset', { // 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 () { + // force the user reset + this.userReset = true; - this.un('select', this.onSelect); + // initialise the base class 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 -- GitLab