]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/CmdMenu.js
make contextmenus status-sensitive
[pve-manager.git] / www / manager6 / lxc / CmdMenu.js
1 Ext.define('PVE.lxc.CmdMenu', {
2 extend: 'Ext.menu.Menu',
3
4 initComponent: function() {
5 var me = this;
6
7 var nodename = me.pveSelNode.data.node;
8 if (!nodename) {
9 throw "no node name specified";
10 }
11
12 var vmid = me.pveSelNode.data.vmid;
13 if (!vmid) {
14 throw "no CT ID specified";
15 }
16
17 var vmname = me.pveSelNode.data.name;
18
19 var vm_command = function(cmd, params) {
20 PVE.Utils.API2Request({
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
30 var running = false;
31 var stopped = true;
32 var suspended = false;
33
34 switch (me.pveSelNode.data.status) {
35 case 'running':
36 running = true;
37 stopped = false;
38 break;
39 case 'paused':
40 stopped = false;
41 suspended = true;
42 break;
43 default: break;
44 }
45
46 me.title = 'CT ' + vmid;
47
48 me.items = [
49 {
50 text: gettext('Start'),
51 iconCls: 'fa fa-fw fa-play',
52 disabled: running,
53 handler: function() {
54 vm_command('start');
55 }
56 },
57 {
58 text: gettext('Migrate'),
59 iconCls: 'fa fa-fw fa-send-o',
60 handler: function() {
61 var win = Ext.create('PVE.window.Migrate', {
62 vmtype: 'lxc',
63 nodename: nodename,
64 vmid: vmid
65 });
66 win.show();
67 }
68 },
69 {
70 text: gettext('Suspend'),
71 iconCls: 'fa fa-fw fa-pause',
72 disabled: stopped || suspended,
73 handler: function() {
74 var msg = PVE.Utils.format_task_description('vzsuspend', vmid);
75 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
76 if (btn !== 'yes') {
77 return;
78 }
79
80 vm_command('suspend');
81 });
82 }
83 },
84 {
85 text: gettext('Resume'),
86 iconCls: 'fa fa-fw fa-play',
87 disabled: !suspended,
88 handler: function() {
89 vm_command('resume');
90 }
91 },
92 {
93 text: gettext('Shutdown'),
94 iconCls: 'fa fa-fw fa-power-off',
95 disabled: stopped || suspended,
96 handler: function() {
97 var msg = PVE.Utils.format_task_description('vzshutdown', vmid);
98 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
99 if (btn !== 'yes') {
100 return;
101 }
102
103 vm_command('shutdown');
104 });
105 }
106 },
107 {
108 text: gettext('Stop'),
109 iconCls: 'fa fa-fw fa-stop',
110 disabled: stopped,
111 handler: function() {
112 var msg = PVE.Utils.format_task_description('vzstop', vmid);
113 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
114 if (btn !== 'yes') {
115 return;
116 }
117
118 vm_command("stop");
119 });
120 }
121 },
122 // {
123 // text: gettext('Convert to template'),
124 // icon: '/pve2/images/forward.png',
125 // handler: function() {
126 // var msg = PVE.Utils.format_task_description('vztemplate', vmid);
127 // Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
128 // if (btn !== 'yes') {
129 // return;
130 // }
131 //
132 // PVE.Utils.API2Request({
133 // url: '/nodes/' + nodename + '/lxc/' + vmid + '/template',
134 // method: 'POST',
135 // failure: function(response, opts) {
136 // Ext.Msg.alert('Error', response.htmlStatus);
137 // }
138 // });
139 // });
140 // }
141 // },
142 {
143 text: gettext('Console'),
144 iconCls: 'fa fa-fw fa-terminal',
145 handler: function() {
146 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
147 }
148 }
149 ];
150
151 me.callParent();
152 }
153 });