]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
ui: followup: minor code cleanup
[pve-manager.git] / www / manager6 / lxc / Config.js
1 Ext.define('PVE.lxc.Config', {
2 extend: 'PVE.panel.Config',
3 alias: 'widget.PVE.lxc.Config',
4
5 onlineHelp: 'chapter_pct',
6
7 initComponent: function() {
8 var me = this;
9
10 var nodename = me.pveSelNode.data.node;
11 if (!nodename) {
12 throw "no node name specified";
13 }
14
15 var vmid = me.pveSelNode.data.vmid;
16 if (!vmid) {
17 throw "no VM ID specified";
18 }
19
20 var template = !!me.pveSelNode.data.template;
21
22 var running = !!me.pveSelNode.data.uptime;
23
24 var caps = Ext.state.Manager.get('GuiCap');
25
26 var base_url = '/nodes/' + nodename + '/lxc/' + vmid;
27
28 me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
29 url: '/api2/json' + base_url + '/status/current',
30 interval: 1000
31 });
32
33 var vm_command = function(cmd, params) {
34 Proxmox.Utils.API2Request({
35 params: params,
36 url: base_url + "/status/" + cmd,
37 waitMsgTarget: me,
38 method: 'POST',
39 failure: function(response, opts) {
40 Ext.Msg.alert('Error', response.htmlStatus);
41 }
42 });
43 };
44
45 var startBtn = Ext.create('Ext.Button', {
46 text: gettext('Start'),
47 disabled: !caps.vms['VM.PowerMgmt'] || running,
48 hidden: template,
49 handler: function() {
50 vm_command('start');
51 },
52 iconCls: 'fa fa-play'
53 });
54
55 var stopBtn = Ext.create('Ext.menu.Item',{
56 text: gettext('Stop'),
57 disabled: !caps.vms['VM.PowerMgmt'],
58 confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid),
59 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
60 dangerous: true,
61 handler: function() {
62 vm_command("stop");
63 },
64 iconCls: 'fa fa-stop'
65 });
66
67 var shutdownBtn = Ext.create('PVE.button.Split', {
68 text: gettext('Shutdown'),
69 disabled: !caps.vms['VM.PowerMgmt'] || !running,
70 hidden: template,
71 confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
72 handler: function() {
73 vm_command('shutdown');
74 },
75 menu: {
76 items:[stopBtn]
77 },
78 iconCls: 'fa fa-power-off'
79 });
80
81 var migrateBtn = Ext.create('Ext.Button', {
82 text: gettext('Migrate'),
83 disabled: !caps.vms['VM.Migrate'],
84 hidden: PVE.data.ResourceStore.getNodes().length < 2,
85 handler: function() {
86 var win = Ext.create('PVE.window.Migrate', {
87 vmtype: 'lxc',
88 nodename: nodename,
89 vmid: vmid
90 });
91 win.show();
92 },
93 iconCls: 'fa fa-send-o'
94 });
95
96 var moreBtn = Ext.create('Proxmox.button.Button', {
97 text: gettext('More'),
98 menu: { items: [
99 {
100 text: gettext('Clone'),
101 iconCls: 'fa fa-fw fa-clone',
102 hidden: caps.vms['VM.Clone'] ? false : true,
103 handler: function() {
104 PVE.window.Clone.wrap(nodename, vmid, template, 'lxc');
105 }
106 },
107 {
108 text: gettext('Convert to template'),
109 disabled: template,
110 xtype: 'pveMenuItem',
111 iconCls: 'fa fa-fw fa-file-o',
112 hidden: caps.vms['VM.Allocate'] ? false : true,
113 confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
114 handler: function() {
115 Proxmox.Utils.API2Request({
116 url: base_url + '/template',
117 waitMsgTarget: me,
118 method: 'POST',
119 failure: function(response, opts) {
120 Ext.Msg.alert('Error', response.htmlStatus);
121 }
122 });
123 }
124 },
125 {
126 iconCls: 'fa fa-heartbeat ',
127 hidden: !caps.nodes['Sys.Console'],
128 text: gettext('Manage HA'),
129 handler: function() {
130 var ha = me.pveSelNode.data.hastate;
131 Ext.create('PVE.ha.VMResourceEdit', {
132 vmid: vmid,
133 guestType: 'ct',
134 isCreate: (!ha || ha === 'unmanaged')
135 }).show();
136 }
137 },
138 {
139 text: gettext('Remove'),
140 disabled: !caps.vms['VM.Allocate'],
141 itemId: 'removeBtn',
142 handler: function() {
143 Ext.create('PVE.window.SafeDestroy', {
144 url: base_url,
145 item: { type: 'CT', id: vmid }
146 }).show();
147 },
148 iconCls: 'fa fa-trash-o'
149 }
150 ]}
151 });
152
153 var vm = me.pveSelNode.data;
154
155 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
156 disabled: !caps.vms['VM.Console'],
157 consoleType: 'lxc',
158 consoleName: vm.name,
159 hidden: template,
160 nodename: nodename,
161 vmid: vmid
162 });
163
164 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
165 data: {
166 lock: undefined
167 },
168 tpl: [
169 '<tpl if="lock">',
170 '<i class="fa fa-lg fa-lock"></i> ({lock})',
171 '</tpl>'
172 ]
173 });
174
175
176 Ext.apply(me, {
177 title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
178 hstateid: 'lxctab',
179 tbarSpacing: false,
180 tbar: [ statusTxt, '->', startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
181 defaults: { statusStore: me.statusStore },
182 items: [
183 {
184 title: gettext('Summary'),
185 xtype: 'pveLxcSummary',
186 iconCls: 'fa fa-book',
187 itemId: 'summary'
188 }
189 ]
190 });
191
192 if (caps.vms['VM.Console'] && !template) {
193 me.items.push(
194 {
195 title: gettext('Console'),
196 itemId: 'consolejs',
197 iconCls: 'fa fa-terminal',
198 xtype: 'pveNoVncConsole',
199 vmid: vmid,
200 consoleType: 'lxc',
201 xtermjs: true,
202 nodename: nodename
203 }
204 );
205 }
206
207 me.items.push(
208 {
209 title: gettext('Resources'),
210 itemId: 'resources',
211 expandedOnInit: true,
212 iconCls: 'fa fa-cube',
213 xtype: 'pveLxcRessourceView'
214 },
215 {
216 title: gettext('Network'),
217 iconCls: 'fa fa-exchange',
218 itemId: 'network',
219 xtype: 'pveLxcNetworkView'
220 },
221 {
222 title: gettext('DNS'),
223 iconCls: 'fa fa-globe',
224 itemId: 'dns',
225 xtype: 'pveLxcDNS'
226 },
227 {
228 title: gettext('Options'),
229 itemId: 'options',
230 iconCls: 'fa fa-gear',
231 xtype: 'pveLxcOptions'
232 },
233 {
234 title: gettext('Task History'),
235 itemId: 'tasks',
236 iconCls: 'fa fa-list',
237 xtype: 'proxmoxNodeTasks',
238 nodename: nodename,
239 vmidFilter: vmid
240 }
241 );
242
243 if (caps.vms['VM.Backup']) {
244 me.items.push({
245 title: gettext('Backup'),
246 iconCls: 'fa fa-floppy-o',
247 xtype: 'pveBackupView',
248 itemId: 'backup'
249 },
250 {
251 title: gettext('Replication'),
252 iconCls: 'fa fa-retweet',
253 xtype: 'pveReplicaView',
254 itemId: 'replication'
255 });
256 }
257
258 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
259 me.items.push({
260 title: gettext('Snapshots'),
261 iconCls: 'fa fa-history',
262 xtype: 'pveLxcSnapshotTree',
263 itemId: 'snapshot'
264 });
265 }
266
267 if (caps.vms['VM.Console']) {
268 me.items.push(
269 {
270 xtype: 'pveFirewallRules',
271 title: gettext('Firewall'),
272 iconCls: 'fa fa-shield',
273 allow_iface: true,
274 base_url: base_url + '/firewall/rules',
275 list_refs_url: base_url + '/firewall/refs',
276 itemId: 'firewall'
277 },
278 {
279 xtype: 'pveFirewallOptions',
280 groups: ['firewall'],
281 iconCls: 'fa fa-gear',
282 onlineHelp: 'pve_firewall_vm_container_configuration',
283 title: gettext('Options'),
284 base_url: base_url + '/firewall/options',
285 fwtype: 'vm',
286 itemId: 'firewall-options'
287 },
288 {
289 xtype: 'pveFirewallAliases',
290 title: gettext('Alias'),
291 groups: ['firewall'],
292 iconCls: 'fa fa-external-link',
293 base_url: base_url + '/firewall/aliases',
294 itemId: 'firewall-aliases'
295 },
296 {
297 xtype: 'pveIPSet',
298 title: gettext('IPSet'),
299 groups: ['firewall'],
300 iconCls: 'fa fa-list-ol',
301 base_url: base_url + '/firewall/ipset',
302 list_refs_url: base_url + '/firewall/refs',
303 itemId: 'firewall-ipset'
304 },
305 {
306 title: gettext('Log'),
307 groups: ['firewall'],
308 iconCls: 'fa fa-list',
309 onlineHelp: 'chapter_pve_firewall',
310 itemId: 'firewall-fwlog',
311 xtype: 'proxmoxLogView',
312 url: '/api2/extjs' + base_url + '/firewall/log'
313 }
314 );
315 }
316
317 if (caps.vms['Permissions.Modify']) {
318 me.items.push({
319 xtype: 'pveACLView',
320 title: gettext('Permissions'),
321 itemId: 'permissions',
322 iconCls: 'fa fa-unlock',
323 path: '/vms/' + vmid
324 });
325 }
326
327 me.callParent();
328
329 me.mon(me.statusStore, 'load', function(s, records, success) {
330 var status;
331 var lock;
332 if (!success) {
333 status = 'unknown';
334 } else {
335 var rec = s.data.get('status');
336 status = rec ? rec.data.value : 'unknown';
337 rec = s.data.get('template');
338 template = rec.data.value || false;
339 rec = s.data.get('lock');
340 lock = rec ? rec.data.value : undefined;
341 }
342
343 statusTxt.update({ lock: lock });
344
345 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
346 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
347 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
348 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
349 consoleBtn.setDisabled(template);
350 });
351
352 me.on('afterrender', function() {
353 me.statusStore.startUpdate();
354 });
355
356 me.on('destroy', function() {
357 me.statusStore.stopUpdate();
358 });
359 }
360 });