]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - mixin/CBind.js
2b69cca9b05fb2e49b2284c145a48b3586a97981
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
) || {};
17 var getConfigValue = function(cname
) {
19 if (cname
in me
.initialConfig
) {
20 return me
.initialConfig
[cname
];
22 if (cname
in me
.cbindData
) {
23 return me
.cbindData
[cname
];
28 throw "unable to get cbind data for '" + cname
+ "'";
31 var applyCBind = function(obj
) {
32 var cbind
= obj
.cbind
, prop
, cdata
, cvalue
, match
, found
;
39 if (match
= /^\{(!)?([a-z_][a-z0-9_]*)\}$/.exec(cdata
)) {
40 var cvalue
= getConfigValue(match
[2]);
41 if (match
[1]) cvalue
= !cvalue
;
45 obj
[prop
] = cdata
.replace(/{([a-z_][a-z0-9_]*)\}/g, function(match
, cname
) {
46 var cvalue
= getConfigValue(cname
);
52 throw "unable to parse cbind template '" + cdata
+ "'";
62 var cloneTemplateArray = function(org
) {
63 var copy
, i
, found
, el
, elcopy
, arrayLength
;
65 arrayLength
= org
.length
;
67 for (i
= 0; i
< arrayLength
; i
++) {
69 if (el
.constructor == Object
&& el
.xtype
) {
75 if (!found
) return org
; // no need to copy
78 for (i
= 0; i
< arrayLength
; i
++) {
80 if (el
.constructor == Object
&& el
.xtype
) {
81 elcopy
= cloneTemplateObject(el
);
86 } else if (el
.constructor == Object
&& el
.xtype
) {
87 elcopy
= cloneTemplateObject(el
);
99 var cloneTemplateObject = function(org
) {
100 var res
= {}, prop
, el
, copy
;
103 if (el
.constructor == Object
&& el
.xtype
) {
104 copy
= cloneTemplateObject(el
);
109 } else if (el
.constructor == Array
) {
110 copy
= cloneTemplateArray(el
);
119 var condCloneProperties = function() {
120 var prop
, el
, i
, tmp
;
124 if (el
=== undefined || el
=== null) continue;
125 if (typeof(el
) === 'object' && el
.constructor == Object
) {
127 me
[prop
] = cloneTemplateObject(el
);
129 } else if (el
.constructor == Array
) {
130 tmp
= cloneTemplateArray(el
);
136 condCloneProperties();