]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - mixin/CBind.js
4bd4a55477de3dc86e510157908cca560a7a65af
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_]*)\}$/i.exec(cdata
)) {
40 var cvalue
= getConfigValue(match
[2]);
41 if (match
[1]) cvalue
= !cvalue
;
44 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata
)) {
45 var keys
= match
[2].split('.');
46 var cvalue
= getConfigValue(keys
.shift());
47 keys
.forEach(function(k
) {
51 throw "unable to get cbind data for '" + match
[2] + "'";
54 if (match
[1]) cvalue
= !cvalue
;
58 obj
[prop
] = cdata
.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match
, cname
) {
59 var cvalue
= getConfigValue(cname
);
65 throw "unable to parse cbind template '" + cdata
+ "'";
75 var cloneTemplateArray = function(org
) {
76 var copy
, i
, found
, el
, elcopy
, arrayLength
;
78 arrayLength
= org
.length
;
80 for (i
= 0; i
< arrayLength
; i
++) {
82 if (el
.constructor == Object
&& el
.xtype
) {
88 if (!found
) return org
; // no need to copy
91 for (i
= 0; i
< arrayLength
; i
++) {
93 if (el
.constructor == Object
&& el
.xtype
) {
94 elcopy
= cloneTemplateObject(el
);
99 } else if (el
.constructor == Array
) {
100 elcopy
= cloneTemplateArray(el
);
109 var cloneTemplateObject = function(org
) {
110 var res
= {}, prop
, el
, copy
;
113 if (el
.constructor == Object
&& el
.xtype
) {
114 copy
= cloneTemplateObject(el
);
119 } else if (el
.constructor == Array
) {
120 copy
= cloneTemplateArray(el
);
129 var condCloneProperties = function() {
130 var prop
, el
, i
, tmp
;
134 if (el
=== undefined || el
=== null) continue;
135 if (typeof(el
) === 'object' && el
.constructor == Object
) {
136 if (el
.xtype
&& prop
!= 'config') {
137 me
[prop
] = cloneTemplateObject(el
);
139 } else if (el
.constructor == Array
) {
140 tmp
= cloneTemplateArray(el
);
146 condCloneProperties();