[pve-devel] [PATCH widget-toolkit 2/3] node network: refactor bond mode array generation

Dominik Csapak d.csapak at proxmox.com
Wed Jul 10 11:30:51 CEST 2019


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 Utils.js                 | 23 +++++++++++++++++++++++
 form/BondModeSelector.js | 30 +++++++++++++++---------------
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/Utils.js b/Utils.js
index 7a78fda..929de6e 100644
--- a/Utils.js
+++ b/Utils.js
@@ -99,6 +99,29 @@ Ext.define('Proxmox.Utils', { utilities: {
 	return data;
     },
 
+    bond_mode_gettext_map: {
+	'802.3ad': 'LACP (802.3ad)',
+	'lacp-balance-slb': 'LACP (balance-slb)',
+	'lacp-balance-tcp': 'LACP (balance-tcp)',
+    },
+
+    render_bond_mode: function(value) {
+	var val = Proxmox.Utils.bond_mode_gettext_map[value];
+	if (!val) {
+	    val = value || '';
+	}
+	return val;
+    },
+
+    bond_mode_array: function(modes) {
+	var arr = [];
+	var i;
+	for (i = 0; i < modes.length; i++) {
+	    arr.push([modes[i], Proxmox.Utils.render_bond_mode(modes[i])]);
+	}
+	return arr;
+    },
+
     getNoSubKeyHtml: function(url) {
 	// url http://www.proxmox.com/products/proxmox-ve/subscription-service-plans
 	return Ext.String.format('You do not have a valid subscription for this server. Please visit <a target="_blank" href="{0}">www.proxmox.com</a> to get a list of available options.', url || 'https://www.proxmox.com');
diff --git a/form/BondModeSelector.js b/form/BondModeSelector.js
index 8781ebc..26c2747 100644
--- a/form/BondModeSelector.js
+++ b/form/BondModeSelector.js
@@ -8,22 +8,22 @@ Ext.define('Proxmox.form.BondModeSelector', {
 	var me = this;
 
 	if (me.openvswitch) {
-           me.comboItems = [
-	       ['active-backup', 'active-backup'],
-	       ['balance-slb', 'balance-slb'],
-	       ['lacp-balance-slb', 'LACP (balance-slb)'],
-	       ['lacp-balance-tcp', 'LACP (balance-tcp)']
-	   ];
+	    me.comboItems = Proxmox.Utils.bond_mode_array([
+	       'active-backup',
+	       'balance-slb',
+	       'lacp-balance-slb',
+	       'lacp-balance-tcp',
+	    ]);
 	} else {
-            me.comboItems = [
-		['balance-rr', 'balance-rr'],
-		['active-backup', 'active-backup'],
-		['balance-xor', 'balance-xor'],
-		['broadcast', 'broadcast'],
-		['802.3ad', 'LACP (802.3ad)'],
-		['balance-tlb', 'balance-tlb'],
-		['balance-alb', 'balance-alb']
-	    ];
+	    me.comboItems = Proxmox.Utils.bond_mode_array([
+		'balance-rr',
+		'active-backup',
+		'balance-xor',
+		'broadcast',
+		'802.3ad',
+		'balance-tlb',
+		'balance-alb',
+	    ]);
 	}
 
 	me.callParent();
-- 
2.20.1





More information about the pve-devel mailing list