]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/CmdMenu.js
ui: lxc/context cmd: factor out confirmed CT command
[pve-manager.git] / www / manager6 / lxc / CmdMenu.js
1 Ext.define('PVE.lxc.CmdMenu', {
2 extend: 'Ext.menu.Menu',
3
4 showSeparator: false,
5 initComponent: function() {
6 let me = this;
7
8 let info = me.pveSelNode.data;
9 if (!info.node) {
10 throw "no node name specified";
11 }
12 if (!info.vmid) {
13 throw "no CT ID specified";
14 }
15
16 let vm_command = function(cmd, params) {
17 Proxmox.Utils.API2Request({
18 params: params,
19 url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
20 method: 'POST',
21 failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
22 });
23 };
24 let confirmedVMCommand = (cmd, params) => {
25 let msg = Proxmox.Utils.format_task_description(`vz${cmd}`, info.vmid);
26 Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
27 if (btn === 'yes') {
28 vm_command(cmd, params);
29 }
30 });
31 };
32
33 let caps = Ext.state.Manager.get('GuiCap');
34 let standalone = PVE.data.ResourceStore.getNodes().length < 2;
35
36 let running = false, stopped = true, suspended = false;
37 switch (info.status) {
38 case 'running':
39 running = true;
40 stopped = false;
41 break;
42 case 'paused':
43 stopped = false;
44 suspended = true;
45 break;
46 default: break;
47 }
48
49 me.title = 'CT ' + info.vmid;
50
51 me.items = [
52 {
53 text: gettext('Start'),
54 iconCls: 'fa fa-fw fa-play',
55 disabled: running,
56 handler: () => vm_command('start'),
57 },
58 {
59 text: gettext('Shutdown'),
60 iconCls: 'fa fa-fw fa-power-off',
61 disabled: stopped || suspended,
62 handler: () => confirmedVMCommand('shutdown'),
63 },
64 {
65 text: gettext('Stop'),
66 iconCls: 'fa fa-fw fa-stop',
67 disabled: stopped,
68 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
69 handler: () => confirmedVMCommand('stop'),
70 },
71 {
72 text: gettext('Reboot'),
73 iconCls: 'fa fa-fw fa-refresh',
74 disabled: stopped,
75 tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
76 handler: () => confirmedVMCommand('reboot'),
77 },
78 {
79 xtype: 'menuseparator',
80 hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
81 },
82 {
83 text: gettext('Clone'),
84 iconCls: 'fa fa-fw fa-clone',
85 hidden: !caps.vms['VM.Clone'],
86 handler: () => PVE.window.Clone.wrap(info.node, info.vmid, me.isTemplate, 'lxc'),
87 },
88 {
89 text: gettext('Migrate'),
90 iconCls: 'fa fa-fw fa-send-o',
91 hidden: standalone || !caps.vms['VM.Migrate'],
92 handler: function() {
93 Ext.create('PVE.window.Migrate', {
94 vmtype: 'lxc',
95 nodename: info.node,
96 vmid: info.vmid,
97 autoShow: true,
98 });
99 },
100 },
101 {
102 text: gettext('Convert to template'),
103 iconCls: 'fa fa-fw fa-file-o',
104 handler: function() {
105 let msg = Proxmox.Utils.format_task_description('vztemplate', info.vmid);
106 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
107 if (btn === 'yes') {
108 Proxmox.Utils.API2Request({
109 url: `/nodes/${info.node}/lxc/${info.vmid}/template`,
110 method: 'POST',
111 failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
112 });
113 }
114 });
115 },
116 },
117 { xtype: 'menuseparator' },
118 {
119 text: gettext('Console'),
120 iconCls: 'fa fa-fw fa-terminal',
121 handler: () =>
122 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', info.vmid, info.node, info.vmname),
123 },
124 ];
125
126 me.callParent();
127 },
128 });