add context menus

This commit is contained in:
Dietmar Maurer 2011-11-14 12:43:16 +01:00
parent 906fa3257a
commit 176eee4fec
8 changed files with 181 additions and 18 deletions

View File

@ -6,6 +6,8 @@ JSSRC= \
StateProvider.js \
button/Button.js \
qemu/SendKeyMenu.js \
qemu/CmdMenu.js \
openvz/CmdMenu.js \
VNCConsole.js \
data/TimezoneStore.js \
data/reader/JsonObject.js \

View File

@ -686,6 +686,18 @@ Ext.define('PVE.Utils', { statics: {
var id = record.data.id;
return PVE.Utils.format_task_description(type, id);
},
openConoleWindow: function(vmtype, vmid, nodename) {
var url = Ext.urlEncode({
console: vmtype, // kvm or openvz
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
}
}});

View File

@ -194,10 +194,30 @@ Ext.define('PVE.grid.ResourceGrid', {
}
],
viewConfig: {
stripeRows: true,
trackOver: false
stripeRows: true
},
listeners: {
itemcontextmenu: function(v, record, item, index, event) {
event.stopEvent();
v.select(record);
var menu;
if (record.data.type === 'qemu') {
menu = Ext.create('PVE.qemu.CmdMenu', {
vmid: record.data.vmid,
nodename: record.data.node
});
} else if (record.data.type === 'openvz') {
menu = Ext.create('PVE.openvz.CmdMenu', {
vmid: record.data.vmid,
nodename: record.data.node
});
} else {
return;
}
menu.showAt(event.getXY());
},
itemdblclick: function(v, record) {
var ws = me.up('pveStdWorkspace');
ws.selectById(record.data.id);

View File

@ -0,0 +1,61 @@
Ext.define('PVE.openvz.CmdMenu', {
extend: 'Ext.menu.Menu',
initComponent: function() {
var me = this;
if (!me.nodename) {
throw "no node name specified";
}
if (!me.vmid) {
throw "no VM ID specified";
}
var vm_command = function(cmd, params) {
PVE.Utils.API2Request({
params: params,
url: '/nodes/' + me.nodename + '/openvz/' + me.vmid + "/status/" + cmd,
method: 'POST',
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
}
});
};
me.title = "CT " + me.vmid;
me.items = [
{
text: 'Start',
icon: '/pve2/images/start.png',
handler: function() {
vm_command('start');
}
},
{
text: 'Shutdown',
icon: '/pve2/images/stop.png',
handler: function() {
var msg = "Do you really want to shutdown the VM?";
Ext.Msg.confirm('Confirmation', msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command('stop');
});
}
},
{
text: 'Console',
icon: '/pve2/images/display.png',
handler: function() {
PVE.Utils.openConoleWindow('openvz', me.vmid, me.nodename);
}
}
];
me.callParent();
}
});

View File

@ -74,14 +74,7 @@ Ext.define('PVE.openvz.Config', {
var consoleBtn = Ext.create('Ext.Button', {
text: 'Console',
handler: function() {
var url = Ext.urlEncode({
console: 'openvz',
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
PVE.Utils.openConoleWindow('openvz', vmid, nodename);
}
});

View File

@ -0,0 +1,61 @@
Ext.define('PVE.qemu.CmdMenu', {
extend: 'Ext.menu.Menu',
initComponent: function() {
var me = this;
if (!me.nodename) {
throw "no node name specified";
}
if (!me.vmid) {
throw "no VM ID specified";
}
var vm_command = function(cmd, params) {
PVE.Utils.API2Request({
params: params,
url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/status/" + cmd,
method: 'POST',
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
}
});
};
me.title = "VM " + me.vmid;
me.items = [
{
text: 'Start',
icon: '/pve2/images/start.png',
handler: function() {
vm_command('start');
}
},
{
text: 'Shutdown',
icon: '/pve2/images/stop.png',
handler: function() {
var msg = "Do you really want to shutdown the VM?";
Ext.Msg.confirm('Confirmation', msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command('shutdown', { timeout: 30 });
});
}
},
{
text: 'Console',
icon: '/pve2/images/display.png',
handler: function() {
PVE.Utils.openConoleWindow('kvm', me.vmid, me.nodename);
}
}
];
me.callParent();
}
});

View File

@ -92,14 +92,7 @@ Ext.define('PVE.qemu.Config', {
var consoleBtn = Ext.create('Ext.Button', {
text: 'Console',
handler: function() {
var url = Ext.urlEncode({
console: 'kvm',
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
PVE.Utils.openConoleWindow('kvm', vmid, nodename);
}
});

View File

@ -322,6 +322,27 @@ Ext.define('PVE.tree.ResourceTree', {
//rootVisible: false,
//title: 'Resource Tree',
listeners: {
itemcontextmenu: function(v, record, item, index, event) {
event.stopEvent();
//v.select(record);
var menu;
if (record.data.type === 'qemu') {
menu = Ext.create('PVE.qemu.CmdMenu', {
vmid: record.data.vmid,
nodename: record.data.node
});
} else if (record.data.type === 'openvz') {
menu = Ext.create('PVE.openvz.CmdMenu', {
vmid: record.data.vmid,
nodename: record.data.node
});
} else {
return;
}
menu.showAt(event.getXY());
},
destroy: function() {
rstore.un("load", updateTree);
}