]>
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; | |
21 | PVE.Utils.API2Request({ | |
22 | params: params, | |
23 | url: '/nodes/' + me.nodename + '/' + "/" + me.action, | |
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 | ||
32 | var win = Ext.create('PVE.window.TaskViewer', { | |
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') { | |
66 | items.push( | |
67 | { | |
68 | xtype: 'pveNodeSelector', | |
69 | name: 'target', | |
70 | disallowedNodes: [me.nodename], | |
09f5f402 | 71 | fieldLabel: gettext('Target node'), |
6ae2ec81 DC |
72 | allowBlank: false, |
73 | onlineValidator: true | |
74 | }, | |
75 | { | |
76 | xtype: 'pveIntegerField', | |
77 | name: 'maxworkers', | |
78 | minValue: 1, | |
79 | maxValue: 100, | |
80 | value: 1, | |
09f5f402 | 81 | fieldLabel: gettext('Parallel jobs'), |
6ae2ec81 DC |
82 | allowBlank: false |
83 | } | |
84 | ); | |
85 | } else if (me.action === 'startall') { | |
86 | items.push({ | |
87 | xtype: 'hiddenfield', | |
88 | name: 'force', | |
89 | value: 1 | |
90 | }); | |
91 | } | |
92 | ||
93 | items.push({ | |
94 | xtype: 'vmselector', | |
95 | itemId: 'vms', | |
96 | name: 'vms', | |
97 | flex: 1, | |
98 | height: 300, | |
99 | selectAll: true, | |
100 | allowBlank: false, | |
eb882c6f DC |
101 | nodename: me.nodename, |
102 | action: me.action | |
6ae2ec81 DC |
103 | }); |
104 | ||
105 | me.formPanel = Ext.create('Ext.form.Panel', { | |
106 | bodyPadding: 10, | |
107 | border: false, | |
108 | layout: { | |
109 | type: 'vbox', | |
110 | align: 'stretch' | |
111 | }, | |
112 | fieldDefaults: { | |
113 | labelWidth: 300, | |
114 | anchor: '100%' | |
115 | }, | |
116 | items: items | |
117 | }); | |
118 | ||
119 | var form = me.formPanel.getForm(); | |
120 | ||
121 | var submitBtn = Ext.create('Ext.Button', { | |
122 | text: me.btnText, | |
123 | handler: function() { | |
124 | form.isValid(); | |
125 | me.submit(form.getValues()); | |
126 | } | |
127 | }); | |
128 | ||
129 | Ext.apply(me, { | |
130 | items: [ me.formPanel ], | |
131 | buttons: [ submitBtn ] | |
132 | }); | |
133 | ||
134 | me.callParent(); | |
135 | ||
136 | form.on('validitychange', function() { | |
137 | var valid = form.isValid(); | |
138 | submitBtn.setDisabled(!valid); | |
139 | }); | |
140 | form.isValid(); | |
141 | } | |
142 | }); |