Commit b82d8626 authored by Dietmar Maurer's avatar Dietmar Maurer

add context menus

parent 5b784e19
...@@ -6,6 +6,8 @@ JSSRC= \ ...@@ -6,6 +6,8 @@ JSSRC= \
StateProvider.js \ StateProvider.js \
button/Button.js \ button/Button.js \
qemu/SendKeyMenu.js \ qemu/SendKeyMenu.js \
qemu/CmdMenu.js \
openvz/CmdMenu.js \
VNCConsole.js \ VNCConsole.js \
data/TimezoneStore.js \ data/TimezoneStore.js \
data/reader/JsonObject.js \ data/reader/JsonObject.js \
......
...@@ -686,6 +686,18 @@ Ext.define('PVE.Utils', { statics: { ...@@ -686,6 +686,18 @@ Ext.define('PVE.Utils', { statics: {
var id = record.data.id; var id = record.data.id;
return PVE.Utils.format_task_description(type, 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();
} }
}}); }});
...@@ -194,10 +194,30 @@ Ext.define('PVE.grid.ResourceGrid', { ...@@ -194,10 +194,30 @@ Ext.define('PVE.grid.ResourceGrid', {
} }
], ],
viewConfig: { viewConfig: {
stripeRows: true, stripeRows: true
trackOver: false
}, },
listeners: { 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) { itemdblclick: function(v, record) {
var ws = me.up('pveStdWorkspace'); var ws = me.up('pveStdWorkspace');
ws.selectById(record.data.id); ws.selectById(record.data.id);
......
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();
}
});
...@@ -74,14 +74,7 @@ Ext.define('PVE.openvz.Config', { ...@@ -74,14 +74,7 @@ Ext.define('PVE.openvz.Config', {
var consoleBtn = Ext.create('Ext.Button', { var consoleBtn = Ext.create('Ext.Button', {
text: 'Console', text: 'Console',
handler: function() { handler: function() {
var url = Ext.urlEncode({ PVE.Utils.openConoleWindow('openvz', vmid, nodename);
console: 'openvz',
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
} }
}); });
......
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();
}
});
...@@ -92,14 +92,7 @@ Ext.define('PVE.qemu.Config', { ...@@ -92,14 +92,7 @@ Ext.define('PVE.qemu.Config', {
var consoleBtn = Ext.create('Ext.Button', { var consoleBtn = Ext.create('Ext.Button', {
text: 'Console', text: 'Console',
handler: function() { handler: function() {
var url = Ext.urlEncode({ PVE.Utils.openConoleWindow('kvm', vmid, nodename);
console: 'kvm',
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
} }
}); });
......
...@@ -322,6 +322,27 @@ Ext.define('PVE.tree.ResourceTree', { ...@@ -322,6 +322,27 @@ Ext.define('PVE.tree.ResourceTree', {
//rootVisible: false, //rootVisible: false,
//title: 'Resource Tree', //title: 'Resource Tree',
listeners: { 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() { destroy: function() {
rstore.un("load", updateTree); rstore.un("load", updateTree);
} }
......
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