Skip to content
Snippets Groups Projects
Commit 4b029132 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the userReset functionality in the ComboBoxMster class. Modify hte...

Add the userReset functionality in the ComboBoxMster class. Modify hte ComboBoxSlave and ComboBoxUserReset accordingly.
parent aa41614e
No related branches found
No related tags found
No related merge requests found
--------------------------------- 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.
......
......@@ -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
......@@ -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));
},
/**
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment