]>
Commit | Line | Data |
---|---|---|
9a389924 | 1 | Ext.define('PVE.form.IPRefSelector', { |
0fc95a12 | 2 | extend: 'Proxmox.form.ComboGrid', |
9a389924 DM |
3 | alias: ['widget.pveIPRefSelector'], |
4 | ||
5 | base_url: undefined, | |
6 | ||
7 | preferredValue: '', // hack: else Form sets dirty flag? | |
8 | ||
9 | ref_type: undefined, // undefined = any [undefined, 'ipset' or 'alias'] | |
10 | ||
beec97dc TL |
11 | valueField: 'ref', |
12 | displayField: 'ref', | |
a02348b9 | 13 | notFoundIsValid: true, |
beec97dc | 14 | |
9a389924 DM |
15 | initComponent: function() { |
16 | var me = this; | |
17 | ||
18 | if (!me.base_url) { | |
19 | throw "no base_url specified"; | |
20 | } | |
21 | ||
22 | var url = "/api2/json" + me.base_url; | |
23 | if (me.ref_type) { | |
24 | url += "?type=" + me.ref_type; | |
25 | } | |
26 | ||
27 | var store = Ext.create('Ext.data.Store', { | |
28 | autoLoad: true, | |
8058410f | 29 | fields: ['type', 'name', 'ref', 'comment'], |
9a389924 DM |
30 | idProperty: 'ref', |
31 | proxy: { | |
56a353b9 | 32 | type: 'proxmox', |
f6710aac | 33 | url: url, |
9a389924 DM |
34 | }, |
35 | sorters: { | |
36 | property: 'ref', | |
f6710aac TL |
37 | order: 'DESC', |
38 | }, | |
9a389924 DM |
39 | }); |
40 | ||
41 | var disable_query_for_ips = function(f, value) { | |
2a4971d8 | 42 | if (value === null || |
9a389924 | 43 | value.match(/^\d/)) { // IP address starts with \d |
ec505260 | 44 | f.queryDelay = 9999999999; // hack: disable with long delay |
9a389924 DM |
45 | } else { |
46 | f.queryDelay = 10; | |
47 | } | |
48 | }; | |
49 | ||
50 | var columns = []; | |
51 | ||
52 | if (!me.ref_type) { | |
53 | columns.push({ | |
54 | header: gettext('Type'), | |
55 | dataIndex: 'type', | |
56 | hideable: false, | |
f6710aac | 57 | width: 60, |
9a389924 DM |
58 | }); |
59 | } | |
60 | ||
6cc50c80 | 61 | columns.push( |
9a389924 DM |
62 | { |
63 | header: gettext('Name'), | |
64 | dataIndex: 'ref', | |
65 | hideable: false, | |
f6710aac | 66 | width: 140, |
9a389924 DM |
67 | }, |
68 | { | |
2a4971d8 | 69 | header: gettext('Comment'), |
91535f2b DC |
70 | dataIndex: 'comment', |
71 | renderer: Ext.String.htmlEncode, | |
f6710aac TL |
72 | flex: 1, |
73 | }, | |
6cc50c80 | 74 | ); |
9a389924 DM |
75 | |
76 | Ext.apply(me, { | |
77 | store: store, | |
f6710aac | 78 | listConfig: { columns: columns }, |
9a389924 DM |
79 | }); |
80 | ||
81 | me.on('change', disable_query_for_ips); | |
82 | ||
83 | me.callParent(); | |
f6710aac | 84 | }, |
9a389924 DM |
85 | }); |
86 |