1 //<script type="text/javascript">
4 var MODULE = { isBuilder : true };
15 render : function(data)
18 //console.log(data); return;
20 document.body.removeChild(scriptTag);
24 this.scriptTag = document.body.appendChild(document.body.createElement('script'));
25 this.scriptTag.setAttribute('language','text/javascript');
28 document.body.createCDATA('Builder._src_' + this.id = JSON.stringify(data));
29 this.scriptTag.innerHTML = "_Builder."
32 this.tree = Builder['_src' + this.id];
33 MODULE = { isBuilder : true };
36 Builder.click= Roo.get(document.body).on('click', this.onclick, this);
44 renderObj : { isBuilder : true },
47 redrawClear : function(isAuto)
49 this.renderObj = { isBuilder : true };
58 //if (this.panelroot) {
59 // this.scroll = this.panelroot.el.getScroll();
60 // this.layout.remove('center', this.panelroot);
61 // this.panelroot = false;
63 if (this.dialogroot) {
64 this.dialogroot.remove();
65 this.dialogroot = false;
67 if (this.layoutbase) {
68 //console.log(Builder.dump(this.layoutbase.el));
72 var pan = this.layoutbase.getRegion('center').getPanel(0);
74 this.layoutbase.remove('center', pan);
80 console.log(JSON.stringify(e));
86 //this.layoutbase= false;
93 redraw: function(isAuto)
96 // top level is not relivant
97 this.redrawClear(isAuto);
101 //console.log(this.dump(cfg));
109 //console.log(this.dump(cfg));
110 // we draw either a dialog or a tab..
112 if (cfg.xtype == 'LayoutDialog') {
115 //var xy = Pman.Tab.BuilderPanel.panel.el.getXY();
116 //cfg.items[0].x = xy[0];
117 //cfg.items[0].y = xy[1];
118 //cfg.items[0].constraintoviewport = false;
120 this.dialogroot = Roo.get( document.body).createChild({
125 MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
126 //this.dialog.el.on('click', this.panelClick, this);
127 MODULE.dialog.show();
132 // otherwise we are creating a layout area on the document..
136 // contentpanel, nestedlayoutpanel, contentpanel.. etc.
137 // force center region..
138 cfg.region = 'center';
139 cfg.background = false;
140 if (!this.layoutbase) {
142 this.layoutbase = new Ext.BorderLayout(document.body, {
150 alwaysShowTabs: true,
156 console.log("ADDING CFG");
158 this.layoutbase.addxtype( cfg );
160 console.log("GOT ERROR? - saved in Builder.lastError");
161 Builder.lastError = e;
163 console.log(typeof(e));
165 console.log(this.dump(e));
173 munge :function (cfg, isListener)
176 //cfg.cls = cfg.cls || '';
177 //cfg.cls += ' ' + cfg.id;
182 //console.log(cfg.xtype + ': ' + cfg.id);
188 if (typeof(cfg.background) != 'undefined') {
189 cfg.background = false;
192 var xtype = (cfg['|xns'] || '') + '.' + (cfg.xtype || '');
195 // key is not string?!?!?!!?
197 if (typeof(p) != 'string') {
201 if (typeof(cfg[p]) == 'object') { // listeners!!!
202 this.munge(cfg[p], p == 'listeners');
206 if (p.charAt(0) == '|' || isListener) {
208 if (!cfg[p].length) {
212 var pp = p.charAt(0) == '|' ? p.substring(1) : p;
218 /** eval:var:MOUDULE **/
219 /** eval:var:_this **/
220 /** eval:var:_tmp **/
221 // stupid IE can not return objects evaluated..
222 // console.log('_tmp =(' + cfg[p] + ')');
223 eval('_tmp =(' + cfg[p] + ')');
226 //if (typeof(_tmp) == 'undefined') {
231 console.log('Error evaluating: ' + cfg[p] + "\r\n" + JSON.stringify(e));
242 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
250 if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
251 // xtype contains full path..
252 var bits = cfg.xtype.split('.');
253 bits.shift(); // remove roo..
254 cfg.xtype = bits.pop(); // get the last bit..
256 while (bits.length) {
257 cfg.xns = cfg.xns[bits.shift()];
262 if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
263 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
267 cfg.listeners = cfg.listeners || {};
269 // we can overlay some event handlers here..
272 //console.log('xtype' + xtype)
274 case 'Roo.LayoutDialog':
275 cfg.listeners.resize = function(dlg, w,h)
277 console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
278 console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
287 // now for all the children.. (items)
288 if (xitems === false) {
293 for (var i = 0; i < xitems.length; i++) {
294 // if +builderhide set !!!! drop it!!
298 if (typeof(xi['*prop']) != 'undefined') {
299 //console.log('adding prop:' + xi['*prop']);
301 var pr = xi['*prop'];
303 // if prop is an array - then it's items are really the value..
304 if (pr.match(/\[\]$/)) {
305 //console.log('adding array?:' + pr);
306 pr = pr.replace(/\[\]$/, '');
307 cfg[pr] = cfg[pr] || [];
313 if (xi.xtype && xi.xtype == 'Array') {
316 //console.log('setting property:' + pr);
327 if (cfg.items.length == 0) {
337 cloneConfig : function(config) {
338 if (!config) { return null; }
340 for (var i in config) {
341 if (typeof config[i] == 'object') {
342 newConfig[i] = this.cloneConfig(config[i]);
343 } else if (typeof config[i] != 'function') {
344 newConfig[i] = config[i];
349 dump : function (arr,level) {
350 var dumped_text = "";
351 if(!level) level = 0;
353 return '... TO DEEP ...';
355 //The padding given at the beginning of the line.
356 var level_padding = "";
357 for(var j=0;j<level+1;j++) level_padding += " ";
359 if(typeof(arr) == 'object') { //Array/Hashes/Objects
360 for(var item in arr) {
362 var value = arr[item];
366 if(typeof(value) == 'function') { //If it is an array,
368 dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
371 if(typeof(value) == 'object') { //If it is an array,
372 dumped_text += level_padding + "'" + item + "': {\n";
373 dumped_text += this.dump(value,level+1);
374 dumped_text += level_padding + "}\n";
377 dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
380 } else { //Stings/Chars/Numbers etc.
381 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
385 findNode : function(ftg , method) {
389 // console.log(ftg.id);
390 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
391 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
396 if (ftg.dom.className.match(/[0-9]+/)) {
397 //console.log(ftg.dom.className);
398 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
400 this[method]( cmat[1] );
411 overPos: function(x,y)
414 var el = document.elementFromPoint(x,y);
415 // //console.log(el.id);
416 // console.log(document.body.innerHTML);
418 getTarget : function () {
421 stopEvent : function() {
428 onclick: function(e) {
429 var tg = Roo.get(e.getTarget());
431 //console.log('no target');
435 if (this.findNode(tg,'logClick')) {
438 var dp = Roo.get(tg.up(''));
439 if (dp && this.findNode(dp,'logClick')) {
443 var ns = Roo.get(tg.getNextSibling());
444 if (ns && this.findNode(ns,'logClick')) {
448 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
452 for(var i =0; i < 5; i++) {
453 tg = Roo.get(tg.up(''));
455 //console.log('no parent' + i);
458 if (tg && this.findNode(tg,'logClick')) {
462 //console.log('no target in parents');
465 logClick : function(id)
467 var bid = id.length ? 'builder-' + id : '';
468 console.log('{ "id" : "' + bid + '"}');
472 hover : function(e) {
475 var tg = Roo.get(e.getTarget());
477 //console.log('no target');
482 if (this.findNode(tg,'logMove')) {
486 var dp = Roo.get(tg.up(''));
487 if (dp && this.findNode(dp,'logMove')) {
492 var ns = Roo.get(tg.getNextSibling());
493 if (ns && this.findNode(ns,'logMove')) {
497 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
502 for(var i =0; i < 5; i++) {
503 tg = Roo.get(tg.up(''));
505 //console.log('no parent' + i);
509 if (tg && this.findNode(tg,'logMove')) {
514 //console.log('no target in parents');
517 logMove : function (id) {
518 //console.log("LOGMOVE: " + id);
520 if (this.lastID === id) {
524 var bid = id.length ? 'builder-' + id : '';
525 console.log('{ "hover-node" : "' + bid + '"}');