[pve-devel] [PATCH pve-manager 1/3] adapt KVComboBoxes to pass store items using 'comboItems' parameter

Emmanuel Kasper e.kasper at proxmox.com
Thu Mar 3 14:43:21 CET 2016


we used a custom 'data' property to pass around the items to
add to the store, but this property is now used by ExtJS to
store content for the component template

also move to declarative style, saves lines
---
 www/manager6/form/Boolean.js                | 17 +++-----
 www/manager6/form/BusTypeSelector.js        |  6 +--
 www/manager6/form/CPUModelSelector.js       | 65 +++++++++++++----------------
 www/manager6/form/CacheTypeSelector.js      | 23 ++++------
 www/manager6/form/ContentTypeSelector.js    |  4 +-
 www/manager6/form/DiskFormatSelector.js     | 17 +++-----
 www/manager6/form/DisplaySelector.js        |  8 +---
 www/manager6/form/HotplugFeatureSelector.js | 18 +++-----
 www/manager6/form/NetworkCardSelector.js    | 19 +++------
 www/manager6/form/ScsiHwSelector.js         | 25 ++++-------
 www/manager6/form/iScsiProviderSelector.js  | 17 +++-----
 11 files changed, 78 insertions(+), 141 deletions(-)

diff --git a/www/manager6/form/Boolean.js b/www/manager6/form/Boolean.js
index f4f2c4a..37f794b 100644
--- a/www/manager6/form/Boolean.js
+++ b/www/manager6/form/Boolean.js
@@ -2,16 +2,9 @@
 Ext.define('PVE.form.Boolean', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.booleanfield'],
-  
-    initComponent: function() {
-	var me = this;
-
-	me.data = [
-	    ['__default__', gettext('Default')],
-	    [1, gettext('Yes')],
-	    [0, gettext('No')]
-	];
-
-	me.callParent();
-    }
+    comboItems: [
+	['__default__', gettext('Default')],
+	[1, gettext('Yes')],
+	[0, gettext('No')]
+    ]
 });
diff --git a/www/manager6/form/BusTypeSelector.js b/www/manager6/form/BusTypeSelector.js
index 00f8281..acb8f74 100644
--- a/www/manager6/form/BusTypeSelector.js
+++ b/www/manager6/form/BusTypeSelector.js
@@ -9,14 +9,14 @@ Ext.define('PVE.form.BusTypeSelector', {
     initComponent: function() {
 	var me = this;
 
-	me.data = [['ide', 'IDE'], ['sata', 'SATA']];
+	me.comboItems = [['ide', 'IDE'], ['sata', 'SATA']];
 
 	if (!me.noVirtIO) {
-	    me.data.push(['virtio', 'VIRTIO']);
+	    me.comboItems.push(['virtio', 'VIRTIO']);
 	}
 
 	if (!me.noScsi) {
-	    me.data.push(['scsi', 'SCSI']);
+	    me.comboItems.push(['scsi', 'SCSI']);
 	}
 
 	me.callParent();
diff --git a/www/manager6/form/CPUModelSelector.js b/www/manager6/form/CPUModelSelector.js
index 5b84e2b..3995874 100644
--- a/www/manager6/form/CPUModelSelector.js
+++ b/www/manager6/form/CPUModelSelector.js
@@ -1,40 +1,33 @@
 Ext.define('PVE.form.CPUModelSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.CPUModelSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-        me.data = [ 
-	    ['__default__', PVE.Utils.defaultText + ' (kvm64)'],
-	    ['486', '486'],
-	    ['athlon', 'athlon'],
-	    ['core2duo', 'core2duo'],
-	    ['coreduo', 'coreduo'],
-	    ['kvm32', 'kvm32'],
-	    ['kvm64', 'kvm64'],
-	    ['pentium', 'pentium'],
-	    ['pentium2', 'pentium2'],
-	    ['pentium3', 'pentium3'],
-	    ['phenom', 'phenom'],
-	    ['qemu32', 'qemu32'],
-	    ['qemu64', 'qemu64'],
-	    ['Conroe', 'Conroe'],
-	    ['Penryn', 'Penryn'],
-	    ['Nehalem', 'Nehalem'],
-	    ['Westmere', 'Westmere'],
-	    ['SandyBridge', 'SandyBridge'],
-	    ['IvyBridge', 'IvyBridge'],
-	    ['Haswell', 'Haswell'],
-	    ['Broadwell', 'Broadwell'],
-	    ['Opteron_G1', 'Opteron_G1'],
-	    ['Opteron_G2', 'Opteron_G2'],
-	    ['Opteron_G3', 'Opteron_G3'],
-	    ['Opteron_G4', 'Opteron_G4'],
-	    ['Opteron_G5', 'Opteron_G5'],
-	    ['host', 'host']
-	];
-
-	me.callParent();
-    }
+    comboItems: [
+	['__default__', PVE.Utils.defaultText + ' (kvm64)'],
+	['486', '486'],
+	['athlon', 'athlon'],
+	['core2duo', 'core2duo'],
+	['coreduo', 'coreduo'],
+	['kvm32', 'kvm32'],
+	['kvm64', 'kvm64'],
+	['pentium', 'pentium'],
+	['pentium2', 'pentium2'],
+	['pentium3', 'pentium3'],
+	['phenom', 'phenom'],
+	['qemu32', 'qemu32'],
+	['qemu64', 'qemu64'],
+	['Conroe', 'Conroe'],
+	['Penryn', 'Penryn'],
+	['Nehalem', 'Nehalem'],
+	['Westmere', 'Westmere'],
+	['SandyBridge', 'SandyBridge'],
+	['IvyBridge', 'IvyBridge'],
+	['Haswell', 'Haswell'],
+	['Broadwell', 'Broadwell'],
+	['Opteron_G1', 'Opteron_G1'],
+	['Opteron_G2', 'Opteron_G2'],
+	['Opteron_G3', 'Opteron_G3'],
+	['Opteron_G4', 'Opteron_G4'],
+	['Opteron_G5', 'Opteron_G5'],
+	['host', 'host']
+    ]
 });
