]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager/openvz/Config.js
fix bug #115: simplify GUI for users without permissions
[pve-manager.git] / www / manager / openvz / Config.js
index 4f013af2087c3a7e7559f8db96088073c3f5f36e..dcd7552eafe561636f585673612c973262cc68be 100644 (file)
@@ -15,6 +15,8 @@ Ext.define('PVE.openvz.Config', {
            throw "no VM ID specified";
        }
 
+       var caps = Ext.state.Manager.get('GuiCap');
+
        me.statusStore = Ext.create('PVE.data.ObjectStore', {
            url: "/api2/json/nodes/" + nodename + "/openvz/" + vmid + "/status/current",
            interval: 1000
@@ -34,29 +36,42 @@ Ext.define('PVE.openvz.Config', {
 
        var startBtn = Ext.create('Ext.Button', { 
            text: gettext('Start'),
+           disabled: !caps.vms['VM.PowerMgmt'],
            handler: function() {
                vm_command('start');
            }                       
        }); 
+
+       var umountBtn = Ext.create('Ext.Button', { 
+           text: gettext('Unmount'),
+           disabled: true,
+           hidden: true,
+           handler: function() {
+               vm_command('umount');
+           }                       
+       }); 
  
        var stopBtn = Ext.create('PVE.button.Button', {
            text: gettext('Stop'),
+           disabled: !caps.vms['VM.PowerMgmt'],
            confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid),
            handler: function() {
-               vm_command("stop", { fast: 1 });
+               vm_command("stop");
            }
        });
  
        var shutdownBtn = Ext.create('PVE.button.Button', {
            text: gettext('Shutdown'),
+           disabled: !caps.vms['VM.PowerMgmt'],
            confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid),
            handler: function() {
-               vm_command('stop');
+               vm_command('shutdown');
            }                       
        });
  
        var migrateBtn = Ext.create('Ext.Button', { 
            text: gettext('Migrate'),
+           disabled: !caps.vms['VM.Migrate'],
            handler: function() {
                var win = Ext.create('PVE.window.Migrate', { 
                    vmtype: 'openvz',
@@ -69,6 +84,7 @@ Ext.define('PVE.openvz.Config', {
 
        var removeBtn = Ext.create('PVE.button.Button', {
            text: gettext('Remove'),
+           disabled: !caps.vms['VM.Allocate'],
            confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
            handler: function() {
                PVE.Utils.API2Request({
@@ -82,21 +98,23 @@ Ext.define('PVE.openvz.Config', {
            }
        });
 
+       var vmname = me.pveSelNode.data.name;
+
        var consoleBtn = Ext.create('Ext.Button', {
            text: gettext('Console'),
+           disabled: !caps.vms['VM.Console'],
            handler: function() {
-               PVE.Utils.openConoleWindow('openvz', vmid, nodename);
+               PVE.Utils.openConoleWindow('openvz', vmid, nodename, vmname);
            }
        });
 
-       var vmname = me.pveSelNode.data.name;
        var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")";
 
        Ext.apply(me, {
            title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"),
            hstateid: 'ovztab',
-           tbar: [ startBtn, stopBtn, shutdownBtn, migrateBtn, 
-                   removeBtn, consoleBtn ],
+           tbar: [ startBtn, shutdownBtn, umountBtn, stopBtn, removeBtn, 
+                   migrateBtn, consoleBtn ],
            defaults: { statusStore: me.statusStore },
            items: [
                {
@@ -129,27 +147,37 @@ Ext.define('PVE.openvz.Config', {
                    itemId: 'ubc',
                    xtype: 'pveBeanCounterGrid',
                    url: '/api2/json/nodes/' + nodename + '/openvz/' + vmid + '/status/ubc'
-               },
-               {
-                   title: "InitLog",
-                   itemId: 'initlog',
-                   xtype: 'pveLogView',
-                   url: '/api2/extjs/nodes/' + nodename + '/openvz/' + vmid + '/initlog'
-               },
-               {
-                   title: gettext('Backup'),
-                   xtype: 'pveBackupView',
-                   itemId: 'backup'
-               },
-               {
-                   title: gettext('Permissions'),
-                   itemId: 'permissions',
-                   html: 'permissions ' + vmid
                }
-
            ]
        });
 
+
+       if (caps.vms['VM.Console']) {
+           me.items.push({
+               title: "InitLog",
+               itemId: 'initlog',
+               xtype: 'pveLogView',
+               url: '/api2/extjs/nodes/' + nodename + '/openvz/' + vmid + '/initlog'
+           });
+       }
+
+       if (caps.vms['VM.Backup']) {
+           me.items.push({
+               title: gettext('Backup'),
+               xtype: 'pveBackupView',
+               itemId: 'backup'
+           });
+       }
+
+       if (caps.vms['Permissions.Modify']) {
+           me.items.push({
+               xtype: 'pveACLView',
+               title: gettext('Permissions'),
+               itemId: 'permissions',
+               path: '/vms/' + vmid
+           });
+       }
+
        me.callParent();
 
        me.statusStore.on('load', function(s, records, success) {
@@ -161,10 +189,20 @@ Ext.define('PVE.openvz.Config', {
                var rec = s.data.get('status');
                status = rec ? rec.data.value : 'unknown';
            }
-           startBtn.setDisabled(status === 'running');
-           shutdownBtn.setDisabled(status !== 'running');
-           stopBtn.setDisabled(status === 'stopped');
-           removeBtn.setDisabled(status !== 'stopped');
+           startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running');
+           shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
+           stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
+           removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
+
+           if (status === 'mounted') {
+               umountBtn.setDisabled(false);
+               umountBtn.setVisible(true);
+               stopBtn.setVisible(false);
+           } else {
+               umountBtn.setDisabled(true);
+               umountBtn.setVisible(false);
+               stopBtn.setVisible(true);
+           }
        });
 
        me.on('afterrender', function() {