]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/lxc/CmdMenu.js
ui: lxc resources: support font awesome icons directly
[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 5 initComponent: function() {
23ebe427 6 let me = this;
b92ba0a7 7
23ebe427
TL
8 let info = me.pveSelNode.data;
9 if (!info.node) {
b92ba0a7
DM
10 throw "no node name specified";
11 }
23ebe427 12 if (!info.vmid) {
b92ba0a7
DM
13 throw "no CT ID specified";
14 }
b92ba0a7 15
23ebe427 16 let vm_command = function(cmd, params) {
e7ade592 17 Proxmox.Utils.API2Request({
b92ba0a7 18 params: params,
23ebe427 19 url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
b92ba0a7 20 method: 'POST',
23ebe427 21 failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
b92ba0a7
DM
22 });
23 };
b1b0fcbc
TL
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 };
b92ba0a7 32
23ebe427
TL
33 let caps = Ext.state.Manager.get('GuiCap');
34 let standalone = PVE.data.ResourceStore.getNodes().length < 2;
ce8dac51 35
23ebe427
TL
36 let running = false, stopped = true, suspended = false;
37 switch (info.status) {
ce8dac51
DC
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
23ebe427 49 me.title = 'CT ' + info.vmid;
b92ba0a7
DM
50
51 me.items = [
52 {
53 text: gettext('Start'),
d4333933 54 iconCls: 'fa fa-fw fa-play',
ce8dac51 55 disabled: running,
23ebe427 56 handler: () => vm_command('start'),
b92ba0a7 57 },
b92ba0a7
DM
58 {
59 text: gettext('Shutdown'),
d4333933 60 iconCls: 'fa fa-fw fa-power-off',
ce8dac51 61 disabled: stopped || suspended,
b1b0fcbc 62 handler: () => confirmedVMCommand('shutdown'),
b92ba0a7
DM
63 },
64 {
65 text: gettext('Stop'),
d4333933 66 iconCls: 'fa fa-fw fa-stop',
ce8dac51 67 disabled: stopped,
833b048f 68 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
b1b0fcbc 69 handler: () => confirmedVMCommand('stop'),
b92ba0a7 70 },
6aee12f1
OB
71 {
72 text: gettext('Reboot'),
73 iconCls: 'fa fa-fw fa-refresh',
74 disabled: stopped,
75 tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
b1b0fcbc 76 handler: () => confirmedVMCommand('reboot'),
6aee12f1 77 },
8ad34211
DC
78 {
79 xtype: 'menuseparator',
f6710aac 80 hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
8ad34211 81 },
9bad05bd
DC
82 {
83 text: gettext('Clone'),
84 iconCls: 'fa fa-fw fa-clone',
85 hidden: !caps.vms['VM.Clone'],
23ebe427 86 handler: () => PVE.window.Clone.wrap(info.node, info.vmid, me.isTemplate, 'lxc'),
9bad05bd 87 },
efbc9f5d
DC
88 {
89 text: gettext('Migrate'),
90 iconCls: 'fa fa-fw fa-send-o',
8ad34211 91 hidden: standalone || !caps.vms['VM.Migrate'],
efbc9f5d 92 handler: function() {
23ebe427 93 Ext.create('PVE.window.Migrate', {
efbc9f5d 94 vmtype: 'lxc',
23ebe427
TL
95 nodename: info.node,
96 vmid: info.vmid,
97 autoShow: true,
efbc9f5d 98 });
f6710aac 99 },
efbc9f5d 100 },
9bad05bd
DC
101 {
102 text: gettext('Convert to template'),
103 iconCls: 'fa fa-fw fa-file-o',
104 handler: function() {
23ebe427 105 let msg = Proxmox.Utils.format_task_description('vztemplate', info.vmid);
9bad05bd 106 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
23ebe427
TL
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 });
9bad05bd 113 }
9bad05bd 114 });
f6710aac 115 },
9bad05bd 116 },
22f2f9d6 117 { xtype: 'menuseparator' },
b92ba0a7
DM
118 {
119 text: gettext('Console'),
d4333933 120 iconCls: 'fa fa-fw fa-terminal',
23ebe427
TL
121 handler: () =>
122 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', info.vmid, info.node, info.vmname),
f6710aac 123 },
b92ba0a7
DM
124 ];
125
126 me.callParent();
f6710aac 127 },
b92ba0a7 128});