diff --git a/www/manager6/form/CacheTypeSelector.js b/www/manager6/form/CacheTypeSelector.js
index 40a7e84..f9d39bf 100644
--- a/www/manager6/form/CacheTypeSelector.js
+++ b/www/manager6/form/CacheTypeSelector.js
@@ -1,19 +1,12 @@
 Ext.define('PVE.form.CacheTypeSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.CacheTypeSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-	me.data = [
-	    ['__default__', PVE.Utils.defaultText + " (" + gettext('No cache') + ")"],
-	    ['directsync', 'Direct sync'],
-	    ['writethrough', 'Write through'],
-	    ['writeback', 'Write back'],
-	    ['unsafe', 'Write back (' + gettext('unsafe') + ')'],
-	    ['none', gettext('No cache')]
-	];
-
-	me.callParent();
-    }
+    comboItems: [
+	['__default__', PVE.Utils.defaultText + " (" + gettext('No cache') + ")"],
+	['directsync', 'Direct sync'],
+	['writethrough', 'Write through'],
+	['writeback', 'Write back'],
+	['unsafe', 'Write back (' + gettext('unsafe') + ')'],
+	['none', gettext('No cache')]
+    ],
 });
diff --git a/www/manager6/form/ContentTypeSelector.js b/www/manager6/form/ContentTypeSelector.js
index 0c74524..3c8b4bd 100644
--- a/www/manager6/form/ContentTypeSelector.js
+++ b/www/manager6/form/ContentTypeSelector.js
@@ -7,14 +7,14 @@ Ext.define('PVE.form.ContentTypeSelector', {
     initComponent: function() {
 	var me = this;
 
-	me.data = [];
+	me.comboItems = [];
 
 	if (me.cts === undefined) {
 	    me.cts = ['images', 'iso', 'vztmpl', 'backup', 'rootdir'];
 	}
 
 	Ext.Array.each(me.cts, function(ct) {
-	    me.data.push([ct, PVE.Utils.format_content_types(ct)]);
+	    me.comboItem.push([ct, PVE.Utils.format_content_types(ct)]);
 	});
 
 	me.callParent();
diff --git a/www/manager6/form/DiskFormatSelector.js b/www/manager6/form/DiskFormatSelector.js
index 30de6ec..c2a24e5 100644
--- a/www/manager6/form/DiskFormatSelector.js
+++ b/www/manager6/form/DiskFormatSelector.js
@@ -1,16 +1,9 @@
 Ext.define('PVE.form.DiskFormatSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.PVE.form.DiskFormatSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-        me.data = [ 
-	    ['raw', gettext('Raw disk image') + ' (raw)'], 
-	    ['qcow2', gettext('QEMU image format') + ' (qcow2)'],
-	    ['vmdk', gettext('VMware image format') + ' (vmdk)']
-	];
-
-	me.callParent();
-    }
+    comboItems:  [
+	['raw', gettext('Raw disk image') + ' (raw)'],
+	['qcow2', gettext('QEMU image format') + ' (qcow2)'],
+	['vmdk', gettext('VMware image format') + ' (vmdk)']
+    ]
 });
diff --git a/www/manager6/form/DisplaySelector.js b/www/manager6/form/DisplaySelector.js
index 755d059..d5ab30a 100644
--- a/www/manager6/form/DisplaySelector.js
+++ b/www/manager6/form/DisplaySelector.js
@@ -1,11 +1,5 @@
 Ext.define('PVE.form.DisplaySelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.DisplaySelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-	me.data = PVE.Utils.kvm_vga_driver_array();
-	me.callParent();
-    }
+    comboItems: PVE.Utils.kvm_vga_driver_array()
 });
