[pve-devel] [PATCH manager v2] ui: qemu: make DisplayEdit declarative and drop DisplaySelector

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Feb 9 13:08:07 CET 2018


DisplayEdit did not get a cleanup during our ExtJS 4 to ExtJS 6
cleanup, in fact it was really touched in the last 5 years.

So refactor it to a declarative syntax, at least almost, we keep the
me.load in initComponent, just to much hassle to adress this for now.

Also purge DisplaySelector. It was a component inheriting from
KVComboBox with the possible VGA values as items only used here.
So just use a KVComboBox directly and set comboboxItems directly.

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

changes v1 -> v2:
* no real semantic change, just ensure that gettext string does not
  have a line break, our gettext parser is not too intelligent to
  catch that.

 www/manager6/Makefile                |  1 -
 www/manager6/form/DisplaySelector.js |  5 ---
 www/manager6/qemu/DisplayEdit.js     | 59 +++++++++++++++---------------------
 3 files changed, 24 insertions(+), 41 deletions(-)
 delete mode 100644 www/manager6/form/DisplaySelector.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index aec62613..77449aa0 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -43,7 +43,6 @@ JSSRC= 				                 	\
 	form/IPProtocolSelector.js			\
 	form/CPUModelSelector.js			\
 	form/VNCKeyboardSelector.js			\
-	form/DisplaySelector.js				\
 	form/CacheTypeSelector.js			\
 	form/SnapshotSelector.js			\
 	form/ContentTypeSelector.js			\
diff --git a/www/manager6/form/DisplaySelector.js b/www/manager6/form/DisplaySelector.js
deleted file mode 100644
index 4b753e45..00000000
--- a/www/manager6/form/DisplaySelector.js
+++ /dev/null
@@ -1,5 +0,0 @@
-Ext.define('PVE.form.DisplaySelector', {
-    extend: 'Proxmox.form.KVComboBox',
-    alias: ['widget.DisplaySelector'],
-    comboItems: PVE.Utils.kvm_vga_driver_array()
-});
diff --git a/www/manager6/qemu/DisplayEdit.js b/www/manager6/qemu/DisplayEdit.js
index 00df0036..936521ae 100644
--- a/www/manager6/qemu/DisplayEdit.js
+++ b/www/manager6/qemu/DisplayEdit.js
@@ -3,47 +3,36 @@ Ext.define('PVE.qemu.DisplayEdit', {
 
     vmconfig: undefined,
 
+    subject: gettext('Display'),
+    width: 350,
+
+    items: [{
+	name: 'vga',
+	xtype: 'proxmoxKVComboBox',
+	value: '__default__',
+	fieldLabel: gettext('Graphic card'),
+	comboItems: PVE.Utils.kvm_vga_driver_array(),
+	validator: function() {
+	    var v = this.getValue();
+	    var cfg = this.up('proxmoxWindowEdit').vmconfig || {};
+
+	    if (v.match(/^serial\d+$/) && (!cfg[v] || cfg[v] !== 'socket')) {
+		var fmt = gettext("Serial interface '{0}' is not correctly configured.");
+		return Ext.String.format(fmt, v);
+	    }
+	    return true;
+	}
+    }],
+
     initComponent : function() {
 	var me = this;
 
-	var displayField;
-
-	var validateDisplay = function() {
-	    /*jslint confusion: true */
-	    var val = displayField.getValue();
-
-	    if (me.vmconfig && val.match(/^serial\d+$/)) {
-		if (me.vmconfig[val] && me.vmconfig[val] === 'socket') {
-		    return true;
-		}
-		return "Serial interface '" + val + "' is not correctly configured.";
-	    }
-	    
-	    return true;
-	};
-
-	displayField = Ext.createWidget('DisplaySelector', {  
-	    name: 'vga',
-	    value: '__default__',
-	    fieldLabel: gettext('Graphic card'),
-	    validator: validateDisplay
-	});
-
-	Ext.apply(me, {
-	    subject: gettext('Display'),
-	    width: 350,
-	    items: displayField
-	});
-
 	me.callParent();
 
 	me.load({
-	    success: function(response, options) {
-		var values = response.result.data;
-
-		me.vmconfig = values;
-
-		me.setValues(values);
+	    success: function(response) {
+		me.vmconfig = response.result.data;
+		me.setValues(me.vmconfig);
 	    }
 	});
     }
-- 
2.14.2





More information about the pve-devel mailing list