]>
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: { | |
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; | |
e7ade592 | 21 | Proxmox.Utils.API2Request({ |
6ae2ec81 | 22 | params: params, |
6e5711db | 23 | url: '/nodes/' + me.nodename + '/' + me.action, |
6ae2ec81 DC |
24 | waitMsgTarget: me, |
25 | method: 'POST', | |
26 | failure: function(response, opts) { | |
27 | Ext.Msg.alert('Error', response.htmlStatus); | |
28 | }, | |
29 | success: function(response, options) { | |
30 | var upid = response.result.data; | |
31 | ||
8cbc11a7 | 32 | var win = Ext.create('Proxmox.window.TaskViewer', { |
6ae2ec81 DC |
33 | upid: upid |
34 | }); | |
35 | win.show(); | |
36 | me.hide(); | |
37 | win.on('destroy', function() { | |
38 | me.close(); | |
39 | }); | |
40 | } | |
41 | }); | |
42 | }, | |
43 | ||
44 | initComponent : function() { | |
45 | var me = this; | |
46 | ||
47 | if (!me.nodename) { | |
48 | throw "no node name specified"; | |
49 | } | |
50 | ||
51 | if (!me.action) { | |
52 | throw "no action specified"; | |
53 | } | |
54 | ||
55 | if (!me.btnText) { | |
56 | throw "no button text specified"; | |
57 | } | |
58 | ||
59 | if (!me.title) { | |
60 | throw "no title specified"; | |
61 | } | |
62 | ||
63 | var items = []; | |
64 | ||
65 | if (me.action === 'migrateall') { | |
21ef191b DC |
66 | /*jslint confusion: true*/ |
67 | /*value is string and number*/ | |
6ae2ec81 DC |
68 | items.push( |
69 | { | |
70 | xtype: 'pveNodeSelector', | |
71 | name: 'target', | |
72 | disallowedNodes: [me.nodename], | |
09f5f402 | 73 | fieldLabel: gettext('Target node'), |
6ae2ec81 DC |
74 | allowBlank: false, |
75 | onlineValidator: true | |
76 | }, | |
77 | { | |
bf96f60d | 78 | xtype: 'proxmoxintegerfield', |
6ae2ec81 DC |
79 | name: 'maxworkers', |
80 | minValue: 1, | |
81 | maxValue: 100, | |
82 | value: 1, | |
09f5f402 | 83 | fieldLabel: gettext('Parallel jobs'), |
6ae2ec81 | 84 | allowBlank: false |
200a9b5d OB |
85 | }, |
86 | { | |
87 | itemId: 'lxcwarning', | |
88 | xtype: 'displayfield', | |
f71b7c28 | 89 | userCls: 'pmx-hint', |
200a9b5d OB |
90 | value: 'Warning: Running CTs will be migrated in Restart Mode.', |
91 | hidden: true // only visible if running container chosen | |
6ae2ec81 DC |
92 | } |
93 | ); | |
21ef191b | 94 | /*jslint confusion: false*/ |
6ae2ec81 DC |
95 | } else if (me.action === 'startall') { |
96 | items.push({ | |
97 | xtype: 'hiddenfield', | |
98 | name: 'force', | |
99 | value: 1 | |
100 | }); | |
101 | } | |
102 | ||
103 | items.push({ | |
104 | xtype: 'vmselector', | |
105 | itemId: 'vms', | |
106 | name: 'vms', | |
107 | flex: 1, | |
108 | height: 300, | |
109 | selectAll: true, | |
110 | allowBlank: false, | |
eb882c6f | 111 | nodename: me.nodename, |
200a9b5d OB |
112 | action: me.action, |
113 | listeners: { | |
114 | selectionchange: function(vmselector, records) { | |
115 | if (me.action == 'migrateall') { | |
21ef191b | 116 | var showWarning = records.some(function(item) { |
200a9b5d OB |
117 | return (item.data.type == 'lxc' && |
118 | item.data.status == 'running'); | |
119 | }); | |
e2c97a19 | 120 | me.down('#lxcwarning').setVisible(showWarning); |
200a9b5d OB |
121 | } |
122 | } | |
123 | } | |
6ae2ec81 DC |
124 | }); |
125 | ||
126 | me.formPanel = Ext.create('Ext.form.Panel', { | |
127 | bodyPadding: 10, | |
128 | border: false, | |
129 | layout: { | |
130 | type: 'vbox', | |
131 | align: 'stretch' | |
132 | }, | |
133 | fieldDefaults: { | |
134 | labelWidth: 300, | |
135 | anchor: '100%' | |
136 | }, | |
137 | items: items | |
138 | }); | |
139 | ||
140 | var form = me.formPanel.getForm(); | |
141 | ||
142 | var submitBtn = Ext.create('Ext.Button', { | |
143 | text: me.btnText, | |
144 | handler: function() { | |
145 | form.isValid(); | |
146 | me.submit(form.getValues()); | |
147 | } | |
148 | }); | |
149 | ||
150 | Ext.apply(me, { | |
151 | items: [ me.formPanel ], | |
152 | buttons: [ submitBtn ] | |
153 | }); | |
154 | ||
155 | me.callParent(); | |
156 | ||
157 | form.on('validitychange', function() { | |
158 | var valid = form.isValid(); | |
159 | submitBtn.setDisabled(!valid); | |
160 | }); | |
161 | form.isValid(); | |
162 | } | |
163 | }); |