]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/ProcessorEdit.js
use IntegerField from widget toolkit
[pve-manager.git] / www / manager6 / qemu / ProcessorEdit.js
1 Ext.define('PVE.qemu.ProcessorInputPanel', {
2 extend: 'PVE.panel.InputPanel',
3 alias: 'widget.pveQemuProcessorPanel',
4 onlineHelp: 'qm_cpu',
5
6 insideWizard: false,
7
8 // defines the possible cpu flags and their labels
9 flagsAvail: ['pcid', 'spec-ctrl'],
10 flagLabels: ['PCID', 'SPEC-CTRL'],
11
12 onGetValues: function(values) {
13 var me = this;
14
15 // build the cpu options:
16 me.cpu.cputype = values.cputype;
17
18 var flags = [];
19
20 me.flagsAvail.forEach(function(flag) {
21 if (values[flag]) {
22 flags.push('+' + flag.toString());
23 }
24 delete values[flag];
25 });
26
27 me.cpu.flags = flags.length ? flags.join(';') : undefined;
28
29 delete values.cputype;
30 delete values.flags;
31 var cpustring = PVE.Parser.printQemuCpu(me.cpu);
32
33 // remove cputype delete request:
34 var del = values['delete'];
35 delete values['delete'];
36 if (del) {
37 del = del.split(',');
38 Ext.Array.remove(del, 'cputype');
39 } else {
40 del = [];
41 }
42
43 if (cpustring) {
44 values.cpu = cpustring;
45 } else {
46 del.push('cpu');
47 }
48
49 var delarr = del.join(',');
50 if (delarr) {
51 values['delete'] = delarr;
52 }
53
54 return values;
55 },
56
57 initComponent : function() {
58 var me = this;
59
60 me.cpu = {};
61
62 me.column1 = [
63 {
64 xtype: 'proxmoxintegerfield',
65 name: 'sockets',
66 minValue: 1,
67 maxValue: 4,
68 value: '1',
69 fieldLabel: gettext('Sockets'),
70 allowBlank: false,
71 listeners: {
72 change: function(f, value) {
73 var sockets = me.down('field[name=sockets]').getValue();
74 var cores = me.down('field[name=cores]').getValue();
75 me.down('field[name=totalcores]').setValue(sockets*cores);
76 }
77 }
78 },
79 {
80 xtype: 'proxmoxintegerfield',
81 name: 'cores',
82 minValue: 1,
83 maxValue: 128,
84 value: '1',
85 fieldLabel: gettext('Cores'),
86 allowBlank: false,
87 listeners: {
88 change: function(f, value) {
89 var sockets = me.down('field[name=sockets]').getValue();
90 var cores = me.down('field[name=cores]').getValue();
91 me.down('field[name=totalcores]').setValue(sockets*cores);
92 }
93 }
94 },
95 {
96 xtype: 'pvecheckbox',
97 fieldLabel: gettext('Enable NUMA'),
98 name: 'numa',
99 uncheckedValue: 0
100 }
101
102 ];
103
104
105 me.column2 = [
106 {
107 xtype: 'CPUModelSelector',
108 name: 'cputype',
109 value: '__default__',
110 fieldLabel: gettext('Type')
111 },
112 {
113 xtype: 'displayfield',
114 fieldLabel: gettext('Total cores'),
115 name: 'totalcores',
116 value: '1'
117 }
118 ];
119
120 me.flagsAvail.forEach(function(flag, i) {
121 me.column2.push({
122 hidden: me.insideWizard,
123 disabled: me.insideWizard,
124 xtype: 'pvecheckbox',
125 fieldLabel: me.flagLabels[i] || flag,
126 name: flag,
127 uncheckedValue: 0
128 });
129 });
130
131 me.callParent();
132 }
133 });
134
135 Ext.define('PVE.qemu.ProcessorEdit', {
136 extend: 'PVE.window.Edit',
137
138 initComponent : function() {
139 var me = this;
140
141 var ipanel = Ext.create('PVE.qemu.ProcessorInputPanel');
142
143 Ext.apply(me, {
144 subject: gettext('Processors'),
145 items: ipanel
146 });
147
148 me.callParent();
149
150 me.load({
151 success: function(response, options) {
152 var data = response.result.data;
153 var value = data.cpu;
154 if (value) {
155 var cpu = PVE.Parser.parseQemuCpu(value);
156 ipanel.cpu = cpu;
157 data.cputype = cpu.cputype;
158 if (cpu.flags) {
159 var flags = cpu.flags.split(';');
160 flags.forEach(function(flag) {
161 var sign = flag.substr(0,1);
162 flag = flag.substr(1);
163 data[flag] = (sign === '+');
164 });
165 }
166 }
167 me.setValues(data);
168 }
169 });
170 }
171 });