]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - mixin/CBind.js
1 Ext
.define('Proxmox.Mixin.CBind', {
6 initComponent
: 'cloneTemplates'
10 cloneTemplates: function() {
13 if (typeof(me
.cbindData
) == "function") {
14 me
.cbindData
= me
.cbindData(me
.initialConfig
);
16 me
.cbindData
= me
.cbindData
|| {};
18 var getConfigValue = function(cname
) {
20 if (cname
in me
.initialConfig
) {
21 return me
.initialConfig
[cname
];
23 if (cname
in me
.cbindData
) {
24 let res
= me
.cbindData
[cname
];
25 if (typeof(res
) == "function") {
26 return res(me
.initialConfig
);
34 throw "unable to get cbind data for '" + cname
+ "'";
37 var applyCBind = function(obj
) {
38 var cbind
= obj
.cbind
, prop
, cdata
, cvalue
, match
, found
;
45 if (typeof cdata
=== 'function') {
46 obj
[prop
] = cdata(getConfigValue
, prop
);
48 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*)\}$/i.exec(cdata
)) {
49 var cvalue
= getConfigValue(match
[2]);
50 if (match
[1]) cvalue
= !cvalue
;
53 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata
)) {
54 var keys
= match
[2].split('.');
55 var cvalue
= getConfigValue(keys
.shift());
56 keys
.forEach(function(k
) {
60 throw "unable to get cbind data for '" + match
[2] + "'";
63 if (match
[1]) cvalue
= !cvalue
;
67 obj
[prop
] = cdata
.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match
, cname
) {
68 var cvalue
= getConfigValue(cname
);
74 throw "unable to parse cbind template '" + cdata
+ "'";
84 var cloneTemplateArray = function(org
) {
85 var copy
, i
, found
, el
, elcopy
, arrayLength
;
87 arrayLength
= org
.length
;
89 for (i
= 0; i
< arrayLength
; i
++) {
91 if (el
.constructor == Object
&& el
.xtype
) {
97 if (!found
) return org
; // no need to copy
100 for (i
= 0; i
< arrayLength
; i
++) {
102 if (el
.constructor == Object
&& el
.xtype
) {
103 elcopy
= cloneTemplateObject(el
);
108 } else if (el
.constructor == Array
) {
109 elcopy
= cloneTemplateArray(el
);
118 var cloneTemplateObject = function(org
) {
119 var res
= {}, prop
, el
, copy
;
122 if (el
=== undefined || el
=== null) {
126 if (el
.constructor == Object
&& el
.xtype
) {
127 copy
= cloneTemplateObject(el
);
132 } else if (el
.constructor == Array
) {
133 copy
= cloneTemplateArray(el
);
142 var condCloneProperties = function() {
143 var prop
, el
, i
, tmp
;
147 if (el
=== undefined || el
=== null) continue;
148 if (typeof(el
) === 'object' && el
.constructor == Object
) {
149 if (el
.xtype
&& prop
!= 'config') {
150 me
[prop
] = cloneTemplateObject(el
);
152 } else if (el
.constructor == Array
) {
153 tmp
= cloneTemplateArray(el
);
159 condCloneProperties();