diff --git a/www/manager/Makefile b/www/manager/Makefile index 538a5dbd..671cd31c 100644 --- a/www/manager/Makefile +++ b/www/manager/Makefile @@ -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 \ diff --git a/www/manager/Utils.js b/www/manager/Utils.js index 93aa9c84..5f052e7f 100644 --- a/www/manager/Utils.js +++ b/www/manager/Utils.js @@ -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(); } + }}); diff --git a/www/manager/grid/ResourceGrid.js b/www/manager/grid/ResourceGrid.js index c7fbb25a..6d27d32f 100644 --- a/www/manager/grid/ResourceGrid.js +++ b/www/manager/grid/ResourceGrid.js @@ -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); diff --git a/www/manager/openvz/CmdMenu.js b/www/manager/openvz/CmdMenu.js new file mode 100644 index 00000000..0b72142e --- /dev/null +++ b/www/manager/openvz/CmdMenu.js @@ -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(); + } +}); diff --git a/www/manager/openvz/Config.js b/www/manager/openvz/Config.js index dd8769f6..fc7dc5c3 100644 --- a/www/manager/openvz/Config.js +++ b/www/manager/openvz/Config.js @@ -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); } }); diff --git a/www/manager/qemu/CmdMenu.js b/www/manager/qemu/CmdMenu.js new file mode 100644 index 00000000..584c827a --- /dev/null +++ b/www/manager/qemu/CmdMenu.js @@ -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(); + } +}); diff --git a/www/manager/qemu/Config.js b/www/manager/qemu/Config.js index 6938a38b..fab25d44 100644 --- a/www/manager/qemu/Config.js +++ b/www/manager/qemu/Config.js @@ -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); } }); diff --git a/www/manager/tree/ResourceTree.js b/www/manager/tree/ResourceTree.js index 30cc8b01..7b4beb02 100644 --- a/www/manager/tree/ResourceTree.js +++ b/www/manager/tree/ResourceTree.js @@ -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); }