Commit 5ef6d7e0 authored by Dietmar Maurer's avatar Dietmar Maurer

implement pveMemoryField

parent 1fb3e9b1
......@@ -33,6 +33,7 @@ JSSRC= \
form/UserSelector.js \
form/RoleSelector.js \
form/VMIDSelector.js \
form/MemoryField.js \
form/NetworkCardSelector.js \
form/DiskFormatSelector.js \
form/BusTypeSelector.js \
......
Ext.define('PVE.form.MemoryField', {
extend: 'Ext.form.field.Number',
alias: 'widget.pveMemoryField',
allowBlank: false,
hotplug: false,
minValue: 32,
maxValue: 4178944,
step: 32,
value: '512', // qm default
computeUpDown: function(value) {
var me = this;
if (!me.hotplug) {
return { up: value + me.step, down: value - me.step };
}
var dimm_size = 512;
var prev_dimm_size = 0;
var min_size = 1024;
var current_size = min_size;
var value_up = min_size;
var value_down = min_size;
var i, j;
for (j = 0; j < 9; j++) {
for (i = 0; i < 32; i++) {
if ((value >= current_size) && (value < (current_size + dimm_size))) {
value_up = current_size + dimm_size;
value_down = current_size - ((i === 0) ? prev_dimm_size : dimm_size);
}
current_size += dimm_size;
}
prev_dimm_size = dimm_size;
dimm_size = dimm_size*2;
}
return { up: value_up, down: value_down };
},
onSpinUp: function() {
var me = this;
if (!me.readOnly) {
var res = me.computeUpDown(me.getValue());
me.setValue(Ext.Number.constrain(res.up, me.minValue, me.maxValue));
}
},
onSpinDown: function() {
var me = this;
if (!me.readOnly) {
var res = me.computeUpDown(me.getValue());
me.setValue(Ext.Number.constrain(res.down, me.minValue, me.maxValue));
}
},
initComponent: function() {
var me = this;
if (me.hotplug) {
me.minValue = 1024;
}
me.callParent();
}
});
......@@ -51,60 +51,12 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
}
},
{
xtype: 'numberfield',
xtype: 'pveMemoryField',
name: 'memory',
hotplug: me.hotplug,
minValue: me.hotplug ? 1024 : 32,
maxValue: 4178944,
value: me.hotplug ? '1024' : '512',
step: 32,
fieldLabel: gettext('Memory') + ' (MB)',
labelAlign: 'right',
labelWidth: labelWidth,
allowBlank: false,
computeUpDown: function(value) {
var me = this;
if (!me.hotplug) {
return { up: value + me.step, down: value - me.step };
}
var dimm_size = 512;
var prev_dimm_size = 0;
var min_size = 1024;
var current_size = min_size;
var value_up = min_size;
var value_down = min_size;
var i, j;
for (j = 0; j < 9; j++) {
for (i = 0; i < 32; i++) {
if ((value >= current_size) && (value < (current_size + dimm_size))) {
value_up = current_size + dimm_size;
value_down = current_size - ((i === 0) ? prev_dimm_size : dimm_size);
}
current_size += dimm_size;
}
prev_dimm_size = dimm_size;
dimm_size = dimm_size*2;
}
return { up: value_up, down: value_down };
},
onSpinUp: function() {
var me = this;
if (!me.readOnly) {
var res = me.computeUpDown(me.getValue());
me.setValue(Ext.Number.constrain(res.up, me.minValue, me.maxValue));
}
},
onSpinDown: function() {
var me = this;
if (!me.readOnly) {
var res = me.computeUpDown(me.getValue());
me.setValue(Ext.Number.constrain(res.down, me.minValue, me.maxValue));
}
}
},
{
xtype: 'radiofield',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment