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