diff --git a/www/manager6/form/HotplugFeatureSelector.js b/www/manager6/form/HotplugFeatureSelector.js
index e0dac4b..2277155 100644
--- a/www/manager6/form/HotplugFeatureSelector.js
+++ b/www/manager6/form/HotplugFeatureSelector.js
@@ -5,6 +5,11 @@ Ext.define('PVE.form.HotplugFeatureSelector', {
     multiSelect: true,
     allowBlank: true,
     deleteEmpty: false,
+    comboItems: [['disk', gettext('Disk')],
+	['network',  gettext('Network')],
+	['usb',  gettext('USB')],
+	['memory',  gettext('Memory')],
+	['cpu',  gettext('CPU')]],
 
     setValue: function(value, doSelect) {
 	var me = this;
@@ -41,17 +46,4 @@ Ext.define('PVE.form.HotplugFeatureSelector', {
         }
         return data;
     },
-
-  
-    initComponent: function() {
-	var me = this;
-
-	me.data = [['disk', gettext('Disk')], 
-		   ['network',  gettext('Network')], 
-		   ['usb',  gettext('USB')],
-		   ['memory',  gettext('Memory')],
-		   ['cpu',  gettext('CPU')]];
-	
-	me.callParent();
-    }
 });
diff --git a/www/manager6/form/NetworkCardSelector.js b/www/manager6/form/NetworkCardSelector.js
index 6e5ef93..94f41a0 100644
--- a/www/manager6/form/NetworkCardSelector.js
+++ b/www/manager6/form/NetworkCardSelector.js
@@ -1,17 +1,10 @@
 Ext.define('PVE.form.NetworkCardSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.PVE.form.NetworkCardSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-        me.data = [ 
-	    ['e1000', 'Intel E1000'],
-	    ['virtio', 'VirtIO (' + gettext('paravirtualized') + ')'],
-	    ['rtl8139', 'Realtek RTL8139'],
-	    ['vmxnet3', 'VMWare vmxnet3']
-	];
- 
-	me.callParent();
-    }
+    comboItems: [
+	['e1000', 'Intel E1000'],
+	['virtio', 'VirtIO (' + gettext('paravirtualized') + ')'],
+	['rtl8139', 'Realtek RTL8139'],
+	['vmxnet3', 'VMWare vmxnet3']
+    ]
 });
diff --git a/www/manager6/form/ScsiHwSelector.js b/www/manager6/form/ScsiHwSelector.js
index aafee7d..c681b57 100644
--- a/www/manager6/form/ScsiHwSelector.js
+++ b/www/manager6/form/ScsiHwSelector.js
@@ -1,20 +1,13 @@
 Ext.define('PVE.form.ScsiHwSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.pveScsiHwSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-        me.data = [ 
-	    ['__default__', PVE.Utils.render_scsihw('')],
-	    ['lsi', PVE.Utils.render_scsihw('lsi')],
-	    ['lsi53c810', PVE.Utils.render_scsihw('lsi53c810')],
-	    ['megasas', PVE.Utils.render_scsihw('megasas')],
-	    ['virtio-scsi-pci', PVE.Utils.render_scsihw('virtio-scsi-pci')],
-	    ['virtio-scsi-single', PVE.Utils.render_scsihw('virtio-scsi-single')],
-	    ['pvscsi', PVE.Utils.render_scsihw('pvscsi')]
-	];
-
-	me.callParent();
-    }
+    comboItems: [
+	['__default__', PVE.Utils.render_scsihw('')],
+	['lsi', PVE.Utils.render_scsihw('lsi')],
+	['lsi53c810', PVE.Utils.render_scsihw('lsi53c810')],
+	['megasas', PVE.Utils.render_scsihw('megasas')],
+	['virtio-scsi-pci', PVE.Utils.render_scsihw('virtio-scsi-pci')],
+	['virtio-scsi-single', PVE.Utils.render_scsihw('virtio-scsi-single')],
+	['pvscsi', PVE.Utils.render_scsihw('pvscsi')]
+    ]
 });
diff --git a/www/manager6/form/iScsiProviderSelector.js b/www/manager6/form/iScsiProviderSelector.js
index 9ea34a1..ca1de9f 100644
--- a/www/manager6/form/iScsiProviderSelector.js
+++ b/www/manager6/form/iScsiProviderSelector.js
@@ -1,16 +1,9 @@
 Ext.define('PVE.form.iScsiProviderSelector', {
     extend: 'PVE.form.KVComboBox',
     alias: ['widget.pveiScsiProviderSelector'],
-  
-    initComponent: function() {
-	var me = this;
-
-	me.data = [
-	    ['comstar', 'Comstar'],
-	    [ 'istgt', 'istgt'],
-	    [ 'iet', 'IET']
-	];
-
-	me.callParent();
-    }
+    comboItems: [
+	['comstar', 'Comstar'],
+	[ 'istgt', 'istgt'],
+	[ 'iet', 'IET']
+    ]
 });
-- 
2.1.4





More information about the pve-devel mailing list