]> git.proxmox.com Git - pve-manager.git/commitdiff
further console cleanups
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Jun 2014 06:46:02 +0000 (08:46 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Jun 2014 06:46:02 +0000 (08:46 +0200)
www/manager/Utils.js
www/manager/VNCConsole.js
www/manager/button/ConsoleButton.js
www/manager/openvz/CmdMenu.js
www/manager/qemu/CmdMenu.js

index 884381f8366c94112744c7f7f4016526753bdeb7..92bf5fc46f24f3a7a54bd8e3a6e8be52ee19b69f 100644 (file)
@@ -1090,17 +1090,44 @@ Ext.define('PVE.Utils', { statics: {
        }
     },
  
-    openConsoleWindow: function(vmtype, vmid, nodename, vmname, novnc) {
-       var url = Ext.urlEncode({
-           console: vmtype, // kvm, openvz or shell
-           novnc: novnc ? 1 : 0,
-           vmid: vmid,
-           vmname: vmname,
-           node: nodename
-       });
-       var nw = window.open("?" + url, '_blank', 
-                            "innerWidth=745,innerheight=427");
-       nw.focus();
+    openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
+       var dv = PVE.Utils.defaultViewer(allowSpice);
+       PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
+    },
+
+    openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) {
+       // kvm, openvz, shell, upgrade
+
+       if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'openvz')) {
+           throw "missing vmid";
+       }
+
+       if (!nodename) {
+           throw "no nodename specified";
+       }
+
+       if (viewer === 'applet' || viewer === 'html5') {
+           PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, viewer === 'html5');
+       } else if (viewer === 'vv') {
+           var url;
+           var params = { proxy: window.location.hostname };
+           if (vmtype === 'kvm') {
+               url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
+               PVE.Utils.openSpiceViewer(url, params);
+           } else if (vmtype === 'openvz') {
+               url = '/nodes/' + nodename + '/openvz/' + vmid.toString() + '/spiceproxy';
+               PVE.Utils.openSpiceViewer(url, params);
+           } else if (vmtype === 'shell') {
+               url = '/nodes/' + nodename + '/spiceshell';
+               PVE.Utils.openSpiceViewer(url, params);
+           } else if (vmtype === 'upgrade') {
+               url = '/nodes/' + nodename + '/spiceshell';
+               params.upgrade = 1;
+               PVE.Utils.openSpiceViewer(url, params);
+           }
+       } else {
+           throw "unknown viewer type";
+       }
     },
 
     defaultViewer: function(allowSpice) {
@@ -1113,6 +1140,18 @@ Ext.define('PVE.Utils', { statics: {
        return dv;
     },
 
+    openVNCViewer: function(vmtype, vmid, nodename, vmname, novnc) {
+       var url = Ext.urlEncode({
+           console: vmtype, // kvm, openvz, upgrade or shell
+           novnc: novnc ? 1 : 0,
+           vmid: vmid,
+           vmname: vmname,
+           node: nodename
+       });
+       var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
+       nw.focus();
+    },
+
     openSpiceViewer: function(url, params){
 
        var downloadWithName = function(uri, name) {
index f1116ec4baef28e898500851874a848cffb0d2ff..3f1f85db66d1c799e98ae2c756cd18eeb3a58948 100644 (file)
@@ -347,7 +347,7 @@ Ext.define('PVE.KVMConsole', {
             { 
                 text: gettext('Console'),
                 handler: function() {
-                   PVE.Utils.openConsoleWindow('kvm', me.vmid, me.nodename, me.vmname, me.novnc);
+                   PVE.Utils.openVNCViewer('kvm', me.vmid, me.nodename, me.vmname, me.novnc);
                }
             },
             '->',
@@ -506,7 +506,7 @@ Ext.define('PVE.Shell', {
            { 
                text: gettext('Shell'),
                handler: function() {
-                   PVE.Utils.openConsoleWindow('shell', undefined, me.nodename, undefined, me.novnc);
+                   PVE.Utils.openVNCViewer('shell', undefined, me.nodename, undefined, me.novnc);
                }
            }
        ]);
index d33cd69275afa5814da23a20ca4c75fb01b0fd08..58da3c221216eb4dd84a82e2bf23879e0e32c694 100644 (file)
@@ -26,83 +26,36 @@ Ext.define('PVE.button.ConsoleButton', {
            throw "no node name specified";
        }
 
-       if (!me.consoleName) {
-           if (me.consoleType === 'kvm') {
-               me.consoleName = "VM " + me.vmid.toString();
-           } else if (me.consoleType === 'openvz') {
-               me.consoleName = "CT " + me.vmid.toString();
-           } else {
-               me.consoleName = "Shell";
-           }
-       }
-
-       var create_spice_console = function() {
-           var url;
-           var params = { proxy: window.location.hostname };
-           if (me.consoleType === 'kvm') {
-               url = '/nodes/' + me.nodename + '/qemu/' + 
-                   me.vmid.toString() + '/spiceproxy';
-               PVE.Utils.openSpiceViewer(url, params);
-           } else if (me.consoleType === 'openvz') {
-               url = '/nodes/' + me.nodename + '/openvz/' + 
-                   me.vmid.toString() + '/spiceproxy';
-               PVE.Utils.openSpiceViewer(url, params);
-           } else if (me.consoleType === 'shell') {
-               url = '/nodes/' + me.nodename + '/spiceshell';
-               PVE.Utils.openSpiceViewer(url, params);
-           } else if (me.consoleType === 'upgrade') {
-               url = '/nodes/' + me.nodename + '/spiceshell';
-               params.upgrade = 1;
-               PVE.Utils.openSpiceViewer(url, params);
-           }
-       };
-
-       var create_vnc_console = function(novnc) {
-           if (me.consoleType === 'kvm') {
-               PVE.Utils.openConsoleWindow('kvm', me.vmid, me.nodename, me.consoleName, novnc);
-           } else if (me.consoleType === 'openvz') {
-               PVE.Utils.openConsoleWindow('openvz', me.vmid, me.nodename, me.consoleName, novnc);
-           } else if (me.consoleType === 'shell') {
-               PVE.Utils.openConsoleWindow('shell', undefined, me.nodename, undefined, novnc);
-           } else if (me.consoleType === 'upgrade') {
-               var url = Ext.urlEncode({ console: 'upgrade', node: me.nodename, novnc: novnc });
-               var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
-               nw.focus();
-           }
-       };
-
        me.spiceMenu = Ext.create('Ext.menu.Item', {
            text: 'SPICE',
            iconCls: 'pve-itype-icon-virt-viewer',
-           handler: create_spice_console
+           handler: function() { 
+               PVE.Utils.openConsoleWindow('vv', me.consoleType, me.vmid, me.nodename, me.consoleName);
+           }
        });
 
        var vncMenu = Ext.create('Ext.menu.Item', {
            text: 'VNC',
            iconCls: 'pve-itype-icon-tigervnc',
-           handler: function() { create_vnc_console(0); }
+           handler: function() { 
+               PVE.Utils.openConsoleWindow('applet', me.consoleType, me.vmid, me.nodename, me.consoleName);
+           }
        });
 
        var noVncMenu = Ext.create('Ext.menu.Item', {
            text: 'noVNC',
            iconCls: 'pve-itype-icon-novnc',
-           handler: function() { create_vnc_console(1); }
+           handler: function() { 
+               PVE.Utils.openConsoleWindow('html5', me.consoleType, me.vmid, me.nodename, me.consoleName);
+           }
        });
 
        Ext.applyIf(me, { text: gettext('Console') });
 
        Ext.apply(me, {
            handler: function() {
-               var dv = PVE.Utils.defaultViewer(me.enableSpice);
-               if (dv === 'vv') {
-                   create_spice_console();
-               } else if (dv === 'applet') {
-                   create_vnc_console(0);
-               } else if (dv === 'html5') {
-                   create_vnc_console(1);
-               } else {
-                   throw "unknown defaultViewer";
-               }
+               PVE.Utils.openDefaultConsoleWindow(me.enableSpice, me.consoleType, me.vmid, 
+                                                  me.nodename, me.consoleName);
            },
            menu: new Ext.menu.Menu({
                items: [ noVncMenu, vncMenu, me.spiceMenu ]
index 14774a4be47c6047b3bb916f60492c0c45d83df3..85589eda659511ff1f0115f898c354adc5b1d5f3 100644 (file)
@@ -81,7 +81,7 @@ Ext.define('PVE.openvz.CmdMenu', {
                text: gettext('Console'),
                icon: '/pve2/images/display.png',
                handler: function() {
-                   PVE.Utils.openConsoleWindow('openvz', vmid, nodename, vmname);
+                   PVE.Utils.openDefaultConsoleWindow(true, 'openvz', vmid, nodename, vmname);
                }
            }
        ];
index 30fd82cb14a21bca817ccb28be30c685c6a00e72..853f57bc840c95eb35345f8538890ee87e3a0152 100644 (file)
@@ -118,14 +118,8 @@ Ext.define('PVE.qemu.CmdMenu', {
                            Ext.Msg.alert('Error', response.htmlStatus);
                        },
                        success: function(response, opts) {
-                           var spice = response.result.data.spice;
-                           if (PVE.VersionInfo.console === 'applet' || !spice) {
-                               PVE.Utils.openConsoleWindow('kvm', vmid, nodename, vmname);
-                           } else {
-                               var url = '/nodes/' + nodename + '/qemu/' + vmid + '/spiceproxy';
-                               var params = { proxy: window.location.hostname };
-                               PVE.Utils.openSpiceViewer(url, params);
-                           }
+                           var allowSpice = response.result.data.spice;
+                           PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
                        }
                    });
                }