1 //<script type="text/javascript">
4 var MODULE = { isBuilder : true };
15 render : function(data, clsname)
21 // console.log(data); return;
24 // This would be alot simpler if we just use the XComponent code...
25 // data should now be dialog or xcomponent..
26 // only snag here is that we do not know the name currently..
28 var ix = '_src_' + this.id++;
29 // should replace module name with Builder._src_{id}
30 data = data.replace(clsname, 'Builder.' + ix);
31 // next.. we need to ensure that parent is set correctly..
32 // done by sender... otherwise building becomes difficult..
33 //data += "\n" + 'Builder.' + ix + ".parent = '#renderel';\n";
35 //Roo.log(data);return;
38 document.body.removeChild(this.scriptTag);
39 this.scriptTag = false;
42 this.scriptTag = document.body.appendChild(document.createElement('script'));
43 this.scriptTag.setAttribute('type','text/javascript');
46 this.scriptTag.appendChild(
47 document.createTextNode(
53 MODULE = { isBuilder : true };
56 Builder.click= Roo.get(document.body).on('click', this.onclick, this);
58 Roo.log('Builder.'+ ix);
59 Roo.XComponent.build();
63 var wait_for_tree = function() {
65 Builder.tree = Builder[ix];
67 Roo.log("Wating for tree : " + ix);
68 wait_for_tree.defer(100);
71 Builder.redraw(false);
73 wait_for_tree.defer(100);
79 renderObj : { isBuilder : true },
82 redrawClear : function(isAuto)
84 this.renderObj = { isBuilder : true };
93 //if (this.panelroot) {
94 // this.scroll = this.panelroot.el.getScroll();
95 // this.layout.remove('center', this.panelroot);
96 // this.panelroot = false;
98 if (this.dialogroot) {
99 this.dialogroot.remove();
100 this.dialogroot = false;
102 if (this.layoutbase) {
103 //console.log(Builder.dump(this.layoutbase.el));
107 var pan = this.layoutbase.getRegion('center').getPanel(0);
109 this.layoutbase.remove('center', pan);
115 console.log(JSON.stringify(e));
121 //this.layoutbase= false;
128 redraw: function(isAuto)
131 // top level is not relivant
132 this.redrawClear(isAuto);
136 //console.log(this.dump(cfg));
144 //console.log(this.dump(cfg));
145 // we draw either a dialog or a tab..
147 if (cfg.xtype == 'LayoutDialog') {
150 //var xy = Pman.Tab.BuilderPanel.panel.el.getXY();
151 //cfg.items[0].x = xy[0];
152 //cfg.items[0].y = xy[1];
153 //cfg.items[0].constraintoviewport = false;
155 this.dialogroot = Roo.get( document.body).createChild({
160 MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
161 //this.dialog.el.on('click', this.panelClick, this);
162 MODULE.dialog.show();
167 // otherwise we are creating a layout area on the document..
171 // contentpanel, nestedlayoutpanel, contentpanel.. etc.
172 // force center region..
173 cfg.region = 'center';
174 cfg.background = false;
175 if (!this.layoutbase) {
177 this.layoutbase = new Ext.BorderLayout(document.body, {
185 alwaysShowTabs: true,
191 console.log("ADDING CFG");
193 this.layoutbase.addxtype( cfg );
195 console.log("GOT ERROR? - saved in Builder.lastError");
196 Builder.lastError = e;
198 console.log(typeof(e));
200 console.log(this.dump(e));
208 munge :function (cfg, isListener)
211 //cfg.cls = cfg.cls || '';
212 //cfg.cls += ' ' + cfg.id;
217 //console.log(cfg.xtype + ': ' + cfg.id);
223 if (typeof(cfg.background) != 'undefined') {
224 cfg.background = false;
227 var xtype = (cfg['|xns'] || '') + '.' + (cfg.xtype || '');
230 // key is not string?!?!?!!?
232 if (typeof(p) != 'string') {
236 if (typeof(cfg[p]) == 'object') { // listeners!!!
237 this.munge(cfg[p], p == 'listeners');
241 if (p.charAt(0) == '|' || isListener) {
243 if (!cfg[p].length) {
247 var pp = p.charAt(0) == '|' ? p.substring(1) : p;
253 /** eval:var:MOUDULE **/
254 /** eval:var:_this **/
255 /** eval:var:_tmp **/
256 // stupid IE can not return objects evaluated..
257 // console.log('_tmp =(' + cfg[p] + ')');
258 eval('_tmp =(' + cfg[p] + ')');
261 //if (typeof(_tmp) == 'undefined') {
266 console.log('Error evaluating: ' + cfg[p] + "\r\n" + JSON.stringify(e));
277 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
285 if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
286 // xtype contains full path..
287 var bits = cfg.xtype.split('.');
288 bits.shift(); // remove roo..
289 cfg.xtype = bits.pop(); // get the last bit..
291 while (bits.length) {
292 cfg.xns = cfg.xns[bits.shift()];
297 if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
298 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
302 cfg.listeners = cfg.listeners || {};
304 // we can overlay some event handlers here..
307 //console.log('xtype' + xtype)
309 case 'Roo.LayoutDialog':
310 cfg.listeners.resize = function(dlg, w,h)
312 console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
313 console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
322 // now for all the children.. (items)
323 if (xitems === false) {
328 for (var i = 0; i < xitems.length; i++) {
329 // if +builderhide set !!!! drop it!!
333 if (typeof(xi['*prop']) != 'undefined') {
334 //console.log('adding prop:' + xi['*prop']);
336 var pr = xi['*prop'];
338 // if prop is an array - then it's items are really the value..
339 if (pr.match(/\[\]$/)) {
340 //console.log('adding array?:' + pr);
341 pr = pr.replace(/\[\]$/, '');
342 cfg[pr] = cfg[pr] || [];
348 if (xi.xtype && xi.xtype == 'Array') {
351 //console.log('setting property:' + pr);
362 if (cfg.items.length == 0) {
372 cloneConfig : function(config) {
373 if (!config) { return null; }
375 for (var i in config) {
376 if (typeof config[i] == 'object') {
377 newConfig[i] = this.cloneConfig(config[i]);
378 } else if (typeof config[i] != 'function') {
379 newConfig[i] = config[i];
384 dump : function (arr,level) {
385 var dumped_text = "";
386 if(!level) level = 0;
388 return '... TO DEEP ...';
390 //The padding given at the beginning of the line.
391 var level_padding = "";
392 for(var j=0;j<level+1;j++) level_padding += " ";
394 if(typeof(arr) == 'object') { //Array/Hashes/Objects
395 for(var item in arr) {
397 var value = arr[item];
401 if(typeof(value) == 'function') { //If it is an array,
403 dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
406 if(typeof(value) == 'object') { //If it is an array,
407 dumped_text += level_padding + "'" + item + "': {\n";
408 dumped_text += this.dump(value,level+1);
409 dumped_text += level_padding + "}\n";
412 dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
415 } else { //Stings/Chars/Numbers etc.
416 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
420 findNode : function(ftg , method) {
424 // console.log(ftg.id);
425 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
426 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
431 if (ftg.dom.className.match(/[0-9]+/)) {
432 //console.log(ftg.dom.className);
433 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
435 this[method]( cmat[1] );
446 overPos: function(x,y)
449 var el = document.elementFromPoint(x,y);
450 // //console.log(el.id);
451 // console.log(document.body.innerHTML);
453 getTarget : function () {
456 stopEvent : function() {
463 onclick: function(e) {
464 var tg = Roo.get(e.getTarget());
466 //console.log('no target');
470 if (this.findNode(tg,'logClick')) {
473 var dp = Roo.get(tg.up(''));
474 if (dp && this.findNode(dp,'logClick')) {
478 var ns = Roo.get(tg.getNextSibling());
479 if (ns && this.findNode(ns,'logClick')) {
483 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
487 for(var i =0; i < 5; i++) {
488 tg = Roo.get(tg.up(''));
490 //console.log('no parent' + i);
493 if (tg && this.findNode(tg,'logClick')) {
497 //console.log('no target in parents');
500 logClick : function(id)
502 var bid = id.length ? 'builder-' + id : '';
503 console.log('{ "id" : "' + bid + '"}');
507 hover : function(e) {
510 var tg = Roo.get(e.getTarget());
512 //console.log('no target');
517 if (this.findNode(tg,'logMove')) {
521 var dp = Roo.get(tg.up(''));
522 if (dp && this.findNode(dp,'logMove')) {
527 var ns = Roo.get(tg.getNextSibling());
528 if (ns && this.findNode(ns,'logMove')) {
532 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
537 for(var i =0; i < 5; i++) {
538 tg = Roo.get(tg.up(''));
540 //console.log('no parent' + i);
544 if (tg && this.findNode(tg,'logMove')) {
549 //console.log('no target in parents');
552 logMove : function (id) {
553 //console.log("LOGMOVE: " + id);
555 if (this.lastID === id) {
559 var bid = id.length ? 'builder-' + id : '';
560 console.log('{ "hover-node" : "' + bid + '"}');
563 clearBootstrap : function()
565 // if the page is not bootstrap
567 if ( typeof(BuilderUseBootstrap) != 'undefined' ) {
568 Roo.log("it's boostrap - BuilderUseBootstrap is defined ");
569 // it's bootstrap - probably remove roo's css..
572 Roo.log("remove css = BuilderUseBootstrap is not defined");
574 var ar = document.getElementsByTagName('link');
575 for (var i = 0; i < ar.length;i++) {
577 Roo.log(l.getAttribute('href'));
578 if (l.getAttribute('href').match(/bootstrap/)) {
585 Roo.each(rem, function(l) { l.parentNode.removeChild(l);});
588 applyFlexy: function(tree)
590 if (typeof(tree['flexy:foreach']) != 'undefined') {
591 //Roo.log("add flexy:foreach");
592 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
594 if (typeof(tree['flexy:if']) != 'undefined') {
595 //Roo.log("add flexy:if");
596 tree.el.attr('flexy:if', tree['flexy:if']);
598 if (typeof(tree['flexy:include']) != 'undefined') {
599 //Roo.log("add flexy:if");
600 tree.el.attr('flexy:include', tree['flexy:include']);
603 if (typeof(tree['xtype-bootstrap']) != 'undefined') {
604 //Roo.log("add flexy:if");
605 tree.el.attr('xtype', tree['xtype-bootstrap']);
609 if (!tree.items || !tree.items.length) { return; }
611 for (var i = 0; i < tree.items.length; i++){
612 this.applyFlexy(tree.items[i]);
619 Roo.onReady(function() { Builder.clearBootstrap(); });
620 Roo.XComponent.on('buildcomplete', function() {
621 Roo.log("xcomponent built!");
623 Builder.applyFlexy(Roo.XComponent.modules[0].el);