]>
Commit | Line | Data |
---|---|---|
42aff488 DC |
1 | /* filter is a javascript builtin, but extjs calls it also filter */ |
2 | Ext.define('PVE.form.VMSelector', { | |
3 | extend: 'Ext.grid.Panel', | |
4 | alias: 'widget.vmselector', | |
5 | ||
6 | mixins: { | |
7 | field: 'Ext.form.field.Field' | |
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', | |
22 | value: /lxc|qemu/ | |
23 | }] | |
24 | }, | |
25 | columns: [ | |
26 | { | |
27 | header: 'ID', | |
28 | dataIndex: 'vmid', | |
29 | width: 80, | |
30 | filter: { | |
31 | type: 'number' | |
32 | } | |
33 | }, | |
34 | { | |
35 | header: gettext('Node'), | |
36 | dataIndex: 'node' | |
37 | }, | |
38 | { | |
39 | header: gettext('Status'), | |
40 | dataIndex: 'status', | |
41 | filter: { | |
42 | type: 'list' | |
43 | } | |
44 | }, | |
45 | { | |
46 | header: gettext('Name'), | |
47 | dataIndex: 'name', | |
48 | flex: 1, | |
49 | filter: { | |
50 | type: 'string' | |
51 | } | |
52 | }, | |
53 | { | |
54 | header: gettext('Pool'), | |
55 | dataIndex: 'pool', | |
56 | filter: { | |
57 | type: 'list' | |
58 | } | |
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: [ | |
77 | {id: 'qemu', text: gettext('Virtual Machine')}, | |
78 | {id: 'lxc', text: gettext('LXC Container')} | |
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 | |
84 | un: function(){} | |
85 | } | |
86 | } | |
c9329af1 TL |
87 | }, |
88 | { | |
89 | header: 'HA ' + gettext('Status'), | |
90 | dataIndex: 'hastate', | |
91 | flex: 1, | |
92 | filter: { | |
93 | type: 'list' | |
94 | } | |
42aff488 DC |
95 | } |
96 | ], | |
97 | ||
98 | selModel: { | |
99 | selType: 'checkboxmodel', | |
afc84579 | 100 | mode: 'SIMPLE' |
42aff488 DC |
101 | }, |
102 | ||
103 | checkChangeEvents: [ | |
104 | 'selectionchange', | |
105 | 'change' | |
106 | ], | |
107 | ||
108 | listeners: { | |
109 | selectionchange: function() { | |
110 | // to trigger validity and error checks | |
111 | this.checkChange(); | |
112 | } | |
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) { | |
141 | var rec = store.findRecord('vmid',item, 0, false, true, true); | |
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; | |
157 | if (me.allowBlank === false && | |
158 | me.getSelectionModel().getCount() === 0) { | |
159 | me.addBodyCls(['x-form-trigger-wrap-default','x-form-trigger-wrap-invalid']); | |
160 | return [gettext('No VM selected')]; | |
161 | } | |
162 | ||
163 | me.removeBodyCls(['x-form-trigger-wrap-default','x-form-trigger-wrap-invalid']); | |
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, |
42aff488 DC |
176 | value: me.nodename |
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', | |
194 | value: 0 | |
195 | },{ | |
196 | id: 'x-gridfilter-status', | |
197 | operator: 'in', | |
198 | property: 'status', | |
199 | value: [statusfilter] | |
200 | }); | |
201 | } | |
eb882c6f DC |
202 | } |
203 | ||
42aff488 DC |
204 | var store = me.getStore(); |
205 | var sm = me.getSelectionModel(); | |
206 | ||
207 | if (me.selectAll) { | |
208 | me.mon(store,'load', function(){ | |
209 | me.getSelectionModel().selectAll(false); | |
210 | }); | |
211 | } | |
212 | } | |
213 | }); | |
a86b4daf TL |
214 | |
215 | ||
216 | Ext.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', | |
234 | value: /lxc|qemu/ | |
235 | }] | |
236 | }, | |
237 | ||
238 | listConfig: { | |
239 | width: 600, | |
240 | plugins: 'gridfilters', | |
241 | columns: [ | |
242 | { | |
243 | header: 'ID', | |
244 | dataIndex: 'vmid', | |
245 | width: 80, | |
246 | filter: { | |
247 | type: 'number' | |
248 | } | |
249 | }, | |
250 | { | |
251 | header: gettext('Name'), | |
252 | dataIndex: 'name', | |
253 | flex: 1, | |
254 | filter: { | |
255 | type: 'string' | |
256 | } | |
257 | }, | |
258 | { | |
259 | header: gettext('Node'), | |
260 | dataIndex: 'node' | |
261 | }, | |
262 | { | |
263 | header: gettext('Status'), | |
264 | dataIndex: 'status', | |
265 | filter: { | |
266 | type: 'list' | |
267 | } | |
268 | }, | |
269 | { | |
270 | header: gettext('Pool'), | |
271 | dataIndex: 'pool', | |
272 | hidden: true, | |
273 | filter: { | |
274 | type: 'list' | |
275 | } | |
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: [ | |
294 | {id: 'qemu', text: gettext('Virtual Machine')}, | |
295 | {id: 'lxc', text: gettext('LXC Container')} | |
296 | ], | |
297 | un: function(){} // due to EXTJS-18711 | |
298 | } | |
299 | } | |
300 | }, | |
301 | { | |
302 | header: 'HA ' + gettext('Status'), | |
303 | dataIndex: 'hastate', | |
304 | hidden: true, | |
305 | flex: 1, | |
306 | filter: { | |
307 | type: 'list' | |
308 | } | |
309 | } | |
310 | ] | |
311 | } | |
312 | }); |