mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-07-27 03:55:33 +00:00
ui: lxc/context cmd: code cleanup/refactoring/modernize
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
bdc157f8f4
commit
23ebe427ec
@ -3,38 +3,30 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
|
|
||||||
showSeparator: false,
|
showSeparator: false,
|
||||||
initComponent: function() {
|
initComponent: function() {
|
||||||
var me = this;
|
let me = this;
|
||||||
|
|
||||||
var nodename = me.pveSelNode.data.node;
|
let info = me.pveSelNode.data;
|
||||||
if (!nodename) {
|
if (!info.node) {
|
||||||
throw "no node name specified";
|
throw "no node name specified";
|
||||||
}
|
}
|
||||||
|
if (!info.vmid) {
|
||||||
var vmid = me.pveSelNode.data.vmid;
|
|
||||||
if (!vmid) {
|
|
||||||
throw "no CT ID specified";
|
throw "no CT ID specified";
|
||||||
}
|
}
|
||||||
var vmname = me.pveSelNode.data.name;
|
|
||||||
|
|
||||||
var vm_command = function(cmd, params) {
|
let vm_command = function(cmd, params) {
|
||||||
Proxmox.Utils.API2Request({
|
Proxmox.Utils.API2Request({
|
||||||
params: params,
|
params: params,
|
||||||
url: '/nodes/' + nodename + '/lxc/' + vmid + "/status/" + cmd,
|
url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
failure: function(response, opts) {
|
failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
|
||||||
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var caps = Ext.state.Manager.get('GuiCap');
|
let caps = Ext.state.Manager.get('GuiCap');
|
||||||
|
let standalone = PVE.data.ResourceStore.getNodes().length < 2;
|
||||||
|
|
||||||
var running = false;
|
let running = false, stopped = true, suspended = false;
|
||||||
var stopped = true;
|
switch (info.status) {
|
||||||
var suspended = false;
|
|
||||||
var standalone = PVE.data.ResourceStore.getNodes().length < 2;
|
|
||||||
|
|
||||||
switch (me.pveSelNode.data.status) {
|
|
||||||
case 'running':
|
case 'running':
|
||||||
running = true;
|
running = true;
|
||||||
stopped = false;
|
stopped = false;
|
||||||
@ -46,47 +38,21 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.title = 'CT ' + vmid;
|
me.title = 'CT ' + info.vmid;
|
||||||
|
|
||||||
me.items = [
|
me.items = [
|
||||||
{
|
{
|
||||||
text: gettext('Start'),
|
text: gettext('Start'),
|
||||||
iconCls: 'fa fa-fw fa-play',
|
iconCls: 'fa fa-fw fa-play',
|
||||||
disabled: running,
|
disabled: running,
|
||||||
handler: function() {
|
handler: () => vm_command('start'),
|
||||||
vm_command('start');
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// text: gettext('Suspend'),
|
|
||||||
// iconCls: 'fa fa-fw fa-pause',
|
|
||||||
// hidde: suspended,
|
|
||||||
// disabled: stopped || suspended,
|
|
||||||
// handler: function() {
|
|
||||||
// var msg = Proxmox.Utils.format_task_description('vzsuspend', vmid);
|
|
||||||
// Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
|
||||||
// if (btn !== 'yes') {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// vm_command('suspend');
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// text: gettext('Resume'),
|
|
||||||
// iconCls: 'fa fa-fw fa-play',
|
|
||||||
// hidden: !suspended,
|
|
||||||
// handler: function() {
|
|
||||||
// vm_command('resume');
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
text: gettext('Shutdown'),
|
text: gettext('Shutdown'),
|
||||||
iconCls: 'fa fa-fw fa-power-off',
|
iconCls: 'fa fa-fw fa-power-off',
|
||||||
disabled: stopped || suspended,
|
disabled: stopped || suspended,
|
||||||
handler: function() {
|
handler: function() {
|
||||||
var msg = Proxmox.Utils.format_task_description('vzshutdown', vmid);
|
var msg = Proxmox.Utils.format_task_description('vzshutdown', info.vmid);
|
||||||
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
||||||
if (btn !== 'yes') {
|
if (btn !== 'yes') {
|
||||||
return;
|
return;
|
||||||
@ -102,7 +68,7 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
disabled: stopped,
|
disabled: stopped,
|
||||||
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
|
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
|
||||||
handler: function() {
|
handler: function() {
|
||||||
var msg = Proxmox.Utils.format_task_description('vzstop', vmid);
|
var msg = Proxmox.Utils.format_task_description('vzstop', info.vmid);
|
||||||
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
||||||
if (btn !== 'yes') {
|
if (btn !== 'yes') {
|
||||||
return;
|
return;
|
||||||
@ -118,7 +84,7 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
disabled: stopped,
|
disabled: stopped,
|
||||||
tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
|
tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
|
||||||
handler: function() {
|
handler: function() {
|
||||||
var msg = Proxmox.Utils.format_task_description('vzreboot', vmid);
|
var msg = Proxmox.Utils.format_task_description('vzreboot', info.vmid);
|
||||||
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
||||||
if (btn !== 'yes') {
|
if (btn !== 'yes') {
|
||||||
return;
|
return;
|
||||||
@ -136,40 +102,34 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
text: gettext('Clone'),
|
text: gettext('Clone'),
|
||||||
iconCls: 'fa fa-fw fa-clone',
|
iconCls: 'fa fa-fw fa-clone',
|
||||||
hidden: !caps.vms['VM.Clone'],
|
hidden: !caps.vms['VM.Clone'],
|
||||||
handler: function() {
|
handler: () => PVE.window.Clone.wrap(info.node, info.vmid, me.isTemplate, 'lxc'),
|
||||||
PVE.window.Clone.wrap(nodename, vmid, me.isTemplate, 'lxc');
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: gettext('Migrate'),
|
text: gettext('Migrate'),
|
||||||
iconCls: 'fa fa-fw fa-send-o',
|
iconCls: 'fa fa-fw fa-send-o',
|
||||||
hidden: standalone || !caps.vms['VM.Migrate'],
|
hidden: standalone || !caps.vms['VM.Migrate'],
|
||||||
handler: function() {
|
handler: function() {
|
||||||
var win = Ext.create('PVE.window.Migrate', {
|
Ext.create('PVE.window.Migrate', {
|
||||||
vmtype: 'lxc',
|
vmtype: 'lxc',
|
||||||
nodename: nodename,
|
nodename: info.node,
|
||||||
vmid: vmid,
|
vmid: info.vmid,
|
||||||
|
autoShow: true,
|
||||||
});
|
});
|
||||||
win.show();
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: gettext('Convert to template'),
|
text: gettext('Convert to template'),
|
||||||
iconCls: 'fa fa-fw fa-file-o',
|
iconCls: 'fa fa-fw fa-file-o',
|
||||||
handler: function() {
|
handler: function() {
|
||||||
var msg = Proxmox.Utils.format_task_description('vztemplate', vmid);
|
let msg = Proxmox.Utils.format_task_description('vztemplate', info.vmid);
|
||||||
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
|
||||||
if (btn !== 'yes') {
|
if (btn === 'yes') {
|
||||||
return;
|
Proxmox.Utils.API2Request({
|
||||||
|
url: `/nodes/${info.node}/lxc/${info.vmid}/template`,
|
||||||
|
method: 'POST',
|
||||||
|
failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Proxmox.Utils.API2Request({
|
|
||||||
url: '/nodes/' + nodename + '/lxc/' + vmid + '/template',
|
|
||||||
method: 'POST',
|
|
||||||
failure: function(response, opts) {
|
|
||||||
Ext.Msg.alert('Error', response.htmlStatus);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -177,9 +137,8 @@ Ext.define('PVE.lxc.CmdMenu', {
|
|||||||
{
|
{
|
||||||
text: gettext('Console'),
|
text: gettext('Console'),
|
||||||
iconCls: 'fa fa-fw fa-terminal',
|
iconCls: 'fa fa-fw fa-terminal',
|
||||||
handler: function() {
|
handler: () =>
|
||||||
PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
|
PVE.Utils.openDefaultConsoleWindow(true, 'lxc', info.vmid, info.node, info.vmname),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user