pve-manager/www/manager6/qemu/CmdMenu.js
Michael Köppl 708de5b341 close #3181: ui: display guest name in confirm dialogs
The confirmation dialogs of the following actions are affected by this
change:
* Remove
* Clone
* Migrate
* Snapshot
* Snapshot restore
* Backup VM/CT from config view
* Restore VM/CT from config view

A combination of VM/CT id and name is added to each confirmation dialog.
The order of id and name depends on the sort field selected in the tree
settings. If "Name" is selected, the confirmation dialogs will show "VM
name (VMID)". In any other case, "VMID (VM name)" will be used.

The VM/CT name is considered optional in all handled cases. If it is
undefined, only the VMID will be displayed in the dialog window. No
exceptions are thrown in case of an undefined guest name because it
only extends the information displayed to the user and is not essential
for performing any of the actions above.

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
2025-04-07 14:07:35 +02:00

186 lines
4.5 KiB
JavaScript

Ext.define('PVE.qemu.CmdMenu', {
extend: 'Ext.menu.Menu',
showSeparator: false,
initComponent: function() {
let me = this;
let info = me.pveSelNode.data;
if (!info.node) {
throw "no node name specified";
}
if (!info.vmid) {
throw "no VM ID specified";
}
let vm_command = function(cmd, params) {
Proxmox.Utils.API2Request({
params: params,
url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
method: 'POST',
failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
});
};
let confirmedVMCommand = (cmd, params, confirmTask) => {
let task = confirmTask || `qm${cmd}`;
let msg = PVE.Utils.formatGuestTaskConfirmation(task, info.vmid, info.name);
Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
if (btn === 'yes') {
vm_command(cmd, params);
}
});
};
let caps = Ext.state.Manager.get('GuiCap');
let standalone = PVE.Utils.isStandaloneNode();
let running = false, stopped = true, suspended = false;
switch (info.status) {
case 'running':
running = true;
stopped = false;
break;
case 'suspended':
stopped = false;
suspended = true;
break;
case 'paused':
stopped = false;
suspended = true;
break;
default: break;
}
me.title = "VM " + info.vmid;
me.items = [
{
text: gettext('Start'),
iconCls: 'fa fa-fw fa-play',
hidden: running || suspended,
disabled: running || suspended,
handler: () => vm_command('start'),
},
{
text: gettext('Pause'),
iconCls: 'fa fa-fw fa-pause',
hidden: stopped || suspended,
disabled: stopped || suspended,
handler: () => confirmedVMCommand('suspend', undefined, 'qmpause'),
},
{
text: gettext('Hibernate'),
iconCls: 'fa fa-fw fa-download',
hidden: stopped || suspended,
disabled: stopped || suspended,
tooltip: gettext('Suspend to disk'),
handler: () => confirmedVMCommand('suspend', { todisk: 1 }),
},
{
text: gettext('Resume'),
iconCls: 'fa fa-fw fa-play',
hidden: !suspended,
handler: () => vm_command('resume'),
},
{
text: gettext('Shutdown'),
iconCls: 'fa fa-fw fa-power-off',
disabled: stopped || suspended,
handler: () => confirmedVMCommand('shutdown'),
},
{
text: gettext('Stop'),
iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
handler: () => {
Ext.create('PVE.GuestStop', {
nodename: info.node,
vm: info,
autoShow: true,
});
},
},
{
text: gettext('Reboot'),
iconCls: 'fa fa-fw fa-refresh',
disabled: stopped,
tooltip: Ext.String.format(gettext('Reboot {0}'), 'VM'),
handler: () => confirmedVMCommand('reboot'),
},
{
xtype: 'menuseparator',
hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
},
{
text: gettext('Migrate'),
iconCls: 'fa fa-fw fa-send-o',
hidden: standalone || !caps.vms['VM.Migrate'],
handler: function() {
Ext.create('PVE.window.Migrate', {
vmtype: 'qemu',
nodename: info.node,
vmid: info.vmid,
vmname: info.name,
autoShow: true,
});
},
},
{
text: gettext('Clone'),
iconCls: 'fa fa-fw fa-clone',
hidden: !caps.vms['VM.Clone'],
handler: () => PVE.window.Clone.wrap(
info.node,
info.vmid,
info.name,
me.isTemplate,
'qemu',
),
},
{
text: gettext('Convert to template'),
iconCls: 'fa fa-fw fa-file-o',
hidden: !caps.vms['VM.Allocate'],
handler: function() {
let msg = PVE.Utils.formatGuestTaskConfirmation('qmtemplate', info.vmid, info.name);
Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
if (btn === 'yes') {
Proxmox.Utils.API2Request({
url: `/nodes/${info.node}/qemu/${info.vmid}/template`,
method: 'POST',
failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
});
}
});
},
},
{ xtype: 'menuseparator' },
{
text: gettext('Console'),
iconCls: 'fa fa-fw fa-terminal',
handler: function() {
Proxmox.Utils.API2Request({
url: `/nodes/${info.node}/qemu/${info.vmid}/status/current`,
failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
success: function({ result: { data } }, opts) {
PVE.Utils.openDefaultConsoleWindow(
{
spice: data.spice,
xtermjs: data.serial,
},
'kvm',
info.vmid,
info.node,
info.name,
);
},
});
},
},
];
me.callParent();
},
});