[pve-devel] [PATCH manager] refactor HDEdit form change handler

Dominik Csapak d.csapak at proxmox.com
Tue May 10 14:25:31 CEST 2016


the old method of doing this was ugly and error-prone,
now one can clearly see what the code does

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/qemu/HDEdit.js | 49 ++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/www/manager6/qemu/HDEdit.js b/www/manager6/qemu/HDEdit.js
index 36c9206..5543afa 100644
--- a/www/manager6/qemu/HDEdit.js
+++ b/www/manager6/qemu/HDEdit.js
@@ -31,35 +31,30 @@ Ext.define('PVE.qemu.HDInputPanel', {
 		    }
 		    var me = this.getView();
 		    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 === 'drbd' ||
-			       rec.data.type === 'rbd' ||
-			       rec.data.type === 'sheepdog' ||
-			       rec.data.type === 'zfs' ||
-			       rec.data.type === 'zfspool') {
-			me.hdfilesel.setDisabled(true);
-			me.hdfilesel.setVisible(false);
+		    var filesel = false;
+		    var sizesel = true;
+		    var formatsel = true;
+		    var rawArray = ['lvm', 'lvmthin', 'drbd', 'rbd', 'sheepdog', 'zfs', 'zfspool', 'iscsi'];
+		    me.formatsel.setValue('qcow2');
+
+		    if (rawArray.indexOf(rec.data.type) !== -1) {
 			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);
+			formatsel = false;
+			sizesel = true;
+			if (rec.data.type === 'iscsi') {
+			    me.hdfilesel.setStorage(value);
+			    sizesel = false;
+			    filesel = true;
+			}
 		    }
+
+		    me.hdsizesel.setVisible(sizesel);
+		    me.hdsizesel.setDisabled(!sizesel);
+
+		    me.formatsel.setDisabled(!formatsel);
+
+		    me.hdfilesel.setVisible(filesel);
+		    me.hdfilesel.setDisabled(!filesel);
 		}
 	    }
 	}
-- 
2.1.4





More information about the pve-devel mailing list