ui: lxc/context cmd: factor out confirmed CT command

unifying CT and VM command menu would be pretty easy now, but I need
to wrap the eslint stuff up, so cannot chase all tails..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-19 10:19:07 +02:00
parent 4ed1130cb1
commit 9f1ceecf96

View File

@ -21,6 +21,14 @@ Ext.define('PVE.lxc.CmdMenu', {
failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
});
};
let confirmedVMCommand = (cmd, params) => {
let msg = Proxmox.Utils.format_task_description(`vz${cmd}`, info.vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
if (btn === 'yes') {
vm_command(cmd, params);
}
});
};
let caps = Ext.state.Manager.get('GuiCap');
let standalone = PVE.data.ResourceStore.getNodes().length < 2;
@ -51,48 +59,21 @@ Ext.define('PVE.lxc.CmdMenu', {
text: gettext('Shutdown'),
iconCls: 'fa fa-fw fa-power-off',
disabled: stopped || suspended,
handler: function() {
var msg = Proxmox.Utils.format_task_description('vzshutdown', info.vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command('shutdown');
});
},
handler: () => confirmedVMCommand('shutdown'),
},
{
text: gettext('Stop'),
iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
handler: function() {
var msg = Proxmox.Utils.format_task_description('vzstop', info.vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command("stop");
});
},
handler: () => confirmedVMCommand('stop'),
},
{
text: gettext('Reboot'),
iconCls: 'fa fa-fw fa-refresh',
disabled: stopped,
tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
handler: function() {
var msg = Proxmox.Utils.format_task_description('vzreboot', info.vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command("reboot");
});
},
handler: () => confirmedVMCommand('reboot'),
},
{
xtype: 'menuseparator',