Commit e4d2abe5 authored by Alexandre Derumier's avatar Alexandre Derumier Committed by Dietmar Maurer

memory form : hotplug improvements

we need to change memory field step dynamically, and also map values to dimm size.

Fixme : apply same behaviour for maxmemory field
Signed-off-by: 's avatarAlexandre Derumier <aderumier@odiso.com>
parent 388e9fc5
......@@ -111,6 +111,9 @@ Ext.define('PVE.qemu.HardwareView', {
},
balloon: {
visible: false
},
hotplug: {
visible: false
}
};
......@@ -216,6 +219,7 @@ Ext.define('PVE.qemu.HardwareView', {
var win = Ext.create(editor, {
pveSelNode: me.pveSelNode,
confid: rec.data.key,
hotplug: me.getObjectValue('hotplug'),
url: '/api2/extjs/' + baseurl
});
......
......@@ -29,9 +29,10 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
initComponent : function() {
var me = this;
var labelWidth = 160;
var hotplug = me.hotplug;
var items = [
{
xtype: 'radiofield',
......@@ -55,13 +56,94 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
xtype: 'numberfield',
name: 'memory',
minValue: 32,
maxValue: 512*1024,
maxValue: 4096*1024,
value: '512',
step: 32,
fieldLabel: gettext('Memory') + ' (MB)',
labelAlign: 'right',
labelWidth: labelWidth,
allowBlank: false
allowBlank: false,
listeners: {
change: function(f, value, oldvalue) {
var me = this;
if(!hotplug) {
return;
}
//fill an array with dimms size
var dimmarray = new Array (255);
var dimm_size = 512;
var current_size = 1024;
var i;
var j;
var dimm_id = 0;
for (j = 0; j < 8; j++) {
for (i = 0; i < 32; i++) {
dimmarray[dimm_id] = current_size;
current_size += dimm_size;
dimm_id++;
}
dimm_size *= 2;
}
//find nearest value in array
var k = 0, closest, closestDiff, currentDiff
closest = dimmarray[0];
for(k; k < dimmarray.length;k++) {
closestDiff = Math.abs(value - closest);
currentDiff = Math.abs(value - dimmarray[k]);
if(currentDiff < closestDiff) {
closest = dimmarray[k];
}
closestDiff = null;
currentDiff = null;
}
if(value != closest){
value = closest;
}
f.setValue(value);
//dynamic step
if(value > oldvalue) {
if(value < 16384) {
me.step = 512;
} else if(value >= 16384 && value < 49152) {
me.step = 1024;
} else if (value >= 49152 && value < 114688) {
me.step = 2048;
} else if (value >= 114688 && value < 245760) {
me.step = 4096;
} else if (value >= 245760 && value < 507904) {
me.step = 8192;
} else if (value >= 507904 && value < 1032192) {
me.step = 16384;
} else if (value >= 1032192 && value < 2080768) {
me.step = 32768;
} else if (value >= 2080768 && value < 4177920) {
me.step = 65536;
}
} else if (value < oldvalue) {
if(value <= 16384) {
me.step = 512;
} else if(value > 16384 && value <= 49152) {
me.step = 1024;
} else if (value > 49152 && value <= 114688) {
me.step = 2048;
} else if (value > 114688 && value <= 245760) {
me.step = 4096;
} else if (value > 245760 && value <= 507904) {
me.step = 8192;
} else if (value > 507904 && value <= 1032192) {
me.step = 16384;
} else if (value > 1032192 && value <= 2080768) {
me.step = 32768;
} else if (value > 2080768 && value <= 4177920) {
me.step = 65536;
}
}
}
}
},
{
xtype: 'radiofield',
......@@ -126,7 +208,7 @@ Ext.define('PVE.qemu.MemoryInputPanel', {
allowBlank: true,
emptyText: PVE.Utils.defaultText + ' (1000)',
submitEmptyText: false
}
},
];
if (me.insideWizard) {
......@@ -144,10 +226,23 @@ Ext.define('PVE.qemu.MemoryEdit', {
initComponent : function() {
var me = this;
var memoryhotplug;
if(me.hotplug) {
Ext.each(me.hotplug.split(','), function(el) {
if (el === 'memory') {
memoryhotplug = 1;
}
});
}
var ipanel = Ext.create('PVE.qemu.MemoryInputPanel', {
hotplug: memoryhotplug,
});
Ext.apply(me, {
subject: gettext('Memory'),
items: [ Ext.create('PVE.qemu.MemoryInputPanel') ],
items: ipanel,
// uncomment the following to use the async configiguration API
// backgroundDelay: 5,
width: 400
......@@ -164,11 +259,10 @@ Ext.define('PVE.qemu.MemoryEdit', {
maxmemory: data.memory,
balloon: data.balloon,
shares: data.shares,
memoryType: data.balloon ? 'dynamic' : 'fixed'
memoryType: data.balloon ? 'dynamic' : 'fixed',
};
me.setValues(values);
ipanel.setValues(values);
}
});
}
});
\ No newline at end of file
});
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