]>
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
) {
19 if (cname
in me
.initialConfig
) {
20 return me
.initialConfig
[cname
];
22 if (cname
in me
.cbindData
) {
23 let res
= me
.cbindData
[cname
];
24 if (typeof res
== "function") {
25 return res(me
.initialConfig
);
33 throw "unable to get cbind data for '" + cname
+ "'";
36 var applyCBind = function(obj
) {
37 var cbind
= obj
.cbind
, prop
, cdata
, cvalue
, match
, found
;
44 if (typeof cdata
=== 'function') {
45 obj
[prop
] = cdata(getConfigValue
, prop
);
47 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*)\}$/i.exec(cdata
)) {
48 var cvalue
= getConfigValue(match
[2]);
49 if (match
[1]) cvalue
= !cvalue
;
52 } else if (match
= /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata
)) {
53 var keys
= match
[2].split('.');
54 var cvalue
= getConfigValue(keys
.shift());
55 keys
.forEach(function(k
) {
59 throw "unable to get cbind data for '" + match
[2] + "'";
62 if (match
[1]) cvalue
= !cvalue
;
66 obj
[prop
] = cdata
.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match
, cname
) {
67 var cvalue
= getConfigValue(cname
);
73 throw "unable to parse cbind template '" + cdata
+ "'";
82 var cloneTemplateArray = function(org
) {
83 var copy
, i
, found
, el
, elcopy
, arrayLength
;
85 arrayLength
= org
.length
;
87 for (i
= 0; i
< arrayLength
; i
++) {
89 if (el
.constructor == Object
&& el
.xtype
) {
95 if (!found
) return org
; // no need to copy
98 for (i
= 0; i
< arrayLength
; i
++) {
100 if (el
.constructor == Object
&& el
.xtype
) {
101 elcopy
= cloneTemplateObject(el
);
106 } else if (el
.constructor == Array
) {
107 elcopy
= cloneTemplateArray(el
);
116 var cloneTemplateObject = function(org
) {
117 var res
= {}, prop
, el
, copy
;
120 if (el
=== undefined || el
=== null) {
124 if (el
.constructor == Object
&& el
.xtype
) {
125 copy
= cloneTemplateObject(el
);
130 } else if (el
.constructor == Array
) {
131 copy
= cloneTemplateArray(el
);
140 var condCloneProperties = function() {
141 var prop
, el
, i
, tmp
;
145 if (el
=== undefined || el
=== null) continue;
146 if (typeof el
=== 'object' && el
.constructor == Object
) {
147 if (el
.xtype
&& prop
!= 'config') {
148 me
[prop
] = cloneTemplateObject(el
);
150 } else if (el
.constructor == Array
) {
151 tmp
= cloneTemplateArray(el
);
157 condCloneProperties();