]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/lxc/Config.js
ui: eslint: fix various spacing related issues
[pve-manager.git] / www / manager6 / lxc / Config.js
index fbaccefea40d4100c12ec2f3082e21d9c178569d..1becc687af01b9a726b6a75e0485079a202f593e 100644 (file)
@@ -6,80 +6,85 @@ Ext.define('PVE.lxc.Config', {
 
     initComponent: function() {
         var me = this;
+       var vm = me.pveSelNode.data;
 
-       var nodename = me.pveSelNode.data.node;
+       var nodename = vm.node;
        if (!nodename) {
            throw "no node name specified";
        }
 
-       var vmid = me.pveSelNode.data.vmid;
+       var vmid = vm.vmid;
        if (!vmid) {
            throw "no VM ID specified";
        }
 
-       var template = me.pveSelNode.data.template;
+       var template = !!vm.template;
+
+       var running = !!vm.uptime;
 
        var caps = Ext.state.Manager.get('GuiCap');
 
        var base_url = '/nodes/' + nodename + '/lxc/' + vmid;
 
-       me.statusStore = Ext.create('PVE.data.ObjectStore', {
+       me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
            url: '/api2/json' + base_url + '/status/current',
-           interval: 1000
+           interval: 1000,
        });
 
        var vm_command = function(cmd, params) {
-           PVE.Utils.API2Request({
+           Proxmox.Utils.API2Request({
                params: params,
                url: base_url + "/status/" + cmd,
                waitMsgTarget: me,
                method: 'POST',
                failure: function(response, opts) {
                    Ext.Msg.alert('Error', response.htmlStatus);
-               }
+               },
            });
        };
 
        var startBtn = Ext.create('Ext.Button', {
            text: gettext('Start'),
-           disabled: !caps.vms['VM.PowerMgmt'],
+           disabled: !caps.vms['VM.PowerMgmt'] || running,
+           hidden: template,
            handler: function() {
                vm_command('start');
            },
-           iconCls: 'fa fa-play'
-       });
-
-       var umountBtn = Ext.create('Ext.Button', {
-           text: gettext('Unmount'),
-           disabled: true,
-           hidden: true,
-           handler: function() {
-               vm_command('umount');
-           }
-       });
-
-       var stopBtn = Ext.create('Ext.menu.Item',{
-           text: gettext('Stop'),
-           disabled: !caps.vms['VM.PowerMgmt'],
-           confirmMsg: PVE.Utils.format_task_description('vzstop', vmid),
-           dangerous: true,
-           handler: function() {
-               vm_command("stop");
-           },
-           iconCls: 'fa fa-stop'
+           iconCls: 'fa fa-play',
        });
 
        var shutdownBtn = Ext.create('PVE.button.Split', {
            text: gettext('Shutdown'),
-           disabled: !caps.vms['VM.PowerMgmt'],
-           confirmMsg: PVE.Utils.format_task_description('vzshutdown', vmid),
+           disabled: !caps.vms['VM.PowerMgmt'] || !running,
+           hidden: template,
+           confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
            handler: function() {
                vm_command('shutdown');
            },
            menu: {
-               items:[stopBtn]
+               items: [{
+                   text: gettext('Reboot'),
+                   disabled: !caps.vms['VM.PowerMgmt'],
+                   confirmMsg: Proxmox.Utils.format_task_description('vzreboot', vmid),
+                   tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
+                   handler: function() {
+                       vm_command("reboot");
+                   },
+                   iconCls: 'fa fa-refresh',
+               },
+               {
+                   text: gettext('Stop'),
+                   disabled: !caps.vms['VM.PowerMgmt'],
+                   confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid),
+                   tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
+                   dangerous: true,
+                   handler: function() {
+                       vm_command("stop");
+                   },
+                   iconCls: 'fa fa-stop',
+               }],
            },
-           iconCls: 'fa fa-power-off'
+           iconCls: 'fa fa-power-off',
        });
 
        var migrateBtn = Ext.create('Ext.Button', {
@@ -90,64 +95,122 @@ Ext.define('PVE.lxc.Config', {
                var win = Ext.create('PVE.window.Migrate', {
                    vmtype: 'lxc',
                    nodename: nodename,
-                   vmid: vmid
+                   vmid: vmid,
                });
                win.show();
            },
-           iconCls: 'fa fa-send-o'
+           iconCls: 'fa fa-send-o',
        });
 
-       var removeBtn = Ext.create('PVE.button.Button', {
-           text: gettext('Remove'),
-           disabled: !caps.vms['VM.Allocate'],
-           handler: function() {
-               Ext.create('PVE.window.SafeDestroy', {
-                   url: base_url,
-                   item: { type: 'CT', id: vmid }
-               }).show();
-           },
-           iconCls: 'fa fa-trash-o'
+       var moreBtn = Ext.create('Proxmox.button.Button', {
+           text: gettext('More'),
+           menu: {
+ items: [
+               {
+                   text: gettext('Clone'),
+                   iconCls: 'fa fa-fw fa-clone',
+                   hidden: caps.vms['VM.Clone'] ? false : true,
+                   handler: function() {
+                       PVE.window.Clone.wrap(nodename, vmid, template, 'lxc');
+                   },
+               },
+               {
+                   text: gettext('Convert to template'),
+                   disabled: template,
+                   xtype: 'pveMenuItem',
+                   iconCls: 'fa fa-fw fa-file-o',
+                   hidden: caps.vms['VM.Allocate'] ? false : true,
+                   confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
+                   handler: function() {
+                       Proxmox.Utils.API2Request({
+                           url: base_url + '/template',
+                           waitMsgTarget: me,
+                           method: 'POST',
+                           failure: function(response, opts) {
+                               Ext.Msg.alert('Error', response.htmlStatus);
+                           },
+                       });
+                   },
+               },
+               {
+                   iconCls: 'fa fa-heartbeat ',
+                   hidden: !caps.nodes['Sys.Console'],
+                   text: gettext('Manage HA'),
+                   handler: function() {
+                       var ha = vm.hastate;
+                       Ext.create('PVE.ha.VMResourceEdit', {
+                           vmid: vmid,
+                           guestType: 'ct',
+                           isCreate: (!ha || ha === 'unmanaged'),
+                       }).show();
+                   },
+               },
+               {
+                   text: gettext('Remove'),
+                   disabled: !caps.vms['VM.Allocate'],
+                   itemId: 'removeBtn',
+                   handler: function() {
+                       Ext.create('PVE.window.SafeDestroy', {
+                           url: base_url,
+                           item: { type: 'CT', id: vmid },
+                       }).show();
+                   },
+                   iconCls: 'fa fa-trash-o',
+               },
+           ]
+},
        });
 
-       var vmname = me.pveSelNode.data.name;
-
        var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
            disabled: !caps.vms['VM.Console'],
            consoleType: 'lxc',
-           consoleName: vmname,
+           consoleName: vm.name,
+           hidden: template,
            nodename: nodename,
            vmid: vmid,
-           iconCls: 'fa fa-terminal'
        });
 
-       var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")";
+       var statusTxt = Ext.create('Ext.toolbar.TextItem', {
+           data: {
+               lock: undefined,
+           },
+           tpl: [
+               '<tpl if="lock">',
+               '<i class="fa fa-lg fa-lock"></i> ({lock})',
+               '</tpl>',
+           ],
+       });
+
 
        Ext.apply(me, {
-           title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"),
+           title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
            hstateid: 'lxctab',
-           tbar: [ startBtn, shutdownBtn, umountBtn, removeBtn,
-                   migrateBtn, consoleBtn ],
+           tbarSpacing: false,
+           tbar: [statusTxt, '->', startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn],
            defaults: { statusStore: me.statusStore },
            items: [
                {
                    title: gettext('Summary'),
-                   xtype: 'pveLxcSummary',
+                   xtype: 'pveGuestSummary',
                    iconCls: 'fa fa-book',
-                   itemId: 'summary'
-               }
-           ]
+                   itemId: 'summary',
+               },
+           ],
        });
 
-       if (caps.vms['VM.Console']) {
-           me.items.push({
-               title: gettext('Console'),
-               itemId: 'console',
-               iconCls: 'fa fa-terminal',
-               xtype: 'pveNoVncConsole',
-               vmid: vmid,
-               consoleType: 'lxc',
-               nodename: nodename
-           });
+       if (caps.vms['VM.Console'] && !template) {
+           me.items.push(
+               {
+                   title: gettext('Console'),
+                   itemId: 'consolejs',
+                   iconCls: 'fa fa-terminal',
+                   xtype: 'pveNoVncConsole',
+                   vmid: vmid,
+                   consoleType: 'lxc',
+                   xtermjs: true,
+                   nodename: nodename,
+               },
+           );
        }
 
        me.items.push(
@@ -156,33 +219,34 @@ Ext.define('PVE.lxc.Config', {
                itemId: 'resources',
                expandedOnInit: true,
                iconCls: 'fa fa-cube',
-               xtype: 'pveLxcRessourceView'
+               xtype: 'pveLxcRessourceView',
            },
            {
                title: gettext('Network'),
                iconCls: 'fa fa-exchange',
                itemId: 'network',
-               xtype: 'pveLxcNetworkView'
+               xtype: 'pveLxcNetworkView',
            },
            {
                title: gettext('DNS'),
                iconCls: 'fa fa-globe',
                itemId: 'dns',
-               xtype: 'pveLxcDNS'
+               xtype: 'pveLxcDNS',
            },
            {
                title: gettext('Options'),
                itemId: 'options',
                iconCls: 'fa fa-gear',
-               xtype: 'pveLxcOptions'
+               xtype: 'pveLxcOptions',
            },
            {
                title: gettext('Task History'),
                itemId: 'tasks',
                iconCls: 'fa fa-list',
-               xtype: 'pveNodeTasks',
-               vmidFilter: vmid
-           }
+               xtype: 'proxmoxNodeTasks',
+               nodename: nodename,
+               vmidFilter: vmid,
+           },
        );
 
        if (caps.vms['VM.Backup']) {
@@ -190,22 +254,24 @@ Ext.define('PVE.lxc.Config', {
                title: gettext('Backup'),
                iconCls: 'fa fa-floppy-o',
                xtype: 'pveBackupView',
-               itemId: 'backup'
+               itemId: 'backup',
            },
            {
                title: gettext('Replication'),
                iconCls: 'fa fa-retweet',
                xtype: 'pveReplicaView',
-               itemId: 'replication'
+               itemId: 'replication',
            });
        }
 
-       if (caps.vms['VM.Snapshot']) {
+       if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
+           caps.vms['VM.Audit']) && !template) {
            me.items.push({
                title: gettext('Snapshots'),
                iconCls: 'fa fa-history',
-               xtype: 'pveLxcSnapshotTree',
-               itemId: 'snapshot'
+               xtype: 'pveGuestSnapshotTree',
+               type: 'lxc',
+               itemId: 'snapshot',
            });
        }
 
@@ -218,7 +284,7 @@ Ext.define('PVE.lxc.Config', {
                    allow_iface: true,
                    base_url: base_url + '/firewall/rules',
                    list_refs_url: base_url + '/firewall/refs',
-                   itemId: 'firewall'
+                   itemId: 'firewall',
                },
                {
                    xtype: 'pveFirewallOptions',
@@ -228,7 +294,7 @@ Ext.define('PVE.lxc.Config', {
                    title: gettext('Options'),
                    base_url: base_url + '/firewall/options',
                    fwtype: 'vm',
-                   itemId: 'firewall-options'
+                   itemId: 'firewall-options',
                },
                {
                    xtype: 'pveFirewallAliases',
@@ -236,7 +302,7 @@ Ext.define('PVE.lxc.Config', {
                    groups: ['firewall'],
                    iconCls: 'fa fa-external-link',
                    base_url: base_url + '/firewall/aliases',
-                   itemId: 'firewall-aliases'
+                   itemId: 'firewall-aliases',
                },
                {
                    xtype: 'pveIPSet',
@@ -245,7 +311,7 @@ Ext.define('PVE.lxc.Config', {
                    iconCls: 'fa fa-list-ol',
                    base_url: base_url + '/firewall/ipset',
                    list_refs_url: base_url + '/firewall/refs',
-                   itemId: 'firewall-ipset'
+                   itemId: 'firewall-ipset',
                },
                {
                    title: gettext('Log'),
@@ -253,9 +319,9 @@ Ext.define('PVE.lxc.Config', {
                    iconCls: 'fa fa-list',
                    onlineHelp: 'chapter_pve_firewall',
                    itemId: 'firewall-fwlog',
-                   xtype: 'pveLogView',
-                   url: '/api2/extjs' + base_url + '/firewall/log'
-               }
+                   xtype: 'proxmoxLogView',
+                   url: '/api2/extjs' + base_url + '/firewall/log',
+               },
            );
        }
 
@@ -265,14 +331,16 @@ Ext.define('PVE.lxc.Config', {
                title: gettext('Permissions'),
                itemId: 'permissions',
                iconCls: 'fa fa-unlock',
-               path: '/vms/' + vmid
+               path: '/vms/' + vmid,
            });
        }
 
        me.callParent();
 
+       var prevStatus = 'unknown';
        me.mon(me.statusStore, 'load', function(s, records, success) {
            var status;
+           var lock;
            if (!success) {
                status = 'unknown';
            } else {
@@ -280,22 +348,25 @@ Ext.define('PVE.lxc.Config', {
                status = rec ? rec.data.value : 'unknown';
                rec = s.data.get('template');
                template = rec.data.value || false;
+               rec = s.data.get('lock');
+               lock = rec ? rec.data.value : undefined;
            }
+
+           statusTxt.update({ lock: lock });
+
            startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
            shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
-           stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
-           removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
+           me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
            consoleBtn.setDisabled(template);
 
-           if (status === 'mounted') {
-               umountBtn.setDisabled(false);
-               umountBtn.setVisible(true);
-               stopBtn.setDisabled(true);
-           } else {
-               umountBtn.setDisabled(true);
-               umountBtn.setVisible(false);
-               stopBtn.setDisabled(false);
+           if (prevStatus === 'stopped' && status === 'running') {
+               let con = me.down('#consolejs');
+               if (con) {
+                   con.reload();
+               }
            }
+
+           prevStatus = status;
        });
 
        me.on('afterrender', function() {
@@ -305,5 +376,5 @@ Ext.define('PVE.lxc.Config', {
        me.on('destroy', function() {
            me.statusStore.stopUpdate();
        });
-    }
+    },
 });