]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/window/BulkAction.js
ui: LXC template upload: allow zstd compressed (.tar.zst) images
[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 be set
13 // currently there are
14 // startall
15 // migrateall
16 // stopall
17 action: undefined,
18
19 submit: function(params) {
20 var me = this;
21
22 Proxmox.Utils.API2Request({
23 params: params,
24 url: '/nodes/' + me.nodename + '/' + me.action,
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
33 var win = Ext.create('Proxmox.window.TaskViewer', {
34 upid: upid,
35 });
36 win.show();
37 me.hide();
38 win.on('destroy', function() {
39 me.close();
40 });
41 },
42 });
43 },
44
45 initComponent: function() {
46 var me = this;
47
48 if (!me.nodename) {
49 throw "no node name specified";
50 }
51 if (!me.action) {
52 throw "no action specified";
53 }
54 if (!me.btnText) {
55 throw "no button text specified";
56 }
57 if (!me.title) {
58 throw "no title specified";
59 }
60
61 var items = [];
62
63 if (me.action === 'migrateall') {
64 /*value is string and number*/
65 items.push(
66 {
67 xtype: 'pveNodeSelector',
68 name: 'target',
69 disallowedNodes: [me.nodename],
70 fieldLabel: gettext('Target node'),
71 allowBlank: false,
72 onlineValidator: true,
73 },
74 {
75 xtype: 'proxmoxintegerfield',
76 name: 'maxworkers',
77 minValue: 1,
78 maxValue: 100,
79 value: 1,
80 fieldLabel: gettext('Parallel jobs'),
81 allowBlank: false,
82 },
83 {
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),
94 },
95
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 }],
105 },
106 {
107 itemId: 'lxcwarning',
108 xtype: 'displayfield',
109 userCls: 'pmx-hint',
110 value: 'Warning: Running CTs will be migrated in Restart Mode.',
111 hidden: true, // only visible if running container chosen
112 },
113 );
114 } else if (me.action === 'startall') {
115 items.push({
116 xtype: 'hiddenfield',
117 name: 'force',
118 value: 1,
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,
130 nodename: me.nodename,
131 action: me.action,
132 listeners: {
133 selectionchange: function(vmselector, records) {
134 if (me.action === 'migrateall') {
135 let showWarning = records.some(
136 item => item.data.type === 'lxc' && item.data.status === 'running',
137 );
138 me.down('#lxcwarning').setVisible(showWarning);
139 }
140 },
141 },
142 });
143
144 me.formPanel = Ext.create('Ext.form.Panel', {
145 bodyPadding: 10,
146 border: false,
147 layout: {
148 type: 'vbox',
149 align: 'stretch',
150 },
151 fieldDefaults: {
152 labelWidth: 300,
153 anchor: '100%',
154 },
155 items: items,
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());
165 },
166 });
167
168 Ext.apply(me, {
169 items: [me.formPanel],
170 buttons: [submitBtn],
171 });
172
173 me.callParent();
174
175 form.on('validitychange', function() {
176 var valid = form.isValid();
177 submitBtn.setDisabled(!valid);
178 });
179 form.isValid();
180 },
181 });