]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/qemu/ProcessorEdit.js
ui: eslint: fix various spacing related issues
[pve-manager.git] / www / manager6 / qemu / ProcessorEdit.js
index 3ecea205bd79eff3c70a0e06d7b1f6bb3b5225a7..5dffbe7a0853c0d158c4d65dd25440c318e7ffb5 100644 (file)
@@ -5,28 +5,19 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 
     insideWizard: false,
 
-    controller: {
-       xclass: 'Ext.app.ViewController',
-
-       updateCores: function() {
-           var me = this.getView();
-           var sockets = me.down('field[name=sockets]').getValue();
-           var cores = me.down('field[name=cores]').getValue();
-           me.down('field[name=totalcores]').setValue(sockets*cores);
-           var vcpus = me.down('field[name=vcpus]');
-           vcpus.setMaxValue(sockets*cores);
-           vcpus.setEmptyText(sockets*cores);
-           vcpus.validate();
+    viewModel: {
+       data: {
+           socketCount: 1,
+           coreCount: 1,
+           showCustomModelPermWarning: false,
+       },
+       formulas: {
+           totalCoreCount: get => get('socketCount') * get('coreCount'),
        },
+    },
 
-       control: {
-           'field[name=sockets]': {
-               change: 'updateCores'
-           },
-           'field[name=cores]': {
-               change: 'updateCores'
-           }
-       }
+    controller: {
+       xclass: 'Ext.app.ViewController',
     },
 
     onGetValues: function(values) {
@@ -42,16 +33,11 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
        // build the cpu options:
        me.cpu.cputype = values.cputype;
 
-       var flags = [];
-
-       ['pcid', 'spec-ctrl'].forEach(function(flag) {
-           if (values[flag]) {
-               flags.push('+' + flag.toString());
-           }
-           delete values[flag];
-       });
-
-       me.cpu.flags = flags.length ? flags.join(';') : undefined;
+       if (values.flags) {
+           me.cpu.flags = values.flags;
+       } else {
+           delete me.cpu.flags;
+       }
 
        delete values.cputype;
        delete values.flags;
@@ -81,6 +67,33 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
        return values;
     },
 
+    setValues: function(values) {
+       let me = this;
+
+       let type = values.cputype;
+       let typeSelector = me.lookupReference('cputype');
+       let typeStore = typeSelector.getStore();
+       typeStore.on('load', (store, records, success) => {
+           if (!success || !type || records.some(x => x.data.name === type)) {
+               return;
+           }
+
+           // if we get here, a custom CPU model is selected for the VM but we
+           // don't have permission to configure it - it will not be in the
+           // list retrieved from the API, so add it manually to allow changing
+           // other processor options
+           typeStore.add({
+               name: type,
+               displayname: type.replace(/^custom-/, ''),
+               custom: 1,
+               vendor: gettext("Unknown"),
+           });
+           typeSelector.select(type);
+       });
+
+       me.callParent([values]);
+    },
+
     cpu: {},
 
     column1: [
@@ -91,7 +104,10 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
            maxValue: 4,
            value: '1',
            fieldLabel: gettext('Sockets'),
-           allowBlank: false
+           allowBlank: false,
+           bind: {
+               value: '{socketCount}',
+           },
        },
        {
            xtype: 'proxmoxintegerfield',
@@ -100,23 +116,41 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
            maxValue: 128,
            value: '1',
            fieldLabel: gettext('Cores'),
-           allowBlank: false
-       }
+           allowBlank: false,
+           bind: {
+               value: '{coreCount}',
+           },
+       },
     ],
 
     column2: [
        {
            xtype: 'CPUModelSelector',
            name: 'cputype',
-           value: '__default__',
-           fieldLabel: gettext('Type')
+           reference: 'cputype',
+           fieldLabel: gettext('Type'),
        },
        {
            xtype: 'displayfield',
            fieldLabel: gettext('Total cores'),
            name: 'totalcores',
-           value: '1'
-       }
+           isFormField: false,
+           bind: {
+               value: '{totalCoreCount}',
+           },
+       },
+    ],
+
+    columnB: [
+       {
+           xtype: 'displayfield',
+           userCls: 'pmx-hint',
+           value: gettext('WARNING: You do not have permission to configure custom CPU types, if you change the type you will not be able to go back!'),
+           hidden: true,
+           bind: {
+               hidden: '{!showCustomModelPermWarning}',
+           },
+       },
     ],
 
     advancedColumn1: [
@@ -124,11 +158,16 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
            xtype: 'proxmoxintegerfield',
            name: 'vcpus',
            minValue: 1,
+           maxValue: 1,
            value: '',
            fieldLabel: gettext('VCPUs'),
            deleteEmpty: true,
            allowBlank: true,
-           emptyText: '1'
+           emptyText: '1',
+           bind: {
+               emptyText: '{totalCoreCount}',
+               maxValue: '{totalCoreCount}',
+           },
        },
        {
            xtype: 'numberfield',
@@ -139,8 +178,11 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
            step: 1,
            fieldLabel: gettext('CPU limit'),
            allowBlank: true,
-           emptyText: gettext('unlimited')
+           emptyText: gettext('unlimited'),
        },
+    ],
+
+    advancedColumn2: [
        {
            xtype: 'proxmoxintegerfield',
            name: 'cpuunits',
@@ -149,43 +191,40 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
            maxValue: 500000,
            value: '1024',
            deleteEmpty: true,
-           allowBlank: true
-       }
-    ],
-
-    advancedColumn2: [
+           allowBlank: true,
+       },
        {
            xtype: 'proxmoxcheckbox',
            fieldLabel: gettext('Enable NUMA'),
            name: 'numa',
-           uncheckedValue: 0
+           uncheckedValue: 0,
        },
+    ],
+    advancedColumnB: [
        {
-           xtype: 'proxmoxcheckbox',
-           fieldLabel: 'PCID',
-           name: 'pcid',
-           uncheckedValue: 0
+           xtype: 'label',
+           text: 'Extra CPU Flags:',
        },
        {
-           xtype: 'proxmoxcheckbox',
-           fieldLabel: 'SPEC-CTRL',
-           name: 'spec-ctrl',
-           uncheckedValue: 0
-       }
-    ]
+           xtype: 'vmcpuflagselector',
+           name: 'flags',
+       },
+    ],
 });
 
 Ext.define('PVE.qemu.ProcessorEdit', {
     extend: 'Proxmox.window.Edit',
 
-    initComponent : function() {
+    width: 700,
+
+    initComponent: function() {
        var me = this;
 
        var ipanel = Ext.create('PVE.qemu.ProcessorInputPanel');
 
        Ext.apply(me, {
            subject: gettext('Processors'),
-           items: ipanel
+           items: ipanel,
        });
 
        me.callParent();
@@ -199,16 +238,18 @@ Ext.define('PVE.qemu.ProcessorEdit', {
                    ipanel.cpu = cpu;
                    data.cputype = cpu.cputype;
                    if (cpu.flags) {
-                       var flags = cpu.flags.split(';');
-                       flags.forEach(function(flag) {
-                           var sign = flag.substr(0,1);
-                           flag = flag.substr(1);
-                           data[flag] = (sign === '+');
-                       });
+                       data.flags = cpu.flags;
+                   }
+
+                   let caps = Ext.state.Manager.get('GuiCap');
+                   if (data.cputype.indexOf('custom-') === 0 &&
+                       !caps.nodes['Sys.Audit']) {
+                       let vm = ipanel.getViewModel();
+                       vm.set("showCustomModelPermWarning", true);
                    }
                }
                me.setValues(data);
-           }
+           },
        });
-    }
+    },
 });