]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/form/IPRefSelector.js
ui: iso selector: fix layout, stretch items again to full space
[pve-manager.git] / www / manager6 / form / IPRefSelector.js
CommitLineData
9a389924 1Ext.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
5d6262aa 11 valueField: 'scopedref',
beec97dc 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,
5d6262aa
LN
29 fields: [
30 'type',
31 'name',
32 'ref',
33 'comment',
34 'scope',
35 {
36 name: 'scopedref',
37 calculate: function(v) {
38 if (v.type === 'alias') {
39 return `${v.scope}/${v.name}`;
40 } else {
41 return `+${v.scope}/${v.name}`;
42 }
43 },
44 },
45 ],
9a389924
DM
46 idProperty: 'ref',
47 proxy: {
56a353b9 48 type: 'proxmox',
f6710aac 49 url: url,
9a389924
DM
50 },
51 sorters: {
52 property: 'ref',
392e3cf1 53 direction: 'ASC',
f6710aac 54 },
9a389924
DM
55 });
56
57 var disable_query_for_ips = function(f, value) {
2a4971d8 58 if (value === null ||
9a389924 59 value.match(/^\d/)) { // IP address starts with \d
ec505260 60 f.queryDelay = 9999999999; // hack: disable with long delay
9a389924
DM
61 } else {
62 f.queryDelay = 10;
63 }
64 };
65
66 var columns = [];
67
68 if (!me.ref_type) {
69 columns.push({
70 header: gettext('Type'),
71 dataIndex: 'type',
72 hideable: false,
f6710aac 73 width: 60,
9a389924
DM
74 });
75 }
76
6cc50c80 77 columns.push(
9a389924
DM
78 {
79 header: gettext('Name'),
80 dataIndex: 'ref',
81 hideable: false,
f6710aac 82 width: 140,
9a389924 83 },
5d6262aa
LN
84 {
85 header: gettext('Scope'),
86 dataIndex: 'scope',
87 hideable: false,
88 width: 140,
89 renderer: function(value) {
90 return value === 'dc' ? gettext("Datacenter") : gettext("Guest");
91 },
92 },
9a389924 93 {
2a4971d8 94 header: gettext('Comment'),
91535f2b
DC
95 dataIndex: 'comment',
96 renderer: Ext.String.htmlEncode,
5d6262aa 97 minWidth: 60,
f6710aac
TL
98 flex: 1,
99 },
6cc50c80 100 );
9a389924
DM
101
102 Ext.apply(me, {
103 store: store,
5d6262aa
LN
104 listConfig: {
105 columns: columns,
106 width: 500,
107 },
9a389924
DM
108 });
109
110 me.on('change', disable_query_for_ips);
111
112 me.callParent();
f6710aac 113 },
9a389924
DM
114});
115