1 //<script type="text/javascript">
4 var MODULE = { isBuilder : true };
15 render : function(data)
18 // console.log(data); return;
20 // This would be alot simpler if we just use the XComponent code...
21 // data should now be dialog or xcomponent..
22 // only snag here is that we do not know the name currently..
30 document.body.removeChild(this.scriptTag);
31 this.scriptTag = false;
34 this.scriptTag = document.body.appendChild(document.createElement('script'));
35 this.scriptTag.setAttribute('type','text/javascript');
38 this.scriptTag.appendChild(
39 document.createTextNode(
40 'Builder._src_' + this.id + ' = ' + JSON.stringify(data, null,4)
45 MODULE = { isBuilder : true };
48 Builder.click= Roo.get(document.body).on('click', this.onclick, this);
51 var ix = '_src_' + this.id;
52 var wait_for_tree = function() {
54 Builder.tree = Builder[ix];
56 Roo.log("Wating for tree : " + ix);
57 wait_for_tree.defer(100);
60 Builder.redraw(false);
62 wait_for_tree.defer(100);
68 renderObj : { isBuilder : true },
71 redrawClear : function(isAuto)
73 this.renderObj = { isBuilder : true };
82 //if (this.panelroot) {
83 // this.scroll = this.panelroot.el.getScroll();
84 // this.layout.remove('center', this.panelroot);
85 // this.panelroot = false;
87 if (this.dialogroot) {
88 this.dialogroot.remove();
89 this.dialogroot = false;
91 if (this.layoutbase) {
92 //console.log(Builder.dump(this.layoutbase.el));
96 var pan = this.layoutbase.getRegion('center').getPanel(0);
98 this.layoutbase.remove('center', pan);
104 console.log(JSON.stringify(e));
110 //this.layoutbase= false;
117 redraw: function(isAuto)
120 // top level is not relivant
121 this.redrawClear(isAuto);
125 //console.log(this.dump(cfg));
133 //console.log(this.dump(cfg));
134 // we draw either a dialog or a tab..
136 if (cfg.xtype == 'LayoutDialog') {
139 //var xy = Pman.Tab.BuilderPanel.panel.el.getXY();
140 //cfg.items[0].x = xy[0];
141 //cfg.items[0].y = xy[1];
142 //cfg.items[0].constraintoviewport = false;
144 this.dialogroot = Roo.get( document.body).createChild({
149 MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
150 //this.dialog.el.on('click', this.panelClick, this);
151 MODULE.dialog.show();
156 // otherwise we are creating a layout area on the document..
160 // contentpanel, nestedlayoutpanel, contentpanel.. etc.
161 // force center region..
162 cfg.region = 'center';
163 cfg.background = false;
164 if (!this.layoutbase) {
166 this.layoutbase = new Ext.BorderLayout(document.body, {
174 alwaysShowTabs: true,
180 console.log("ADDING CFG");
182 this.layoutbase.addxtype( cfg );
184 console.log("GOT ERROR? - saved in Builder.lastError");
185 Builder.lastError = e;
187 console.log(typeof(e));
189 console.log(this.dump(e));
197 munge :function (cfg, isListener)
200 //cfg.cls = cfg.cls || '';
201 //cfg.cls += ' ' + cfg.id;
206 //console.log(cfg.xtype + ': ' + cfg.id);
212 if (typeof(cfg.background) != 'undefined') {
213 cfg.background = false;
216 var xtype = (cfg['|xns'] || '') + '.' + (cfg.xtype || '');
219 // key is not string?!?!?!!?
221 if (typeof(p) != 'string') {
225 if (typeof(cfg[p]) == 'object') { // listeners!!!
226 this.munge(cfg[p], p == 'listeners');
230 if (p.charAt(0) == '|' || isListener) {
232 if (!cfg[p].length) {
236 var pp = p.charAt(0) == '|' ? p.substring(1) : p;
242 /** eval:var:MOUDULE **/
243 /** eval:var:_this **/
244 /** eval:var:_tmp **/
245 // stupid IE can not return objects evaluated..
246 // console.log('_tmp =(' + cfg[p] + ')');
247 eval('_tmp =(' + cfg[p] + ')');
250 //if (typeof(_tmp) == 'undefined') {
255 console.log('Error evaluating: ' + cfg[p] + "\r\n" + JSON.stringify(e));
266 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
274 if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
275 // xtype contains full path..
276 var bits = cfg.xtype.split('.');
277 bits.shift(); // remove roo..
278 cfg.xtype = bits.pop(); // get the last bit..
280 while (bits.length) {
281 cfg.xns = cfg.xns[bits.shift()];
286 if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
287 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
291 cfg.listeners = cfg.listeners || {};
293 // we can overlay some event handlers here..
296 //console.log('xtype' + xtype)
298 case 'Roo.LayoutDialog':
299 cfg.listeners.resize = function(dlg, w,h)
301 console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
302 console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
311 // now for all the children.. (items)
312 if (xitems === false) {
317 for (var i = 0; i < xitems.length; i++) {
318 // if +builderhide set !!!! drop it!!
322 if (typeof(xi['*prop']) != 'undefined') {
323 //console.log('adding prop:' + xi['*prop']);
325 var pr = xi['*prop'];
327 // if prop is an array - then it's items are really the value..
328 if (pr.match(/\[\]$/)) {
329 //console.log('adding array?:' + pr);
330 pr = pr.replace(/\[\]$/, '');
331 cfg[pr] = cfg[pr] || [];
337 if (xi.xtype && xi.xtype == 'Array') {
340 //console.log('setting property:' + pr);
351 if (cfg.items.length == 0) {
361 cloneConfig : function(config) {
362 if (!config) { return null; }
364 for (var i in config) {
365 if (typeof config[i] == 'object') {
366 newConfig[i] = this.cloneConfig(config[i]);
367 } else if (typeof config[i] != 'function') {
368 newConfig[i] = config[i];
373 dump : function (arr,level) {
374 var dumped_text = "";
375 if(!level) level = 0;
377 return '... TO DEEP ...';
379 //The padding given at the beginning of the line.
380 var level_padding = "";
381 for(var j=0;j<level+1;j++) level_padding += " ";
383 if(typeof(arr) == 'object') { //Array/Hashes/Objects
384 for(var item in arr) {
386 var value = arr[item];
390 if(typeof(value) == 'function') { //If it is an array,
392 dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
395 if(typeof(value) == 'object') { //If it is an array,
396 dumped_text += level_padding + "'" + item + "': {\n";
397 dumped_text += this.dump(value,level+1);
398 dumped_text += level_padding + "}\n";
401 dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
404 } else { //Stings/Chars/Numbers etc.
405 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
409 findNode : function(ftg , method) {
413 // console.log(ftg.id);
414 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
415 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
420 if (ftg.dom.className.match(/[0-9]+/)) {
421 //console.log(ftg.dom.className);
422 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
424 this[method]( cmat[1] );
435 overPos: function(x,y)
438 var el = document.elementFromPoint(x,y);
439 // //console.log(el.id);
440 // console.log(document.body.innerHTML);
442 getTarget : function () {
445 stopEvent : function() {
452 onclick: function(e) {
453 var tg = Roo.get(e.getTarget());
455 //console.log('no target');
459 if (this.findNode(tg,'logClick')) {
462 var dp = Roo.get(tg.up(''));
463 if (dp && this.findNode(dp,'logClick')) {
467 var ns = Roo.get(tg.getNextSibling());
468 if (ns && this.findNode(ns,'logClick')) {
472 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
476 for(var i =0; i < 5; i++) {
477 tg = Roo.get(tg.up(''));
479 //console.log('no parent' + i);
482 if (tg && this.findNode(tg,'logClick')) {
486 //console.log('no target in parents');
489 logClick : function(id)
491 var bid = id.length ? 'builder-' + id : '';
492 console.log('{ "id" : "' + bid + '"}');
496 hover : function(e) {
499 var tg = Roo.get(e.getTarget());
501 //console.log('no target');
506 if (this.findNode(tg,'logMove')) {
510 var dp = Roo.get(tg.up(''));
511 if (dp && this.findNode(dp,'logMove')) {
516 var ns = Roo.get(tg.getNextSibling());
517 if (ns && this.findNode(ns,'logMove')) {
521 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
526 for(var i =0; i < 5; i++) {
527 tg = Roo.get(tg.up(''));
529 //console.log('no parent' + i);
533 if (tg && this.findNode(tg,'logMove')) {
538 //console.log('no target in parents');
541 logMove : function (id) {
542 //console.log("LOGMOVE: " + id);
544 if (this.lastID === id) {
548 var bid = id.length ? 'builder-' + id : '';
549 console.log('{ "hover-node" : "' + bid + '"}');