Skip to content
Snippets Groups Projects
Commit 60aebec2 authored by legac's avatar legac
Browse files

Add the ComboBowUserReset.

parent 5849c401
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
/**
* 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
......@@ -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);
......
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