[pve-devel] [PATCH pve-manager 2/3] ext6migrate: set valueField as a class property

Emmanuel Kasper e.kasper at proxmox.com
Mon Feb 15 09:22:59 CET 2016


Also moves to full declarative style for
IPProtocolSelector, saves 11 lines of of boilerplate code
(works when the store is local and not pulled over the API)
---
 www/manager6/form/IPProtocolSelector.js | 69 ++++++++++++++-------------------
 www/manager6/grid/FirewallRules.js      | 39 +++++++++----------
 2 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/www/manager6/form/IPProtocolSelector.js b/www/manager6/form/IPProtocolSelector.js
index 55a95d9..af166fc 100644
--- a/www/manager6/form/IPProtocolSelector.js
+++ b/www/manager6/form/IPProtocolSelector.js
@@ -1,11 +1,34 @@
 Ext.define('PVE.form.IPProtocolSelector', {
     extend: 'PVE.form.ComboGrid',
     alias: ['widget.pveIPProtocolSelector'],
-
-    initComponent: function() {
-	var me = this;
-	
- 	var store = Ext.create('Ext.data.Store', {
+    valueField: 'p',
+    displayField: 'p',
+    listConfig: {
+	columns: [
+	    {
+		header: gettext('Protocol'),
+		dataIndex: 'p',
+		hideable: false,
+		sortable: false,
+		width: 100
+	    },
+	    {
+		header: gettext('Number'),
+		dataIndex: 'n',
+		hideable: false,
+		sortable: false,
+		width: 50
+	    },
+	    {
+		header: gettext('Description'),
+		dataIndex: 'd',
+		hideable: false,
+		sortable: false,
+		flex: 1
+	    }
+	]
+    },
+    store: {
 	    fields: [ 'p', 'd', 'n'],
 	    data: [
 		{ p: 'tcp', n: 6, d: 'Transmission Control Protocol' },
@@ -60,39 +83,5 @@ Ext.define('PVE.form.IPProtocolSelector', {
 		{ p: 'wesp', n: 141, d: 'Wrapped Encapsulating Security Payload' },
 		{ p: 'rohc', n: 142, d: 'Robust Header Compression' }
 	    ]
-	});
-
-	Ext.apply(me, {
-	    store: store,
-	    valueField: 'p',
-	    displayField: 'p',
-            listConfig: {
-		columns: [
-		    {
-			header: gettext('Protocol'),
-			dataIndex: 'p',
-			hideable: false,
-			sortable: false,
-			width: 100
-		    },
-		    {
-			header: gettext('Number'),
-			dataIndex: 'n',
-			hideable: false,
-			sortable: false,
-			width: 50
-		    },
-		    {
-			header: gettext('Description'),
-			dataIndex: 'd',
-			hideable: false,
-			sortable: false,
-			flex: 1
-		    }
-		]
-	    }
-	});
-
-        me.callParent();
-    }
+	}
 });
diff --git a/www/manager6/grid/FirewallRules.js b/www/manager6/grid/FirewallRules.js
index ab3207b..371fc41 100644
--- a/www/manager6/grid/FirewallRules.js
+++ b/www/manager6/grid/FirewallRules.js
@@ -1,7 +1,25 @@
 Ext.define('PVE.form.FWMacroSelector', {
     extend: 'PVE.form.ComboGrid',
     alias: 'widget.pveFWMacroSelector',
-
+    allowBlank: true,
+    autoSelect: false,
+    valueField: 'macro',
+    displayField: 'macro',
+    listConfig: {
+	columns: [
+	    {
+		header: gettext('Macro'),
+		dataIndex: 'macro',
+		hideable: false,
+		width: 100
+	    },
+	    {
+		header: gettext('Description'),
+		flex: 1,
+		dataIndex: 'descr'
+	    }
+	]
+    },
     initComponent: function() {
 	var me = this;
 
@@ -21,25 +39,6 @@ Ext.define('PVE.form.FWMacroSelector', {
 
 	Ext.apply(me, {
 	    store: store,
-	    allowBlank: true,
-	    autoSelect: false,
-	    valueField: 'macro',
-	    displayField: 'macro',
-            listConfig: {
-		columns: [
-		    {
-			header: gettext('Macro'),
-			dataIndex: 'macro',
-			hideable: false,
-			width: 100
-		    },
-		    {
-			header: gettext('Description'),
-			flex: 1,
-			dataIndex: 'descr'
-		    }
-		]
-	    }
 	});
 
 	me.callParent();
-- 
2.1.4





More information about the pve-devel mailing list