]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/qemu/CmdMenu.js
ui: cloudinit: align default value for package upgrades with backend again
[pve-manager.git] / www / manager6 / qemu / CmdMenu.js
index 180e61773c3338aeb13d6e8b1d6c8300f669b9ab..ccc5f74d4e4b4c73f6422d5d48dbbb28a3c858db 100644 (file)
@@ -21,9 +21,17 @@ Ext.define('PVE.qemu.CmdMenu', {
                failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
            });
        };
+       let confirmedVMCommand = (cmd, params, confirmTask) => {
+           let task = confirmTask || `qm${cmd}`;
+           let msg = Proxmox.Utils.format_task_description(task, 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;
 
        let running = false, stopped = true, suspended = false;
@@ -58,14 +66,7 @@ Ext.define('PVE.qemu.CmdMenu', {
                iconCls: 'fa fa-fw fa-pause',
                hidden: stopped || suspended,
                disabled: stopped || suspended,
-               handler: function() {
-                   let msg = Proxmox.Utils.format_task_description('qmpause', info.vmid);
-                   Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
-                       if (btn === 'yes') {
-                           vm_command('suspend');
-                       }
-                   });
-               },
+               handler: () => confirmedVMCommand('suspend', undefined, 'qmpause'),
            },
            {
                text: gettext('Hibernate'),
@@ -73,14 +74,7 @@ Ext.define('PVE.qemu.CmdMenu', {
                hidden: stopped || suspended,
                disabled: stopped || suspended,
                tooltip: gettext('Suspend to disk'),
-               handler: function() {
-                   let msg = Proxmox.Utils.format_task_description('qmsuspend', info.vmid);
-                   Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
-                       if (btn === 'yes') {
-                           vm_command('suspend', { todisk: 1 });
-                       }
-                   });
-               },
+               handler: () => confirmedVMCommand('suspend', { todisk: 1 }),
            },
            {
                text: gettext('Resume'),
@@ -92,42 +86,21 @@ Ext.define('PVE.qemu.CmdMenu', {
                text: gettext('Shutdown'),
                iconCls: 'fa fa-fw fa-power-off',
                disabled: stopped || suspended,
-               handler: function() {
-                   let msg = Proxmox.Utils.format_task_description('qmshutdown', info.vmid);
-                   Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
-                       if (btn === 'yes') {
-                           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'), 'VM'),
-               handler: function() {
-                   let msg = Proxmox.Utils.format_task_description('qmstop', info.vmid);
-                   Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
-                       if (btn === 'yes') {
-                           vm_command("stop");
-                       }
-                   });
-               },
+               handler: () => confirmedVMCommand('stop'),
            },
            {
                text: gettext('Reboot'),
                iconCls: 'fa fa-fw fa-refresh',
                disabled: stopped,
                tooltip: Ext.String.format(gettext('Reboot {0}'), 'VM'),
-               handler: function() {
-                   let msg = Proxmox.Utils.format_task_description('qmreboot', info.vmid);
-                   Ext.Msg.confirm(gettext('Confirm'), msg, (btn) => {
-                       if (btn === 'yes') {
-                           vm_command("reboot");
-                       }
-                   });
-               },
+               handler: () => confirmedVMCommand('reboot'),
            },
            {
                xtype: 'menuseparator',