Signed-off-by: Fiona Ebner <f.eb...@proxmox.com>
---

Depends on https://lists.proxmox.com/pipermail/pve-devel/2023-June/057635.html

Used a new window, because it's small and couldn't find a good
fit with the existing ones. Maybe SafeDestroy, but not in name and
would require a few modifications too.

Not sure about using gettext() for the option names.

 www/manager6/Makefile               |   1 +
 www/manager6/node/Config.js         |  32 +++----
 www/manager6/window/NodeShutdown.js | 126 ++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 20 deletions(-)
 create mode 100644 www/manager6/window/NodeShutdown.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 9b6dd13b..94c8c05e 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -107,6 +107,7 @@ JSSRC=                                                      
\
        window/FirewallLograteEdit.js                   \
        window/LoginWindow.js                           \
        window/Migrate.js                               \
+       window/NodeShutdown.js                          \
        window/Prune.js                                 \
        window/Restore.js                               \
        window/SafeDestroyGuest.js                      \
diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index 6ed2172a..51d9e85d 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -19,18 +19,6 @@ Ext.define('PVE.node.Config', {
            interval: 5000,
        });
 
-       var node_command = function(cmd) {
-           Proxmox.Utils.API2Request({
-               params: { command: cmd },
-               url: '/nodes/' + nodename + '/status',
-               method: 'POST',
-               waitMsgTarget: me,
-               failure: function(response, opts) {
-                   Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-               },
-           });
-       };
-
        var actionBtn = Ext.create('Ext.Button', {
            text: gettext('Bulk Actions'),
            iconCls: 'fa fa-fw fa-ellipsis-v',
@@ -83,24 +71,28 @@ Ext.define('PVE.node.Config', {
            }),
        });
 
-       let restartBtn = Ext.create('Proxmox.button.Button', {
+       let restartBtn = Ext.create('Ext.button.Button', {
            text: gettext('Reboot'),
            disabled: !caps.nodes['Sys.PowerMgmt'],
-           dangerous: true,
-           confirmMsg: Ext.String.format(gettext("Reboot node '{0}'?"), 
nodename),
            handler: function() {
-               node_command('reboot');
+               Ext.create('PVE.window.NodeShutdown', {
+                   confirmMsg: Ext.String.format(gettext("Reboot node 
'{0}'?"), nodename),
+                   url: '/nodes/' + nodename + '/status',
+                   command: 'reboot',
+               }).show();
            },
            iconCls: 'fa fa-undo',
        });
 
-       var shutdownBtn = Ext.create('Proxmox.button.Button', {
+       let shutdownBtn = Ext.create('Ext.button.Button', {
            text: gettext('Shutdown'),
            disabled: !caps.nodes['Sys.PowerMgmt'],
-           dangerous: true,
-           confirmMsg: Ext.String.format(gettext("Shutdown node '{0}'?"), 
nodename),
            handler: function() {
-               node_command('shutdown');
+               Ext.create('PVE.window.NodeShutdown', {
+                   confirmMsg: Ext.String.format(gettext("Shutdown node 
'{0}'?"), nodename),
+                   url: '/nodes/' + nodename + '/status',
+                   command: 'shutdown',
+               }).show();
            },
            iconCls: 'fa fa-power-off',
        });
diff --git a/www/manager6/window/NodeShutdown.js 
b/www/manager6/window/NodeShutdown.js
new file mode 100644
index 00000000..4cdc541c
--- /dev/null
+++ b/www/manager6/window/NodeShutdown.js
@@ -0,0 +1,126 @@
+Ext.define('PVE.window.NodeShutdown', {
+    extend: 'Ext.window.Window',
+    alias: 'widget.pveNodeShutdown',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    title: gettext('Confirm'),
+    modal: true,
+    buttonAlign: 'center',
+    bodyPadding: 10,
+    width: 450,
+    layout: { type: 'hbox' },
+    defaultFocus: 'nodeShutdownNoButton',
+
+    config: {
+       url: undefined,
+       confirmMsg: undefined,
+       command: undefined,
+    },
+
+    getParams: function() {
+       let me = this;
+       let params = { command: me.getCommand(), };
+
+       let shutdownPolicy = me.lookup('shutdownPolicy').getValue();
+       if (shutdownPolicy && shutdownPolicy !== '__default__') {
+           params['shutdown-policy'] = shutdownPolicy;
+       }
+
+       return params;
+    },
+
+    controller: {
+       xclass: 'Ext.app.ViewController',
+
+       control: {
+           'button[reference=yesButton]': {
+               click: function() {
+                   const view = this.getView();
+                   Proxmox.Utils.API2Request({
+                       params: view.getParams(),
+                       url: view.getUrl(),
+                       method: 'POST',
+                       waitMsgTarget: view,
+                       failure: function(response, opts) {
+                           Ext.Msg.alert(gettext('Error'), 
response.htmlStatus);
+                       },
+                       success: function(response, options) {
+                           view.close();
+                       },
+                   });
+               },
+           },
+           'button[reference=noButton]': {
+               click: function() {
+                   this.getView().close();
+               },
+           },
+       },
+    },
+
+    buttons: [
+       {
+           xtype: 'proxmoxHelpButton',
+           listeners: {
+               beforerender: () => {
+                   Ext.GlobalEvents.fireEvent('proxmoxShowHelp', 
'ha_manager_shutdown_policy');
+               },
+           },
+       },
+       '->',
+       {
+           reference: 'yesButton',
+           text: gettext('Yes'),
+       },
+       {
+           id: 'nodeShutdownNoButton',
+           reference: 'noButton',
+           text: gettext('No'),
+       },
+    ],
+
+    items: [
+       {
+           xtype: 'component',
+           cls: [
+               Ext.baseCSSPrefix + 'message-box-icon',
+               Ext.baseCSSPrefix + 'message-box-warning',
+               Ext.baseCSSPrefix + 'dlg-icon',
+           ],
+       },
+       {
+           xtype: 'container',
+           flex: 1,
+           layout: {
+               type: 'vbox',
+               align: 'stretch',
+           },
+           items: [
+               {
+                   xtype: 'displayfield',
+                   reference: 'messageCmp',
+                   cbind: {
+                       value: '{confirmMsg}',
+                   },
+               },
+               {
+                   reference: 'shutdownPolicy',
+                   fieldLabel: gettext('HA Shutdown Policy'),
+                   labelWidth: 130,
+                   xtype: 'proxmoxKVComboBox',
+                   comboItems: [
+                       [
+                           '__default__',
+                           Ext.String.format(gettext("Fallback from {0}"), 
"datacenter.cfg")
+                       ],
+                       ['migrate', gettext("Migrate")],
+                       ['conditional', gettext("Conditional")],
+                       ['freeze', gettext("Freeze")],
+                       ['failover', gettext("Failover")],
+                   ],
+                   value: '__default__',
+               },
+           ],
+       },
+    ],
+});
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to