[pve-devel] [PATCH manager 08/11] refactor OSDefaults, OSTypeEdit: add and use getDefaults

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Aug 29 12:08:31 CEST 2017


encapuslation wise it makes sense to have a helper which assembles a
os specific setting object in the OSDefaults class, where those
settings are defined.

Else we always need to check if the current OSType on the user side
of this class, which is against encapsulation.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

new in this version

 www/manager6/qemu/OSDefaults.js |  8 ++++++++
 www/manager6/qemu/OSTypeEdit.js | 30 ++++++++++++------------------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/www/manager6/qemu/OSDefaults.js b/www/manager6/qemu/OSDefaults.js
index 89d9c153..d47b9d01 100644
--- a/www/manager6/qemu/OSDefaults.js
+++ b/www/manager6/qemu/OSDefaults.js
@@ -73,5 +73,13 @@ Ext.define('PVE.qemu.OSDefaults', {
 	    pveOS: 'wxp',
 	    parent : 'w2k'
 	});
+
+	me.getDefaults = function(ostype) {
+	    if (PVE.qemu.OSDefaults[ostype]) {
+		return PVE.qemu.OSDefaults[ostype];
+	    } else {
+		return PVE.qemu.OSDefaults.generic;
+	    }
+	};
     }
 });
diff --git a/www/manager6/qemu/OSTypeEdit.js b/www/manager6/qemu/OSTypeEdit.js
index 162a92ec..14a1245b 100644
--- a/www/manager6/qemu/OSTypeEdit.js
+++ b/www/manager6/qemu/OSTypeEdit.js
@@ -8,26 +8,20 @@ Ext.define('PVE.qemu.OSTypeInputPanel', {
 	xclass: 'Ext.app.ViewController',
 	control: {
 	    'radiogroup': {
-		    change: function(field, value) {
-			var me = this;
-			if (!me.getView().insideWizard) {
-			    return;
-			}
-
-			var targetValues;
-
-			if (PVE.qemu.OSDefaults[value.ostype]) {
-			    targetValues = PVE.qemu.OSDefaults[value.ostype];
-			} else {
-			    targetValues = PVE.qemu.OSDefaults.generic;
-			}
-
-			me.setWidget('pveBusSelector', targetValues.busType);
-			me.setWidget('pveNetworkCardSelector', targetValues.networkCard);
-			me.setWizardHiddenValue('qemuScsiController', targetValues.scsihw);
-		    }
+		change: 'onOSTypeChange'
 	    }
 	},
+	onOSTypeChange: function(field) {
+	    var me = this, ostype = field.getValue();
+	    if (!me.getView().insideWizard) {
+		return;
+	    }
+	    var targetValues = PVE.qemu.OSDefaults.getDefaults(ostype);
+
+	    me.setWidget('pveBusSelector', targetValues.busType);
+	    me.setWidget('pveNetworkCardSelector', targetValues.networkCard);
+	    me.setWizardHiddenValue('qemuScsiController', targetValues.scsihw);
+	},
 	setWidget: function(widget, newValue) {
 	    // changing a widget is safe only if ComponentQuery.query returns us
 	    // a single value array
-- 
2.11.0




More information about the pve-devel mailing list