[pve-devel] [PATCH manager 06/17] add new DiskStorageSelector.js

Dominik Csapak d.csapak at proxmox.com
Wed Jul 19 15:45:18 CEST 2017


this is a wrapper for selecting a storage/disk image

it is a simple container with 4 form fields inside
which can be reused, whenever we need to select a storage for a disk,
image etc.

we have code similar to this four times already
(qemu image creation, lxc mp creation, qemu cloning, qemu efidisk
creation)

so it was time to refactor this and use the storage information from the
backend instead of hardcoding values in the frontend

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Makefile                    |   1 +
 www/manager6/form/DiskStorageSelector.js | 109 +++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 www/manager6/form/DiskStorageSelector.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 6c3efe0d..573beb57 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -50,6 +50,7 @@ JSSRC= 				                 	\
 	form/NodeSelector.js				\
 	form/FileSelector.js				\
 	form/StorageSelector.js				\
+	form/DiskStorageSelector.js			\
 	form/BridgeSelector.js				\
 	form/SecurityGroupSelector.js			\
 	form/IPRefSelector.js				\
diff --git a/www/manager6/form/DiskStorageSelector.js b/www/manager6/form/DiskStorageSelector.js
new file mode 100644
index 00000000..d1754b4c
--- /dev/null
+++ b/www/manager6/form/DiskStorageSelector.js
@@ -0,0 +1,109 @@
+Ext.define('PVE.form.DiskStorageSelector', {
+    extend: 'Ext.container.Container',
+    alias: 'widget.pveDiskStorageSelector',
+
+    layout: 'fit',
+    defaults: {
+	margin: '0 0 5 0'
+    },
+
+    changeStorage: function(f, value) {
+	var me = this;
+	var formatsel = me.getComponent('diskformat');
+	var hdfilesel = me.getComponent('hdimage');
+	var hdsizesel = me.getComponent('disksize');
+
+	// initial store load, and reset/deletion of the storage
+	if (!value) {
+	    hdfilesel.setDisabled(true);
+	    hdfilesel.setVisible(false);
+
+	    formatsel.setDisabled(true);
+	    return;
+	}
+
+	var rec = f.store.getById(value);
+	// if the storage is not defined, or valid,
+	// we cannot know what to enable/disable
+	if (!rec) {
+	    return;
+	}
+
+	var format = PVE.Utils.getStorageFormat(rec.data.type);
+
+	formatsel.setDisabled(format.formats.length === 1);
+	formatsel.setValue(format.formats.length === 1 ? 'raw' : 'qcow2');
+
+	hdfilesel.setDisabled(!format.select || me.hideSelection);
+	hdfilesel.setVisible(format.select && !me.hideSelection);
+	if (!me.hideSelection) {
+	    hdfilesel.setStorage(value);
+	}
+
+	hdsizesel.setDisabled(format.select || me.hideSize);
+	hdsizesel.setVisible(!format.select && !me.hideSize);
+    },
+
+    initComponent: function() {
+	var me = this;
+
+	me.items = [
+	    {
+		xtype: 'pveStorageSelector',
+		itemId: 'hdstorage',
+		name: 'hdstorage',
+		reference: 'hdstorage',
+		fieldLabel: me.storageLabel || gettext('Storage'),
+		nodename: me.nodename,
+		storageContent: me.storageContent,
+		autoSelect: me.autoSelect,
+		allowBlank: me.allowBlank,
+		emptyText: me.emptyText,
+		listeners: {
+		    change: {
+			fn: me.changeStorage,
+			scope: me
+		    }
+		}
+	    },
+	    {
+		xtype: 'pveFileSelector',
+		name: 'hdimage',
+		reference: 'hdimage',
+		itemId: 'hdimage',
+		fieldLabel: gettext('Disk image'),
+		nodename: me.nodename,
+		disabled: me.hideSelection,
+		hidden: me.hideSelection || true
+	    },
+	    {
+		xtype: 'numberfield',
+		itemId: 'disksize',
+		reference: 'disksize',
+		name: 'disksize',
+		fieldLabel: gettext('Disk size') + ' (GB)',
+		hidden: me.hideSize,
+		disabled: me.hideSize,
+		minValue: 0.001,
+		maxValue: 128*1024,
+		decimalPrecision: 3,
+		value: '32',
+		allowBlank: false
+	    },
+	    {
+		xtype: 'pveDiskFormatSelector',
+		itemId: 'diskformat',
+		reference: 'diskformat',
+		name: 'diskformat',
+		fieldLabel: gettext('Format'),
+		nodename: me.nodename,
+		disabled: true,
+		hidden: me.storageContent === 'rootdir',
+		value: 'qcow2',
+		allowBlank: false
+	    }
+	];
+
+	me.callParent();
+    }
+});
-- 
2.11.0





More information about the pve-devel mailing list