[pve-devel] [PATCH v10 manager 04/19] ui: disk storage selector: add setSize function

Fabian Ebner f.ebner at proxmox.com
Wed Apr 6 10:04:01 CEST 2022


In preparation for disk import from an existing volume.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 www/manager6/form/DiskStorageSelector.js | 25 +++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/www/manager6/form/DiskStorageSelector.js b/www/manager6/form/DiskStorageSelector.js
index ac6b064f..9699938e 100644
--- a/www/manager6/form/DiskStorageSelector.js
+++ b/www/manager6/form/DiskStorageSelector.js
@@ -25,8 +25,10 @@ Ext.define('PVE.form.DiskStorageSelector', {
     // hideSelection is not true
     hideSelection: undefined,
 
-    // hides the size field (e.g, for the efi disk dialog)
+    // hides and disables the size field (e.g, for the efi disk dialog)
     hideSize: false,
+    // disables the size field (e.g. when importing from existing volume)
+    disableSize: false,
 
     // hides the format field (e.g. for TPM state), always assumes 'raw'
     hideFormat: false,
@@ -75,7 +77,7 @@ Ext.define('PVE.form.DiskStorageSelector', {
 	    hdfilesel.setStorage(value);
 	}
 
-	hdsizesel.setDisabled(select || me.hideSize);
+	hdsizesel.setDisabled(select || me.hideSize || me.disableSize);
 	hdsizesel.setVisible(!select && !me.hideSize);
     },
 
@@ -103,6 +105,23 @@ Ext.define('PVE.form.DiskStorageSelector', {
 	hdstorage.fireEvent('validitychange');
     },
 
+    setSize: function(size, fixed) {
+	let me = this;
+	let sizeField = me.getComponent('disksize');
+
+	me.disableSize = fixed;
+	// For import, size 0 shouldn't show as invalid, so disable first.
+	sizeField.setDisabled(fixed);
+
+	if (size === undefined || size === null) {
+	    size = me.defaultSize;
+	} else {
+	    size = size / Proxmox.Utils.SizeUnits.GiB;
+	}
+
+	sizeField.setValue(size);
+    },
+
     initComponent: function() {
 	var me = this;
 
@@ -143,7 +162,7 @@ Ext.define('PVE.form.DiskStorageSelector', {
 		name: 'disksize',
 		fieldLabel: gettext('Disk size') + ' (GiB)',
 		hidden: me.hideSize,
-		disabled: me.hideSize,
+		disabled: me.hideSize || me.disableSize,
 		minValue: 0.001,
 		maxValue: 128*1024,
 		decimalPrecision: 3,
-- 
2.30.2






More information about the pve-devel mailing list