]>
Commit | Line | Data |
---|---|---|
211267b8 DM |
1 | /* Key-Value ComboBox |
2 | * | |
3 | * config properties: | |
4 | * comboItems: an array of Key - Value pairs | |
5 | * deleteEmpty: if set to true (default), an empty value received from the | |
6 | * comboBox will reset the property to its default value | |
7 | */ | |
a4eeb593 | 8 | Ext.define('Proxmox.form.KVComboBox', { |
211267b8 DM |
9 | extend: 'Ext.form.field.ComboBox', |
10 | alias: 'widget.proxmoxKVComboBox', | |
11 | ||
f0372135 DM |
12 | config: { |
13 | deleteEmpty: true | |
14 | }, | |
15 | ||
211267b8 DM |
16 | comboItems: undefined, |
17 | displayField: 'value', | |
18 | valueField: 'key', | |
19 | queryMode: 'local', | |
20 | ||
21 | // overide framework function to implement deleteEmpty behaviour | |
22 | getSubmitData: function() { | |
23 | var me = this, | |
24 | data = null, | |
25 | val; | |
26 | if (!me.disabled && me.submitValue) { | |
27 | val = me.getSubmitValue(); | |
28 | if (val !== null && val !== '' && val !== '__default__') { | |
29 | data = {}; | |
30 | data[me.getName()] = val; | |
f0372135 | 31 | } else if (me.getDeleteEmpty()) { |
211267b8 DM |
32 | data = {}; |
33 | data['delete'] = me.getName(); | |
34 | } | |
35 | } | |
36 | return data; | |
37 | }, | |
38 | ||
39 | validator: function(val) { | |
40 | var me = this; | |
41 | ||
42 | if (me.editable || val === null || val === '') { | |
43 | return true; | |
44 | } | |
45 | ||
46 | if (me.store.getCount() > 0) { | |
47 | var values = me.multiSelect ? val.split(me.delimiter) : [val]; | |
48 | var items = me.store.getData().collect('value', 'data'); | |
49 | if (Ext.Array.every(values, function(value) { | |
50 | return Ext.Array.contains(items, value); | |
51 | })) { | |
52 | return true; | |
53 | } | |
54 | } | |
55 | ||
56 | // returns a boolean or string | |
57 | /*jslint confusion: true */ | |
58 | return "value '" + val + "' not allowed!"; | |
59 | }, | |
60 | ||
61 | initComponent: function() { | |
62 | var me = this; | |
63 | ||
64 | me.store = Ext.create('Ext.data.ArrayStore', { | |
65 | model: 'KeyValue', | |
66 | data : me.comboItems | |
67 | }); | |
68 | ||
69 | if (me.initialConfig.editable === undefined) { | |
70 | me.editable = false; | |
71 | } | |
72 | ||
73 | me.callParent(); | |
74 | } | |
75 | }); |