From 6654703de65cf8362bfb5637b0fea46c9a850cb8 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Sat, 20 Nov 2021 21:39:22 +0100 Subject: [PATCH] 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 --- src/form/BandwidthSelector.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/form/BandwidthSelector.js b/src/form/BandwidthSelector.js index d49cd52..069891c 100644 --- a/src/form/BandwidthSelector.js +++ b/src/form/BandwidthSelector.js @@ -29,6 +29,9 @@ Ext.define('Proxmox.form.SizeField', { // for KiB set it to 'KiB' backendUnit: undefined, + // submit a canonical size unit, e.g., 20.5 MiB + submitAutoScaledSizeUnit: false, + // allow setting 0 and using it as a submit value allowZero: false, @@ -55,6 +58,9 @@ Ext.define('Proxmox.form.SizeField', { let vm = fieldContainer.getViewModel(); let unit = vm.get('unit'); + if (typeof v === "string") { + v = Proxmox.Utils.size_unit_to_bytes(v); + } v /= Proxmox.Utils.SizeUnits[unit]; v *= fieldContainer.backendFactor; @@ -85,7 +91,11 @@ Ext.define('Proxmox.form.SizeField', { 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: { // our setValue gets only called if we have a value, avoid -- 2.39.2