[pve-devel] [PATCH manager 2/3] ui: rbd: storage: obsolete strange getBinds binding assembly

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Nov 15 13:20:10 CET 2018


this was added for our (also in other places used):
> xtype: me.isCreate ? 'pveCephPoolSelector' : 'displayfield',
construct. But as displayfield does not has a submitValue setter we
cannot bind it generally.

So add such a setter with a small override and declare the bindings
direct when declaring the items, less side effects and all the
configurations for an item stays in the same place.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 www/manager6/Toolkit.js         |  9 ++++++++
 www/manager6/storage/RBDEdit.js | 39 ++++++++++++++++-----------------
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/www/manager6/Toolkit.js b/www/manager6/Toolkit.js
index 0c9364bd..55b127c5 100644
--- a/www/manager6/Toolkit.js
+++ b/www/manager6/Toolkit.js
@@ -27,3 +27,12 @@ Ext.apply(Ext.form.field.VTypes, {
     IP64AddressListText: gettext('Example') + ': 192.168.1.1,192.168.1.2',
     IP64AddressListMask: /[A-Fa-f0-9\,\:\.\;\ ]/
 });
+
+Ext.define('PVE.form.field.Display', {
+    override: 'Ext.form.field.Display',
+
+    setSubmitValue: function(value) {
+	// do nothing, this is only to allow generalized  bindings for the:
+	// `me.isCreate ? 'textfield' : 'displayfield'` cases we have.
+    }
+});
diff --git a/www/manager6/storage/RBDEdit.js b/www/manager6/storage/RBDEdit.js
index 22efef10..c38759df 100644
--- a/www/manager6/storage/RBDEdit.js
+++ b/www/manager6/storage/RBDEdit.js
@@ -98,28 +98,16 @@ Ext.define('PVE.storage.RBDInputPanel', {
 	}
 	me.type = 'rbd';
 
-	var getBinds = function (activeIfPVECeph, hide) {
-	    var bind = {
-		disabled: activeIfPVECeph ? '{!pveceph}' : '{pveceph}'
-	    };
-
-	    // displayfield has no submitValue and bind mixin cannot handle that
-	    if (me.isCreate) {
-		bind.submitValue = activeIfPVECeph ? '{pveceph}' : '{!pveceph}';
-	    }
-	    if (hide) {
-		bind.hidden = activeIfPVECeph ? '{!pveceph}' : '{pveceph}';
-	    }
-
-	    return bind;
-	};
-
 	me.column1 = [
 	    {
 		xtype: me.isCreate ? 'pveCephPoolSelector' : 'displayfield',
 		nodename: me.nodename,
 		name: 'pool',
-		bind: getBinds(true, true),
+		bind: {
+		    disabled: '{!pveceph}',
+		    submitValue: '{pveceph}',
+		    hidden: '{!pveceph}'
+		},
 		fieldLabel: gettext('Pool'),
 		allowBlank: false
 	    },
@@ -127,7 +115,11 @@ Ext.define('PVE.storage.RBDInputPanel', {
 		xtype: me.isCreate ? 'textfield' : 'displayfield',
 		name: 'pool',
 		value: 'rbd',
-		bind: getBinds(false, true),
+		bind: {
+		    disabled: '{pveceph}',
+		    submitValue: '{!pveceph}',
+		    hidden: '{pveceph}'
+		},
 		fieldLabel: gettext('Pool'),
 		allowBlank: false
 	    },
@@ -135,7 +127,11 @@ Ext.define('PVE.storage.RBDInputPanel', {
 		xtype: 'textfield',
 		name: 'monhost',
 		vtype: 'HostList',
-		bind: getBinds(false, true),
+		bind: {
+		    disabled: '{pveceph}',
+		    submitValue: '{!pveceph}',
+		    hidden: '{pveceph}'
+		},
 		value: '',
 		fieldLabel: 'Monitor(s)',
 		allowBlank: false
@@ -153,7 +149,10 @@ Ext.define('PVE.storage.RBDInputPanel', {
 	    {
 		xtype: me.isCreate ? 'textfield' : 'displayfield',
 		name: 'username',
-		bind: me.isCreate ? getBinds(false) : {},
+		bind: {
+		    disabled: '{pveceph}',
+		    submitValue: '{!pveceph}'
+		},
 		value: 'admin',
 		fieldLabel: gettext('User name'),
 		allowBlank: true
-- 
2.19.1





More information about the pve-devel mailing list