diff --git a/models/widgets_fields.py b/models/widgets_fields.py index af93efa9d2969f10812e4632cb452d182f5fc966..9fe1e0f84f7a89fdddee0a75bc5f96cedb1b84f7 100755 --- a/models/widgets_fields.py +++ b/models/widgets_fields.py @@ -28,14 +28,16 @@ fieldsModifier.merge_fields('conference_start', # fieldsModifier = dbui.FieldsModifier('foo1') fieldsModifier.configure_field('my_axis', - master=True, - masterField='axis', - masterStore='axesStore', + displayField='axis', + role='master', + store='axesStore', + valueField='axis', xtype='xlinkedcombobox') fieldsModifier.configure_field('my_granularity', displayField='granularity', mode='local', + role='slave', store='axesStore', valueField='granularity', xtype='xlinkedcombobox') diff --git a/static/plugin_dbui/src/applinkedcombobox.js b/static/plugin_dbui/src/applinkedcombobox.js index 8ca795c434a5cf92aead4c03a37a3a284734654e..f19a4138c2df3ddbd7cb18b6a95a26fde8d89934 100644 --- a/static/plugin_dbui/src/applinkedcombobox.js +++ b/static/plugin_dbui/src/applinkedcombobox.js @@ -7,11 +7,12 @@ * linked to a common store. * * The master shows the values which are used to filter the common store. - * Values are unique and sorted in alphabetic order. It is enough to define - * the properties master, masterField and masterStore to setup a master. + * Values are unique and sorted in alphabetic order. + * The properties role, store, displayField and valueField have to be defined. * - * A slave is a standard combobox. The store identifier should be the same - * than the masterStore. + * A slave is a standard combobox. + * The properties store, displayField and valueField have to be defined. + * The store identifier should be the same for the master and the slave. * * Several masters and slaves can be attached to a single store. * @@ -23,55 +24,53 @@ Ext.namespace('App.form'); App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { /** - * @cfg {Boolean] master true for a master combobox. default is false. + * @cfg {String] role role of the combobox either master of slave. + * The default is slave */ - master: false, + role: 'slave', /** - * @cfg {String] masterField field of the common store display in the combobox - */ - masterField: null, - - /** - * @cfg {String] masterStore identifier of the store used by masters and slave - */ + * private properties + */ masterStore: null, - + /** * private method require by the ExtJS component model */ initComponent: function () { - this.lazyInit = false; - // configure a master combobox. // create a local store containing the values which can be used // to filter the master store - if (this.master) { + if (this.role === 'master') { + + this.masterStore = App.getStore(this.store); this.mode = 'local'; - this.store = []; - this.masterStore = App.getStore(this.masterStore); - this.masterStore.each(this.fillData, this); - this.store.sort(); - this.triggerAction = 'all'; + this.store = new Ext.data.ArrayStore({ + fields: [this.displayField, this.valueField], + data: this.getMasterData() + }); // configure a slave combobox - } else { + } else if (this.role === 'slave'){ this.store = App.getStore(this.store); - this.triggerAction = 'all'; } + // configuration parameters common to master and slave + this.store.sort(this.dispayField); + this.triggerAction = 'all'; + // construct the underlying class. DON'T MOVE App.form.LinkedComboBox.superclass.initComponent.call(this); // logic to filter the content of the master store - if (this.master) { + if (this.role === 'master') { this.on('select', this.filterMasterStore, this); // logic to update the content of a slave - } else { + } else if (this.role === 'slave') { this.store.on('datachanged', this.onDataChanged, this); } @@ -87,27 +86,26 @@ App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { /** * Helper method to extract the master values to filter the common store. * - * @param {Ext.data.Record} record */ - fillData: function (record) { - var i, - value = record.get(this.masterField); + getMasterData: function () { - // initialise the list - if (this.store.length === 0) { - this.store.push(value); - return; - } + var data = [], + key, + keys = [], + i, + record; - // avoid duplicate entries - for (i = 0; i < this.store.length; i += 1) { - if (value === this.store[i]) { - return; + for (i = 0; i < this.masterStore.getCount(); i += 1) { + record = this.masterStore.getAt(i); + key = record.get(this.displayField); + if (keys.indexOf(key) === -1) { + keys.push(key); + data.push([key, record.get(this.valueField)]); } } - this.store.push(value); + return data; }, - + /** * Helper method to filter the master store * @@ -116,7 +114,7 @@ App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { * @param {Integer} index */ filterMasterStore: function (combo, record, index) { - this.masterStore.filter(this.masterField, combo.getValue()); + this.masterStore.filter(this.valueField, combo.getValue()); }, /** @@ -125,7 +123,7 @@ App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { */ onDataChanged: function () { - var value = this.store.getAt(0).get(this.displayField); + var value = this.store.getAt(0).get(this.valueField); this.setValue(value); } });