]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/form/VMSelector.js
ui: eslint: fix various spacing related issues
[pve-manager.git] / www / manager6 / form / VMSelector.js
CommitLineData
42aff488
DC
1/* filter is a javascript builtin, but extjs calls it also filter */
2Ext.define('PVE.form.VMSelector', {
3 extend: 'Ext.grid.Panel',
4 alias: 'widget.vmselector',
5
6 mixins: {
f6710aac 7 field: 'Ext.form.field.Field',
42aff488
DC
8 },
9
10 allowBlank: true,
11 selectAll: false,
12 isFormField: true,
13
14 plugins: 'gridfilters',
15
16 store: {
17 model: 'PVEResources',
18 autoLoad: true,
19 sorters: 'vmid',
20 filters: [{
21 property: 'type',
f6710aac
TL
22 value: /lxc|qemu/,
23 }],
42aff488
DC
24 },
25 columns: [
26 {
27 header: 'ID',
28 dataIndex: 'vmid',
29 width: 80,
30 filter: {
f6710aac
TL
31 type: 'number',
32 },
42aff488
DC
33 },
34 {
35 header: gettext('Node'),
f6710aac 36 dataIndex: 'node',
42aff488
DC
37 },
38 {
39 header: gettext('Status'),
40 dataIndex: 'status',
41 filter: {
f6710aac
TL
42 type: 'list',
43 },
42aff488
DC
44 },
45 {
46 header: gettext('Name'),
47 dataIndex: 'name',
48 flex: 1,
49 filter: {
f6710aac
TL
50 type: 'string',
51 },
42aff488
DC
52 },
53 {
54 header: gettext('Pool'),
55 dataIndex: 'pool',
56 filter: {
f6710aac
TL
57 type: 'list',
58 },
42aff488
DC
59 },
60 {
61 header: gettext('Type'),
62 dataIndex: 'type',
63 width: 120,
64 renderer: function(value) {
65 if (value === 'qemu') {
66 return gettext('Virtual Machine');
67 } else if (value === 'lxc') {
68 return gettext('LXC Container');
69 }
70
71 return '';
72 },
73 filter: {
74 type: 'list',
75 store: {
76 data: [
8058410f
TL
77 { id: 'qemu', text: gettext('Virtual Machine') },
78 { id: 'lxc', text: gettext('LXC Container') },
42aff488
DC
79 ],
80 // due to EXTJS-18711
81 // we have to do a static list via a store
82 // but to avoid creating an object,
83 // we have to have a pseudo un function
8058410f 84 un: function() {},
f6710aac
TL
85 },
86 },
c9329af1
TL
87 },
88 {
89 header: 'HA ' + gettext('Status'),
90 dataIndex: 'hastate',
91 flex: 1,
92 filter: {
f6710aac
TL
93 type: 'list',
94 },
95 },
42aff488
DC
96 ],
97
98 selModel: {
99 selType: 'checkboxmodel',
f6710aac 100 mode: 'SIMPLE',
42aff488
DC
101 },
102
103 checkChangeEvents: [
104 'selectionchange',
f6710aac 105 'change',
42aff488
DC
106 ],
107
108 listeners: {
109 selectionchange: function() {
110 // to trigger validity and error checks
111 this.checkChange();
f6710aac 112 },
42aff488
DC
113 },
114
115 getValue: function() {
116 var me = this;
117 var sm = me.getSelectionModel();
118 var selection = sm.getSelection();
119 var values = [];
120 var store = me.getStore();
121 selection.forEach(function(item) {
122 // only add if not filtered
123 if (store.findExact('vmid', item.data.vmid) !== -1) {
124 values.push(item.data.vmid);
125 }
126 });
127 return values;
128 },
129
130 setValue: function(value) {
131 console.log(value);
132 var me = this;
133 var sm = me.getSelectionModel();
134 if (!Ext.isArray(value)) {
135 value = value.split(',');
136 }
137 var selection = [];
138 var store = me.getStore();
139
140 value.forEach(function(item) {
f6710aac 141 var rec = store.findRecord('vmid', item, 0, false, true, true);
42aff488
DC
142 console.log(store);
143
144 if (rec) {
145 console.log(rec);
146 selection.push(rec);
147 }
148 });
149
150 sm.select(selection);
151
152 return me.mixins.field.setValue.call(me, value);
153 },
154
155 getErrors: function(value) {
156 var me = this;
8058410f 157 if (me.allowBlank === false &&
42aff488 158 me.getSelectionModel().getCount() === 0) {
f6710aac 159 me.addBodyCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
42aff488
DC
160 return [gettext('No VM selected')];
161 }
162
f6710aac 163 me.removeBodyCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']);
42aff488
DC
164 return [];
165 },
166
167 initComponent: function() {
168 var me = this;
169
170 me.callParent();
171
172 if (me.nodename) {
173 me.store.filters.add({
174 property: 'node',
5c6b8a65 175 exactMatch: true,
f6710aac 176 value: me.nodename,
42aff488
DC
177 });
178 }
179
eb882c6f
DC
180 // only show the relevant guests by default
181 if (me.action) {
919ae0f7 182 var statusfilter = '';
eb882c6f
DC
183 switch (me.action) {
184 case 'startall':
919ae0f7 185 statusfilter = 'stopped';
eb882c6f
DC
186 break;
187 case 'stopall':
919ae0f7 188 statusfilter = 'running';
eb882c6f
DC
189 break;
190 }
919ae0f7
DC
191 if (statusfilter !== '') {
192 me.store.filters.add({
193 property: 'template',
f6710aac
TL
194 value: 0,
195 }, {
919ae0f7
DC
196 id: 'x-gridfilter-status',
197 operator: 'in',
198 property: 'status',
f6710aac 199 value: [statusfilter],
919ae0f7
DC
200 });
201 }
eb882c6f
DC
202 }
203
42aff488
DC
204 var store = me.getStore();
205 var sm = me.getSelectionModel();
206
207 if (me.selectAll) {
8058410f 208 me.mon(store, 'load', function() {
42aff488
DC
209 me.getSelectionModel().selectAll(false);
210 });
211 }
f6710aac 212 },
42aff488 213});
a86b4daf
TL
214
215
216Ext.define('PVE.form.VMComboSelector', {
0fc95a12 217 extend: 'Proxmox.form.ComboGrid',
a86b4daf
TL
218 alias: 'widget.vmComboSelector',
219
220 valueField: 'vmid',
221 displayField: 'vmid',
222
223 autoSelect: false,
224 editable: true,
225 anyMatch: true,
226 forceSelection: true,
227
228 store: {
229 model: 'PVEResources',
230 autoLoad: true,
231 sorters: 'vmid',
232 filters: [{
233 property: 'type',
f6710aac
TL
234 value: /lxc|qemu/,
235 }],
a86b4daf
TL
236 },
237
238 listConfig: {
239 width: 600,
240 plugins: 'gridfilters',
241 columns: [
242 {
243 header: 'ID',
244 dataIndex: 'vmid',
245 width: 80,
246 filter: {
f6710aac
TL
247 type: 'number',
248 },
a86b4daf
TL
249 },
250 {
251 header: gettext('Name'),
252 dataIndex: 'name',
253 flex: 1,
254 filter: {
f6710aac
TL
255 type: 'string',
256 },
a86b4daf
TL
257 },
258 {
259 header: gettext('Node'),
f6710aac 260 dataIndex: 'node',
a86b4daf
TL
261 },
262 {
263 header: gettext('Status'),
264 dataIndex: 'status',
265 filter: {
f6710aac
TL
266 type: 'list',
267 },
a86b4daf
TL
268 },
269 {
270 header: gettext('Pool'),
271 dataIndex: 'pool',
272 hidden: true,
273 filter: {
f6710aac
TL
274 type: 'list',
275 },
a86b4daf
TL
276 },
277 {
278 header: gettext('Type'),
279 dataIndex: 'type',
280 width: 120,
281 renderer: function(value) {
282 if (value === 'qemu') {
283 return gettext('Virtual Machine');
284 } else if (value === 'lxc') {
285 return gettext('LXC Container');
286 }
287
288 return '';
289 },
290 filter: {
291 type: 'list',
292 store: {
293 data: [
8058410f
TL
294 { id: 'qemu', text: gettext('Virtual Machine') },
295 { id: 'lxc', text: gettext('LXC Container') },
a86b4daf 296 ],
8058410f 297 un: function() {}, // due to EXTJS-18711
f6710aac
TL
298 },
299 },
a86b4daf
TL
300 },
301 {
302 header: 'HA ' + gettext('Status'),
303 dataIndex: 'hastate',
304 hidden: true,
305 flex: 1,
306 filter: {
f6710aac
TL
307 type: 'list',
308 },
309 },
310 ],
311 },
a86b4daf 312});