[pve-devel] [PATCH manager 1/4] qemu: factor out storage selector creation for later reuse

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Feb 22 14:33:39 CET 2016


---
 www/manager/qemu/HDEdit.js | 152 +++++++++++++++++++++++----------------------
 1 file changed, 79 insertions(+), 73 deletions(-)

diff --git a/www/manager/qemu/HDEdit.js b/www/manager/qemu/HDEdit.js
index b8ca4e5..9677b83 100644
--- a/www/manager/qemu/HDEdit.js
+++ b/www/manager/qemu/HDEdit.js
@@ -1,3 +1,81 @@
+Ext.define('PVE.HDStorage', { statics: {
+    addStorageSelector: function(me, to, with_format) {
+	me.formatsel = Ext.create('PVE.form.DiskFormatSelector', {
+	    name: 'diskformat',
+	    fieldLabel: gettext('Format'),
+	    value: 'qcow2',
+	    allowBlank: false,
+	    hidden: !with_format,
+	});
+
+	me.hdfilesel = Ext.create('PVE.form.FileSelector', {
+	    name: 'hdimage',
+	    nodename: me.nodename,
+	    storageContent: 'images',
+	    fieldLabel: gettext('Disk image'),
+	    disabled: true,
+	    hidden: true,
+	    allowBlank: false
+	});
+
+	me.hdsizesel = Ext.createWidget('numberfield', {
+	    name: 'disksize',
+	    minValue: 0.001,
+	    maxValue: 128*1024,
+	    decimalPrecision: 3,
+	    value: '32',
+	    fieldLabel: gettext('Disk size') + ' (GB)',
+	    allowBlank: false
+	});
+
+	me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
+	    name: 'hdstorage',
+	    nodename: me.nodename,
+	    fieldLabel: gettext('Storage'),
+	    storageContent: 'images',
+	    autoSelect: me.insideWizard,
+	    allowBlank: false,
+	    listeners: {
+		change: function(f, value) {
+		    var rec = f.store.getById(value);
+		    if (rec.data.type === 'iscsi') {
+			me.hdfilesel.setStorage(value);
+			me.hdfilesel.setDisabled(false);
+			me.formatsel.setValue('raw');
+			me.formatsel.setDisabled(true);
+			me.hdfilesel.setVisible(true);
+			me.hdsizesel.setDisabled(true);
+			me.hdsizesel.setVisible(false);
+		    } else if (rec.data.type === 'lvm' ||
+			       rec.data.type === 'lvmthin' ||
+			       rec.data.type === 'rbd' ||
+			       rec.data.type === 'sheepdog' ||
+			       rec.data.type === 'zfs' ||
+			       rec.data.type === 'zfspool') {
+			me.hdfilesel.setDisabled(true);
+			me.hdfilesel.setVisible(false);
+			me.formatsel.setValue('raw');
+			me.formatsel.setDisabled(true);
+			me.hdsizesel.setDisabled(false);
+			me.hdsizesel.setVisible(true);
+		    } else {
+			me.hdfilesel.setDisabled(true);
+			me.hdfilesel.setVisible(false);
+			me.formatsel.setValue('qcow2');
+			me.formatsel.setDisabled(false);
+			me.hdsizesel.setDisabled(false);
+			me.hdsizesel.setVisible(true);
+		    }
+		}
+	    }
+	});
+	to.push(me.hdstoragesel);
+	to.push(me.hdfilesel);
+	to.push(me.hdsizesel);
+	to.push(me.formatsel);
+    }
+}});
+
 // fixme: howto avoid jslint type confusion?
 /*jslint confusion: true */
 Ext.define('PVE.qemu.HDInputPanel', {
@@ -133,79 +211,7 @@ Ext.define('PVE.qemu.HDInputPanel', {
 	    });
 	    me.column1.push(me.unusedDisks);
 	} else if (me.create) {
-	    me.formatsel = Ext.create('PVE.form.DiskFormatSelector', {
-		name: 'diskformat',
-		fieldLabel: gettext('Format'),
-		value: 'qcow2',
-		allowBlank: false
-	    });
-
-	    me.hdfilesel = Ext.create('PVE.form.FileSelector', {
-		name: 'hdimage',
-		nodename: me.nodename,
-		storageContent: 'images',
-		fieldLabel: gettext('Disk image'),
-		disabled: true,
-		hidden: true,
-		allowBlank: false
-	    });
-
-	    me.hdsizesel = Ext.createWidget('numberfield', {
-		name: 'disksize',
-		minValue: 0.001,
-		maxValue: 128*1024,
-		decimalPrecision: 3,
-		value: '32',
-		fieldLabel: gettext('Disk size') + ' (GB)',
-		allowBlank: false
-	    });
-
-	    me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
-		name: 'hdstorage',
-		nodename: me.nodename,
-		fieldLabel: gettext('Storage'),
-		storageContent: 'images',
-		autoSelect: me.insideWizard,
-		allowBlank: false,
-		listeners: {
-		    change: function(f, value) {
-			var rec = f.store.getById(value);
-			if (rec.data.type === 'iscsi') {
-			    me.hdfilesel.setStorage(value);
-			    me.hdfilesel.setDisabled(false);
-			    me.formatsel.setValue('raw');
-			    me.formatsel.setDisabled(true);
-			    me.hdfilesel.setVisible(true);
-			    me.hdsizesel.setDisabled(true);
-			    me.hdsizesel.setVisible(false);
-			} else if (rec.data.type === 'lvm' ||
-				   rec.data.type === 'lvmthin' ||
-				   rec.data.type === 'rbd' ||
-				   rec.data.type === 'sheepdog' ||
-				   rec.data.type === 'zfs' ||
-				   rec.data.type === 'zfspool') {
-			    me.hdfilesel.setDisabled(true);
-			    me.hdfilesel.setVisible(false);
-			    me.formatsel.setValue('raw');
-			    me.formatsel.setDisabled(true);
-			    me.hdsizesel.setDisabled(false);
-			    me.hdsizesel.setVisible(true);
-			} else {
-			    me.hdfilesel.setDisabled(true);
-			    me.hdfilesel.setVisible(false);
-			    me.formatsel.setValue('qcow2');
-			    me.formatsel.setDisabled(false);
-			    me.hdsizesel.setDisabled(false);
-			    me.hdsizesel.setVisible(true);
-			}			
-		    }
-		}
-	    });
-	    me.column1.push(me.hdstoragesel);
-	    me.column1.push(me.hdfilesel);
-	    me.column1.push(me.hdsizesel);
-	    me.column1.push(me.formatsel);
-
+	    PVE.HDStorage.addStorageSelector(me, me.column1, true);
 	} else {
 	    me.column1.push({
 		xtype: 'textfield',
-- 
2.1.4





More information about the pve-devel mailing list