make contextmenus status-sensitive

for example, allow starting from contextmenu
only if vm/ct is stopped, etc.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2016-04-05 11:31:47 +02:00 committed by Dietmar Maurer
parent d4333933e5
commit ce8dac510e
2 changed files with 42 additions and 0 deletions

View File

@ -27,12 +27,29 @@ Ext.define('PVE.lxc.CmdMenu', {
}); });
}; };
var running = false;
var stopped = true;
var suspended = false;
switch (me.pveSelNode.data.status) {
case 'running':
running = true;
stopped = false;
break;
case 'paused':
stopped = false;
suspended = true;
break;
default: break;
}
me.title = 'CT ' + vmid; me.title = 'CT ' + vmid;
me.items = [ me.items = [
{ {
text: gettext('Start'), text: gettext('Start'),
iconCls: 'fa fa-fw fa-play', iconCls: 'fa fa-fw fa-play',
disabled: running,
handler: function() { handler: function() {
vm_command('start'); vm_command('start');
} }
@ -52,6 +69,7 @@ Ext.define('PVE.lxc.CmdMenu', {
{ {
text: gettext('Suspend'), text: gettext('Suspend'),
iconCls: 'fa fa-fw fa-pause', iconCls: 'fa fa-fw fa-pause',
disabled: stopped || suspended,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('vzsuspend', vmid); var msg = PVE.Utils.format_task_description('vzsuspend', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
@ -66,6 +84,7 @@ Ext.define('PVE.lxc.CmdMenu', {
{ {
text: gettext('Resume'), text: gettext('Resume'),
iconCls: 'fa fa-fw fa-play', iconCls: 'fa fa-fw fa-play',
disabled: !suspended,
handler: function() { handler: function() {
vm_command('resume'); vm_command('resume');
} }
@ -73,6 +92,7 @@ Ext.define('PVE.lxc.CmdMenu', {
{ {
text: gettext('Shutdown'), text: gettext('Shutdown'),
iconCls: 'fa fa-fw fa-power-off', iconCls: 'fa fa-fw fa-power-off',
disabled: stopped || suspended,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('vzshutdown', vmid); var msg = PVE.Utils.format_task_description('vzshutdown', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
@ -87,6 +107,7 @@ Ext.define('PVE.lxc.CmdMenu', {
{ {
text: gettext('Stop'), text: gettext('Stop'),
iconCls: 'fa fa-fw fa-stop', iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('vzstop', vmid); var msg = PVE.Utils.format_task_description('vzstop', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {

View File

@ -27,12 +27,29 @@ Ext.define('PVE.qemu.CmdMenu', {
}); });
}; };
var running = false;
var stopped = true;
var suspended = false;
switch (me.pveSelNode.data.status) {
case 'running':
running = true;
stopped = false;
break;
case 'paused':
stopped = false;
suspended = true;
break;
default: break;
}
me.title = "VM " + vmid; me.title = "VM " + vmid;
me.items = [ me.items = [
{ {
text: gettext('Start'), text: gettext('Start'),
iconCls: 'fa fa-fw fa-play', iconCls: 'fa fa-fw fa-play',
disabled: running,
handler: function() { handler: function() {
vm_command('start'); vm_command('start');
} }
@ -52,6 +69,7 @@ Ext.define('PVE.qemu.CmdMenu', {
{ {
text: gettext('Suspend'), text: gettext('Suspend'),
iconCls: 'fa fa-fw fa-pause', iconCls: 'fa fa-fw fa-pause',
disabled: stopped || suspended,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('qmsuspend', vmid); var msg = PVE.Utils.format_task_description('qmsuspend', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
@ -65,6 +83,7 @@ Ext.define('PVE.qemu.CmdMenu', {
{ {
text: gettext('Resume'), text: gettext('Resume'),
iconCls: 'fa fa-fw fa-play', iconCls: 'fa fa-fw fa-play',
disabled: !suspended,
handler: function() { handler: function() {
vm_command('resume'); vm_command('resume');
} }
@ -72,6 +91,7 @@ Ext.define('PVE.qemu.CmdMenu', {
{ {
text: gettext('Shutdown'), text: gettext('Shutdown'),
iconCls: 'fa fa-fw fa-power-off', iconCls: 'fa fa-fw fa-power-off',
disabled: stopped || suspended,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('qmshutdown', vmid); var msg = PVE.Utils.format_task_description('qmshutdown', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
@ -86,6 +106,7 @@ Ext.define('PVE.qemu.CmdMenu', {
{ {
text: gettext('Stop'), text: gettext('Stop'),
iconCls: 'fa fa-fw fa-stop', iconCls: 'fa fa-fw fa-stop',
disabled: stopped,
handler: function() { handler: function() {
var msg = PVE.Utils.format_task_description('qmstop', vmid); var msg = PVE.Utils.format_task_description('qmstop', vmid);
Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {