]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/lxc/CmdMenu.js
lxc: refactor stop button
[pve-manager.git] / www / manager6 / lxc / CmdMenu.js
CommitLineData
b92ba0a7
DM
1Ext.define('PVE.lxc.CmdMenu', {
2 extend: 'Ext.menu.Menu',
3
efbc9f5d 4 showSeparator: false,
b92ba0a7
DM
5 initComponent: function() {
6 var me = this;
7
8 var nodename = me.pveSelNode.data.node;
9 if (!nodename) {
10 throw "no node name specified";
11 }
12
13 var vmid = me.pveSelNode.data.vmid;
14 if (!vmid) {
15 throw "no CT ID specified";
16 }
b92ba0a7
DM
17 var vmname = me.pveSelNode.data.name;
18
19 var vm_command = function(cmd, params) {
e7ade592 20 Proxmox.Utils.API2Request({
b92ba0a7
DM
21 params: params,
22 url: '/nodes/' + nodename + '/lxc/' + vmid + "/status/" + cmd,
23 method: 'POST',
24 failure: function(response, opts) {
25 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
26 }
27 });
28 };
29
8ad34211
DC
30 var caps = Ext.state.Manager.get('GuiCap');
31
ce8dac51
DC
32 var running = false;
33 var stopped = true;
34 var suspended = false;
8ad34211 35 var standalone = PVE.data.ResourceStore.getNodes().length < 2;
ce8dac51
DC
36
37 switch (me.pveSelNode.data.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
d59ed79b 49 me.title = 'CT ' + vmid;
b92ba0a7
DM
50
51 me.items = [
52 {
53 text: gettext('Start'),
d4333933 54 iconCls: 'fa fa-fw fa-play',
ce8dac51 55 disabled: running,
b92ba0a7
DM
56 handler: function() {
57 vm_command('start');
58 }
59 },
1b711780
DC
60// {
61// text: gettext('Suspend'),
62// iconCls: 'fa fa-fw fa-pause',
efbc9f5d 63// hidde: suspended,
1b711780
DC
64// disabled: stopped || suspended,
65// handler: function() {
e7ade592 66// var msg = Proxmox.Utils.format_task_description('vzsuspend', vmid);
1b711780
DC
67// Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
68// if (btn !== 'yes') {
69// return;
70// }
71//
72// vm_command('suspend');
73// });
74// }
75// },
76// {
77// text: gettext('Resume'),
78// iconCls: 'fa fa-fw fa-play',
efbc9f5d 79// hidden: !suspended,
1b711780
DC
80// handler: function() {
81// vm_command('resume');
82// }
83// },
b92ba0a7
DM
84 {
85 text: gettext('Shutdown'),
d4333933 86 iconCls: 'fa fa-fw fa-power-off',
ce8dac51 87 disabled: stopped || suspended,
b92ba0a7 88 handler: function() {
e7ade592 89 var msg = Proxmox.Utils.format_task_description('vzshutdown', vmid);
b92ba0a7
DM
90 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
91 if (btn !== 'yes') {
92 return;
93 }
94
95 vm_command('shutdown');
96 });
9bd6cd80 97 }
b92ba0a7
DM
98 },
99 {
100 text: gettext('Stop'),
d4333933 101 iconCls: 'fa fa-fw fa-stop',
ce8dac51 102 disabled: stopped,
833b048f 103 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
b92ba0a7 104 handler: function() {
e7ade592 105 var msg = Proxmox.Utils.format_task_description('vzstop', vmid);
b92ba0a7
DM
106 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
107 if (btn !== 'yes') {
108 return;
109 }
110
111 vm_command("stop");
112 });
113 }
114 },
8ad34211
DC
115 {
116 xtype: 'menuseparator',
117 hidden: standalone || !caps.vms['VM.Migrate']
118 },
9bad05bd
DC
119 {
120 text: gettext('Clone'),
121 iconCls: 'fa fa-fw fa-clone',
122 hidden: !caps.vms['VM.Clone'],
123 handler: function() {
124 PVE.window.Clone.wrap(nodename, vmid, me.isTemplate, 'lxc');
125 }
126 },
efbc9f5d
DC
127 {
128 text: gettext('Migrate'),
129 iconCls: 'fa fa-fw fa-send-o',
8ad34211 130 hidden: standalone || !caps.vms['VM.Migrate'],
efbc9f5d
DC
131 handler: function() {
132 var win = Ext.create('PVE.window.Migrate', {
133 vmtype: 'lxc',
134 nodename: nodename,
135 vmid: vmid
136 });
137 win.show();
138 }
139 },
9bad05bd
DC
140 {
141 text: gettext('Convert to template'),
142 iconCls: 'fa fa-fw fa-file-o',
143 handler: function() {
144 var msg = Proxmox.Utils.format_task_description('vztemplate', vmid);
145 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
146 if (btn !== 'yes') {
147 return;
148 }
149
150 Proxmox.Utils.API2Request({
151 url: '/nodes/' + nodename + '/lxc/' + vmid + '/template',
152 method: 'POST',
153 failure: function(response, opts) {
154 Ext.Msg.alert('Error', response.htmlStatus);
155 }
156 });
157 });
158 }
159 },
22f2f9d6 160 { xtype: 'menuseparator' },
b92ba0a7
DM
161 {
162 text: gettext('Console'),
d4333933 163 iconCls: 'fa fa-fw fa-terminal',
b92ba0a7
DM
164 handler: function() {
165 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
166 }
167 }
168 ];
169
170 me.callParent();
171 }
172});