[pve-devel] applied: [PATCH v2] mixin/CBind: allow binding sub elements
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Feb 9 11:11:18 CET 2018
applied
On Fri, Feb 09, 2018 at 08:28:34AM +0100, Thomas Lamprecht wrote:
> 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 at proxmox.com>
> ---
>
> changes v1 -> v2:
> * fix regex to allow even and uneven dot counts with only one letter between
>
>
> mixin/CBind.js | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/mixin/CBind.js b/mixin/CBind.js
> index 48bc7f4..ecf30e2 100644
> --- a/mixin/CBind.js
> +++ b/mixin/CBind.js
> @@ -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);
> --
> 2.14.2
More information about the pve-devel
mailing list