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