]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
mixin/CBind: allow binding sub elements
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Feb 2018 07:28:34 +0000 (08:28 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 9 Feb 2018 09:13:34 +0000 (10:13 +0100)
allow to access sub elements of configuration items for binding.

E.g., if the following configuration is present:

foo: {
    bar: true
}

one could do:

xtype: 'displayfield',
cbind {
    value: '{foo.bar}'
}
[...]

This mirrors the abillity of ExtJS's 'bind', which can do this also.
Simple implementation mirroring the surrounding code.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
mixin/CBind.js

index 48bc7f44e5be8b94f24251f980bf2dec10c488f6..ecf30e23c5035e2e0eb13de10451e1bba0623a74 100644 (file)
@@ -41,6 +41,19 @@ Ext.define('Proxmox.Mixin.CBind', {
                    if (match[1]) cvalue = !cvalue;
                    obj[prop] = cvalue;
                    found = true;
+               } else if (match = /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata)) {
+                   var keys = match[2].split('.');
+                   var cvalue = getConfigValue(keys.shift());
+                   keys.forEach(function(k) {
+                       if (k in cvalue) {
+                           cvalue = cvalue[k];
+                       } else {
+                           throw "unable to get cbind data for '" + match[2] + "'";
+                       }
+                   });
+                   if (match[1]) cvalue = !cvalue;
+                   obj[prop] = cvalue;
+                   found = true;
                } else {
                    obj[prop] = cdata.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match, cname) {
                        var cvalue = getConfigValue(cname);