mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-06-23 05:05:16 +00:00
KVComboBox: imported from pve-manager
This commit is contained in:
parent
0e49da6db9
commit
211267b8cc
1
Makefile
1
Makefile
@ -23,6 +23,7 @@ JSSRC= \
|
|||||||
form/IntegerField.js \
|
form/IntegerField.js \
|
||||||
form/TextField.js \
|
form/TextField.js \
|
||||||
form/Checkbox.js \
|
form/Checkbox.js \
|
||||||
|
form/KVComboBox.js \
|
||||||
grid/ObjectGrid.js \
|
grid/ObjectGrid.js \
|
||||||
grid/PendingObjectGrid.js \
|
grid/PendingObjectGrid.js \
|
||||||
panel/InputPanel.js \
|
panel/InputPanel.js \
|
||||||
|
72
form/KVComboBox.js
Normal file
72
form/KVComboBox.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* Key-Value ComboBox
|
||||||
|
*
|
||||||
|
* config properties:
|
||||||
|
* comboItems: an array of Key - Value pairs
|
||||||
|
* deleteEmpty: if set to true (default), an empty value received from the
|
||||||
|
* comboBox will reset the property to its default value
|
||||||
|
*/
|
||||||
|
Ext.define('proxmox.form.KVComboBox', {
|
||||||
|
extend: 'Ext.form.field.ComboBox',
|
||||||
|
alias: 'widget.proxmoxKVComboBox',
|
||||||
|
|
||||||
|
deleteEmpty: true,
|
||||||
|
comboItems: undefined,
|
||||||
|
displayField: 'value',
|
||||||
|
valueField: 'key',
|
||||||
|
queryMode: 'local',
|
||||||
|
|
||||||
|
// overide framework function to implement deleteEmpty behaviour
|
||||||
|
getSubmitData: function() {
|
||||||
|
var me = this,
|
||||||
|
data = null,
|
||||||
|
val;
|
||||||
|
if (!me.disabled && me.submitValue) {
|
||||||
|
val = me.getSubmitValue();
|
||||||
|
if (val !== null && val !== '' && val !== '__default__') {
|
||||||
|
data = {};
|
||||||
|
data[me.getName()] = val;
|
||||||
|
} else if (me.deleteEmpty) {
|
||||||
|
data = {};
|
||||||
|
data['delete'] = me.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
validator: function(val) {
|
||||||
|
var me = this;
|
||||||
|
|
||||||
|
if (me.editable || val === null || val === '') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (me.store.getCount() > 0) {
|
||||||
|
var values = me.multiSelect ? val.split(me.delimiter) : [val];
|
||||||
|
var items = me.store.getData().collect('value', 'data');
|
||||||
|
if (Ext.Array.every(values, function(value) {
|
||||||
|
return Ext.Array.contains(items, value);
|
||||||
|
})) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns a boolean or string
|
||||||
|
/*jslint confusion: true */
|
||||||
|
return "value '" + val + "' not allowed!";
|
||||||
|
},
|
||||||
|
|
||||||
|
initComponent: function() {
|
||||||
|
var me = this;
|
||||||
|
|
||||||
|
me.store = Ext.create('Ext.data.ArrayStore', {
|
||||||
|
model: 'KeyValue',
|
||||||
|
data : me.comboItems
|
||||||
|
});
|
||||||
|
|
||||||
|
if (me.initialConfig.editable === undefined) {
|
||||||
|
me.editable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
me.callParent();
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user