[pve-devel] [PATCH manager] Allow change of Datacenter wide default console without browser refresh

Emmanuel Kasper e.kasper at proxmox.com
Tue Dec 19 17:13:42 CET 2017


The previous implementation was relying on PVE.VersionInfo.console,
which is set after login and never refreshed after that.

We execute the API call before setting the button handler, otherwise
the browser would fire its popup blocker

Signed-off-by: Emmanuel Kasper <e.kasper at proxmox.com>
---
 www/manager6/Utils.js                |  4 ++--
 www/manager6/button/ConsoleButton.js | 25 ++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 578ba81e..1dc72260 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1180,9 +1180,9 @@ Ext.define('PVE.Utils', { utilities: {
 	}
     },
 
-    defaultViewer: function(allowSpice) {
+    defaultViewer: function(allowSpice, dcViewer) {
 	var vncdefault = 'html5';
-	var dv = PVE.VersionInfo.console || vncdefault;
+	var dv = dcViewer || vncdefault;
 	if (dv === 'vv' && !allowSpice) {
 	    dv = vncdefault;
 	}
diff --git a/www/manager6/button/ConsoleButton.js b/www/manager6/button/ConsoleButton.js
index a3bf7464..f75a7d48 100644
--- a/www/manager6/button/ConsoleButton.js
+++ b/www/manager6/button/ConsoleButton.js
@@ -18,14 +18,10 @@ Ext.define('PVE.button.ConsoleButton', {
 	var me = this;
 
 	me.enableSpice = enable;
+	me.setButtonHandler();
 	me.down('#spicemenu').setDisabled(!enable);
     },
 
-    handler: function() {
-	var me = this;
-	PVE.Utils.openDefaultConsoleWindow(me.enableSpice, me.consoleType, me.vmid,
-					   me.nodename, me.consoleName);
-    },
 
     menu: [
 	{
@@ -61,6 +57,24 @@ Ext.define('PVE.button.ConsoleButton', {
 	}
     ],
 
+    setButtonHandler: function() {
+	var me = this;
+
+	PVE.Utils.API2Request({
+	    url: '/api2/extjs/cluster/options',
+	    method: 'GET',
+	    success: function(response) {
+		var dcViewer = response.result.data.console;
+		var defViewer = PVE.Utils.defaultViewer(me.enableSpice, dcViewer);
+
+		me.setHandler(function() {
+		    PVE.Utils.openConsoleWindow(defViewer, me.consoleType,
+			me.vmid, me.nodename, me.consoleName);
+		});
+	    }
+	});
+    },
+
     initComponent: function() {
         var me = this;
 
@@ -69,5 +83,6 @@ Ext.define('PVE.button.ConsoleButton', {
 	}
 
 	me.callParent();
+	me.setButtonHandler();
     }
 });
-- 
2.11.0





More information about the pve-devel mailing list