]>
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 return me
.cbindData
[cname
];
29 throw "unable to get cbind data for '" + cname
+ "'";
32 var applyCBind = function(obj
) {
33 var cbind
= obj
.cbind
, prop
, cdata
, cvalue
, match
, found
;
40 if (typeof cdata
=== 'function') {
41 obj
[prop
] = cdata(getConfigValue
, prop
);
43 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*)\}$/i.exec(cdata
)) {
44 var cvalue
= getConfigValue(match
[2]);
45 if (match
[1]) cvalue
= !cvalue
;
48 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata
)) {
49 var keys
= match
[2].split('.');
50 var cvalue
= getConfigValue(keys
.shift());
51 keys
.forEach(function(k
) {
55 throw "unable to get cbind data for '" + match
[2] + "'";
58 if (match
[1]) cvalue
= !cvalue
;
62 obj
[prop
] = cdata
.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match
, cname
) {
63 var cvalue
= getConfigValue(cname
);
69 throw "unable to parse cbind template '" + cdata
+ "'";
79 var cloneTemplateArray = function(org
) {
80 var copy
, i
, found
, el
, elcopy
, arrayLength
;
82 arrayLength
= org
.length
;
84 for (i
= 0; i
< arrayLength
; i
++) {
86 if (el
.constructor == Object
&& el
.xtype
) {
92 if (!found
) return org
; // no need to copy
95 for (i
= 0; i
< arrayLength
; i
++) {
97 if (el
.constructor == Object
&& el
.xtype
) {
98 elcopy
= cloneTemplateObject(el
);
103 } else if (el
.constructor == Array
) {
104 elcopy
= cloneTemplateArray(el
);
113 var cloneTemplateObject = function(org
) {
114 var res
= {}, prop
, el
, copy
;
117 if (el
=== undefined || el
=== null) {
121 if (el
.constructor == Object
&& el
.xtype
) {
122 copy
= cloneTemplateObject(el
);
127 } else if (el
.constructor == Array
) {
128 copy
= cloneTemplateArray(el
);
137 var condCloneProperties = function() {
138 var prop
, el
, i
, tmp
;
142 if (el
=== undefined || el
=== null) continue;
143 if (typeof(el
) === 'object' && el
.constructor == Object
) {
144 if (el
.xtype
&& prop
!= 'config') {
145 me
[prop
] = cloneTemplateObject(el
);
147 } else if (el
.constructor == Array
) {
148 tmp
= cloneTemplateArray(el
);
154 condCloneProperties();