]>
Commit | Line | Data |
---|---|---|
6ae2ec81 DC |
1 | Ext.define('PVE.window.BulkAction', { |
2 | extend: 'Ext.window.Window', | |
3 | ||
4 | resizable: true, | |
5 | width: 800, | |
6 | modal: true, | |
7 | layout: { | |
f6710aac | 8 | type: 'fit', |
6ae2ec81 DC |
9 | }, |
10 | border: false, | |
11 | ||
12 | // the action to be set | |
13 | // currently there are | |
14 | // startall | |
15 | // migrateall | |
16 | // stopall | |
17 | action: undefined, | |
18 | ||
19 | submit: function(params) { | |
20 | var me = this; | |
3d625330 | 21 | |
e7ade592 | 22 | Proxmox.Utils.API2Request({ |
6ae2ec81 | 23 | params: params, |
6e5711db | 24 | url: '/nodes/' + me.nodename + '/' + me.action, |
6ae2ec81 DC |
25 | waitMsgTarget: me, |
26 | method: 'POST', | |
27 | failure: function(response, opts) { | |
28 | Ext.Msg.alert('Error', response.htmlStatus); | |
29 | }, | |
30 | success: function(response, options) { | |
31 | var upid = response.result.data; | |
32 | ||
8cbc11a7 | 33 | var win = Ext.create('Proxmox.window.TaskViewer', { |
f6710aac | 34 | upid: upid, |
6ae2ec81 DC |
35 | }); |
36 | win.show(); | |
37 | me.hide(); | |
38 | win.on('destroy', function() { | |
39 | me.close(); | |
40 | }); | |
f6710aac | 41 | }, |
6ae2ec81 DC |
42 | }); |
43 | }, | |
44 | ||
8058410f | 45 | initComponent: function() { |
6ae2ec81 DC |
46 | var me = this; |
47 | ||
48 | if (!me.nodename) { | |
49 | throw "no node name specified"; | |
50 | } | |
6ae2ec81 DC |
51 | if (!me.action) { |
52 | throw "no action specified"; | |
53 | } | |
6ae2ec81 DC |
54 | if (!me.btnText) { |
55 | throw "no button text specified"; | |
56 | } | |
6ae2ec81 DC |
57 | if (!me.title) { |
58 | throw "no title specified"; | |
59 | } | |
60 | ||
61 | var items = []; | |
62 | ||
63 | if (me.action === 'migrateall') { | |
21ef191b | 64 | /*value is string and number*/ |
6ae2ec81 DC |
65 | items.push( |
66 | { | |
67 | xtype: 'pveNodeSelector', | |
68 | name: 'target', | |
69 | disallowedNodes: [me.nodename], | |
09f5f402 | 70 | fieldLabel: gettext('Target node'), |
6ae2ec81 | 71 | allowBlank: false, |
f6710aac | 72 | onlineValidator: true, |
6ae2ec81 DC |
73 | }, |
74 | { | |
bf96f60d | 75 | xtype: 'proxmoxintegerfield', |
6ae2ec81 DC |
76 | name: 'maxworkers', |
77 | minValue: 1, | |
78 | maxValue: 100, | |
79 | value: 1, | |
09f5f402 | 80 | fieldLabel: gettext('Parallel jobs'), |
f6710aac | 81 | allowBlank: false, |
200a9b5d | 82 | }, |
3d625330 | 83 | { |
736cffb1 TL |
84 | xtype: 'fieldcontainer', |
85 | fieldLabel: gettext('Allow local disk migration'), | |
86 | layout: 'hbox', | |
87 | items: [{ | |
88 | xtype: 'proxmoxcheckbox', | |
89 | name: 'with-local-disks', | |
90 | checked: true, | |
91 | uncheckedValue: 0, | |
92 | listeners: { | |
93 | change: (cb, val) => me.down('#localdiskwarning').setVisible(val), | |
f6710aac | 94 | }, |
3d625330 | 95 | |
736cffb1 TL |
96 | }, |
97 | { | |
98 | itemId: 'localdiskwarning', | |
99 | xtype: 'displayfield', | |
100 | flex: 1, | |
101 | padding: '0 0 0 10', | |
102 | userCls: 'pmx-hint', | |
103 | value: 'Note: Migration with local disks might take long.', | |
104 | }], | |
3d625330 | 105 | }, |
200a9b5d OB |
106 | { |
107 | itemId: 'lxcwarning', | |
108 | xtype: 'displayfield', | |
f71b7c28 | 109 | userCls: 'pmx-hint', |
200a9b5d | 110 | value: 'Warning: Running CTs will be migrated in Restart Mode.', |
f6710aac TL |
111 | hidden: true, // only visible if running container chosen |
112 | }, | |
6ae2ec81 DC |
113 | ); |
114 | } else if (me.action === 'startall') { | |
115 | items.push({ | |
116 | xtype: 'hiddenfield', | |
117 | name: 'force', | |
f6710aac | 118 | value: 1, |
6ae2ec81 DC |
119 | }); |
120 | } | |
121 | ||
122 | items.push({ | |
123 | xtype: 'vmselector', | |
124 | itemId: 'vms', | |
125 | name: 'vms', | |
126 | flex: 1, | |
127 | height: 300, | |
128 | selectAll: true, | |
129 | allowBlank: false, | |
eb882c6f | 130 | nodename: me.nodename, |
200a9b5d OB |
131 | action: me.action, |
132 | listeners: { | |
133 | selectionchange: function(vmselector, records) { | |
f4eab70a TL |
134 | if (me.action === 'migrateall') { |
135 | let showWarning = records.some( | |
136 | item => item.data.type === 'lxc' && item.data.status === 'running', | |
137 | ); | |
e2c97a19 | 138 | me.down('#lxcwarning').setVisible(showWarning); |
200a9b5d | 139 | } |
f6710aac TL |
140 | }, |
141 | }, | |
6ae2ec81 DC |
142 | }); |
143 | ||
144 | me.formPanel = Ext.create('Ext.form.Panel', { | |
145 | bodyPadding: 10, | |
146 | border: false, | |
147 | layout: { | |
148 | type: 'vbox', | |
f6710aac | 149 | align: 'stretch', |
6ae2ec81 DC |
150 | }, |
151 | fieldDefaults: { | |
152 | labelWidth: 300, | |
f6710aac | 153 | anchor: '100%', |
6ae2ec81 | 154 | }, |
f6710aac | 155 | items: items, |
6ae2ec81 DC |
156 | }); |
157 | ||
158 | var form = me.formPanel.getForm(); | |
159 | ||
160 | var submitBtn = Ext.create('Ext.Button', { | |
161 | text: me.btnText, | |
162 | handler: function() { | |
163 | form.isValid(); | |
164 | me.submit(form.getValues()); | |
f6710aac | 165 | }, |
6ae2ec81 DC |
166 | }); |
167 | ||
168 | Ext.apply(me, { | |
8058410f TL |
169 | items: [me.formPanel], |
170 | buttons: [submitBtn], | |
6ae2ec81 DC |
171 | }); |
172 | ||
173 | me.callParent(); | |
174 | ||
175 | form.on('validitychange', function() { | |
176 | var valid = form.isValid(); | |
177 | submitBtn.setDisabled(!valid); | |
178 | }); | |
179 | form.isValid(); | |
f6710aac | 180 | }, |
6ae2ec81 | 181 | }); |