]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/lxc/CmdMenu.js
ui: eslint: fix trailing comma and comma related whitespaces errors
[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);
f6710aac 26 },
b92ba0a7
DM
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');
f6710aac 58 },
b92ba0a7 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 });
f6710aac 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 });
f6710aac 113 },
b92ba0a7 114 },
6aee12f1
OB
115 {
116 text: gettext('Reboot'),
117 iconCls: 'fa fa-fw fa-refresh',
118 disabled: stopped,
119 tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
120 handler: function() {
121 var msg = Proxmox.Utils.format_task_description('vzreboot', vmid);
122 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
123 if (btn !== 'yes') {
124 return;
125 }
126
127 vm_command("reboot");
128 });
f6710aac 129 },
6aee12f1 130 },
8ad34211
DC
131 {
132 xtype: 'menuseparator',
f6710aac 133 hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
8ad34211 134 },
9bad05bd
DC
135 {
136 text: gettext('Clone'),
137 iconCls: 'fa fa-fw fa-clone',
138 hidden: !caps.vms['VM.Clone'],
139 handler: function() {
140 PVE.window.Clone.wrap(nodename, vmid, me.isTemplate, 'lxc');
f6710aac 141 },
9bad05bd 142 },
efbc9f5d
DC
143 {
144 text: gettext('Migrate'),
145 iconCls: 'fa fa-fw fa-send-o',
8ad34211 146 hidden: standalone || !caps.vms['VM.Migrate'],
efbc9f5d
DC
147 handler: function() {
148 var win = Ext.create('PVE.window.Migrate', {
149 vmtype: 'lxc',
150 nodename: nodename,
f6710aac 151 vmid: vmid,
efbc9f5d
DC
152 });
153 win.show();
f6710aac 154 },
efbc9f5d 155 },
9bad05bd
DC
156 {
157 text: gettext('Convert to template'),
158 iconCls: 'fa fa-fw fa-file-o',
159 handler: function() {
160 var msg = Proxmox.Utils.format_task_description('vztemplate', vmid);
161 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
162 if (btn !== 'yes') {
163 return;
164 }
165
166 Proxmox.Utils.API2Request({
167 url: '/nodes/' + nodename + '/lxc/' + vmid + '/template',
168 method: 'POST',
169 failure: function(response, opts) {
170 Ext.Msg.alert('Error', response.htmlStatus);
f6710aac 171 },
9bad05bd
DC
172 });
173 });
f6710aac 174 },
9bad05bd 175 },
22f2f9d6 176 { xtype: 'menuseparator' },
b92ba0a7
DM
177 {
178 text: gettext('Console'),
d4333933 179 iconCls: 'fa fa-fw fa-terminal',
b92ba0a7
DM
180 handler: function() {
181 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
f6710aac
TL
182 },
183 },
b92ba0a7
DM
184 ];
185
186 me.callParent();
f6710aac 187 },
b92ba0a7 188});