mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-21 23:28:10 +00:00
bandwidth field: allow to submit auto-scaled size-units as string
opt-in to avoid breaking existing users and a bit of an experiment in general.. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
851ebc36cd
commit
6654703de6
@ -29,6 +29,9 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
// for KiB set it to 'KiB'
|
// for KiB set it to 'KiB'
|
||||||
backendUnit: undefined,
|
backendUnit: undefined,
|
||||||
|
|
||||||
|
// submit a canonical size unit, e.g., 20.5 MiB
|
||||||
|
submitAutoScaledSizeUnit: false,
|
||||||
|
|
||||||
// allow setting 0 and using it as a submit value
|
// allow setting 0 and using it as a submit value
|
||||||
allowZero: false,
|
allowZero: false,
|
||||||
|
|
||||||
@ -55,6 +58,9 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
let vm = fieldContainer.getViewModel();
|
let vm = fieldContainer.getViewModel();
|
||||||
let unit = vm.get('unit');
|
let unit = vm.get('unit');
|
||||||
|
|
||||||
|
if (typeof v === "string") {
|
||||||
|
v = Proxmox.Utils.size_unit_to_bytes(v);
|
||||||
|
}
|
||||||
v /= Proxmox.Utils.SizeUnits[unit];
|
v /= Proxmox.Utils.SizeUnits[unit];
|
||||||
v *= fieldContainer.backendFactor;
|
v *= fieldContainer.backendFactor;
|
||||||
|
|
||||||
@ -85,7 +91,11 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
|
|
||||||
v = parseFloat(v) * Proxmox.Utils.SizeUnits[unit];
|
v = parseFloat(v) * Proxmox.Utils.SizeUnits[unit];
|
||||||
|
|
||||||
return String(Math.floor(v / fieldContainer.backendFactor));
|
if (fieldContainer.submitAutoScaledSizeUnit) {
|
||||||
|
return Proxmox.Utils.format_size(v, !unit.endsWith('iB'));
|
||||||
|
} else {
|
||||||
|
return String(Math.floor(v / fieldContainer.backendFactor));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
listeners: {
|
listeners: {
|
||||||
// our setValue gets only called if we have a value, avoid
|
// our setValue gets only called if we have a value, avoid
|
||||||
|
Loading…
Reference in New Issue
Block a user