Commit a2cc62aa authored by Dietmar Maurer's avatar Dietmar Maurer

new ConsoleButton class

We now use that split-button everywhere to make the GUI more consistent.
parent c00eceaa
......@@ -5,6 +5,7 @@ JSSRC= \
Parser.js \
StateProvider.js \
button/Button.js \
button/ConsoleButton.js \
qemu/SendKeyMenu.js \
qemu/CmdMenu.js \
qemu/TemplateMenu.js \
......
Ext.define('PVE.button.ConsoleButton', {
extend: 'Ext.button.Split',
alias: 'widget.pveConsoleButton',
consoleType: 'shell', // one of 'shell', 'kvm', 'openvz', 'upgrade'
consoleName: undefined,
enableSpice: undefined,
nodename: undefined,
vmid: 0,
setEnableSpice: function(enable){
var me = this;
me.enableSpice = enable;
me.spiceMenu.setDisabled(!enable);
},
getEnableSpice: function() {
var me = this;
if (me.enableSpice === undefined) {
if (PVE.VersionInfo.console && PVE.VersionInfo.console === 'vv') {
return true;
} else {
return false;
}
} else {
return me.enableSpice;
}
},
initComponent: function() {
var me = this;
if (!me.nodename) {
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() {
if (me.consoleType === 'kvm') {
PVE.Utils.openConsoleWindow('kvm', me.vmid, me.nodename, me.consoleName);
} else if (me.consoleType === 'openvz') {
PVE.Utils.openConsoleWindow('openvz', me.vmid, me.nodename, me.consoleName);
} else if (me.consoleType === 'shell') {
PVE.Utils.openConsoleWindow('shell', undefined, me.nodename);
} else if (me.consoleType === 'upgrade') {
var url = Ext.urlEncode({ console: 'upgrade', node: me.nodename });
var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
nw.focus();
}
};
me.spiceMenu = Ext.create('Ext.menu.Item', {
text: 'SPICE',
handler: create_spice_console
});
var vncMenu = Ext.create('Ext.menu.Item', {
text: 'VNC',
handler: create_vnc_console
});
Ext.applyIf(me, { text: gettext('Console') });
Ext.apply(me, {
handler: function() {
if (!me.getEnableSpice() ||
(PVE.VersionInfo.console && PVE.VersionInfo.console === 'applet')) {
create_vnc_console();
} else {
create_spice_console();
}
},
menu: new Ext.menu.Menu({
items: [ vncMenu, me.spiceMenu ]
})
});
me.callParent();
}
});
......@@ -78,30 +78,12 @@ Ext.define('PVE.node.APT', {
}
});
var upgrade_btn = new PVE.button.Button({
text: gettext('Upgrade'),
var upgrade_btn = Ext.create('PVE.button.ConsoleButton', {
disabled: !(PVE.UserName && PVE.UserName === 'root@pam'),
handler: function() {
PVE.Utils.checked_command(function() {
var url;
var params;
if (PVE.Utils.defaultViewer() === 'vv') {
url = '/nodes/' + nodename + '/spiceshell';
params = { upgrade: 1, proxy: window.location.hostname };
PVE.Utils.openSpiceViewer(url, params);
} else {
url = Ext.urlEncode({
console: 'upgrade',
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
}
});
}
});
text: gettext('Upgrade'),
consoleType: 'upgrade',
nodename: nodename
});
var show_changelog = function(rec) {
if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
......
......@@ -47,18 +47,12 @@ Ext.define('PVE.node.Config', {
}
});
var shellBtn = Ext.create('Ext.Button', {
text: gettext('Shell'),
var shellBtn = Ext.create('PVE.button.ConsoleButton', {
disabled: !caps.nodes['Sys.Console'],
handler: function() {
if (PVE.Utils.defaultViewer() === 'vv') {
var params = { proxy: window.location.hostname };
PVE.Utils.openSpiceViewer('/nodes/' + nodename + '/spiceshell', params);
} else {
PVE.Utils.openConsoleWindow('shell', undefined, nodename);
}
}
});
text: gettext('Shell'),
consoleType: 'shell',
nodename: nodename
});
me.items = [];
......
......@@ -101,18 +101,12 @@ Ext.define('PVE.openvz.Config', {
var vmname = me.pveSelNode.data.name;
var consoleBtn = Ext.create('Ext.Button', {
text: gettext('Console'),
var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
disabled: !caps.vms['VM.Console'],
handler: function() {
if (PVE.Utils.defaultViewer() === 'vv') {
var params = { proxy: window.location.hostname };
PVE.Utils.openSpiceViewer('/nodes/' + nodename + '/openvz/' + vmid +
'/spiceproxy', params);
} else {
PVE.Utils.openConsoleWindow('openvz', vmid, nodename, vmname);
}
}
consoleType: 'openvz',
consoleName: vmname,
nodename: nodename,
vmid: vmid
});
var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")";
......
......@@ -110,40 +110,12 @@ Ext.define('PVE.qemu.Config', {
var vmname = me.pveSelNode.data.name;
var spice = false;
var spiceMenu = Ext.create('Ext.menu.Item', {
text: 'SPICE',
handler: function(){
var url = '/nodes/' + nodename + '/qemu/' + vmid + '/spiceproxy';
var params = { proxy: window.location.hostname };
PVE.Utils.openSpiceViewer(url, params);
}
});
var consoleBtn = Ext.create('Ext.button.Split', {
text: gettext('Console'),
var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
disabled: !caps.vms['VM.Console'],
handler: function() {
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);
}
},
menu: new Ext.menu.Menu({
items: [
{
text: 'VNC',
handler: function(){
PVE.Utils.openConsoleWindow('kvm', vmid, nodename, vmname);
}
},
spiceMenu
]
})
consoleType: 'kvm',
consoleName: vmname,
nodename: nodename,
vmid: vmid
});
var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
......@@ -218,6 +190,7 @@ Ext.define('PVE.qemu.Config', {
var status;
var qmpstatus;
var template;
var spice = false;
if (!success) {
me.workspace.checkVmMigration(me.pveSelNode);
......@@ -242,9 +215,8 @@ Ext.define('PVE.qemu.Config', {
startBtn.setVisible(true);
resumeBtn.setVisible(false);
}
spiceMenu.setVisible(spice);
spiceMenu.setDisabled(!caps.vms['VM.Console'] || status !== 'running');
consoleBtn.setEnableSpice(spice);
startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment