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