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..
27 document.body.removeChild(this.scriptTag);
28 this.scriptTag = false;
31 this.scriptTag = document.body.appendChild(document.createElement('script'));
32 this.scriptTag.setAttribute('type','text/javascript');
35 this.scriptTag.appendChild(
36 document.createTextNode(
37 'Builder._src_' + this.id + ' = ' + JSON.stringify(data, null,4)
42 MODULE = { isBuilder : true };
45 Builder.click= Roo.get(document.body).on('click', this.onclick, this);
48 var ix = '_src_' + this.id;
49 var wait_for_tree = function() {
51 Builder.tree = Builder[ix];
53 Roo.log("Wating for tree : " + ix);
54 wait_for_tree.defer(100);
57 Builder.redraw(false);
59 wait_for_tree.defer(100);
65 renderObj : { isBuilder : true },
68 redrawClear : function(isAuto)
70 this.renderObj = { isBuilder : true };
79 //if (this.panelroot) {
80 // this.scroll = this.panelroot.el.getScroll();
81 // this.layout.remove('center', this.panelroot);
82 // this.panelroot = false;
84 if (this.dialogroot) {
85 this.dialogroot.remove();
86 this.dialogroot = false;
88 if (this.layoutbase) {
89 //console.log(Builder.dump(this.layoutbase.el));
93 var pan = this.layoutbase.getRegion('center').getPanel(0);
95 this.layoutbase.remove('center', pan);
101 console.log(JSON.stringify(e));
107 //this.layoutbase= false;
114 redraw: function(isAuto)
117 // top level is not relivant
118 this.redrawClear(isAuto);
122 //console.log(this.dump(cfg));
130 //console.log(this.dump(cfg));
131 // we draw either a dialog or a tab..
133 if (cfg.xtype == 'LayoutDialog') {
136 //var xy = Pman.Tab.BuilderPanel.panel.el.getXY();
137 //cfg.items[0].x = xy[0];
138 //cfg.items[0].y = xy[1];
139 //cfg.items[0].constraintoviewport = false;
141 this.dialogroot = Roo.get( document.body).createChild({
146 MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
147 //this.dialog.el.on('click', this.panelClick, this);
148 MODULE.dialog.show();
153 // otherwise we are creating a layout area on the document..
157 // contentpanel, nestedlayoutpanel, contentpanel.. etc.
158 // force center region..
159 cfg.region = 'center';
160 cfg.background = false;
161 if (!this.layoutbase) {
163 this.layoutbase = new Ext.BorderLayout(document.body, {
171 alwaysShowTabs: true,
177 console.log("ADDING CFG");
179 this.layoutbase.addxtype( cfg );
181 console.log("GOT ERROR? - saved in Builder.lastError");
182 Builder.lastError = e;
184 console.log(typeof(e));
186 console.log(this.dump(e));
194 munge :function (cfg, isListener)
197 //cfg.cls = cfg.cls || '';
198 //cfg.cls += ' ' + cfg.id;
203 //console.log(cfg.xtype + ': ' + cfg.id);
209 if (typeof(cfg.background) != 'undefined') {
210 cfg.background = false;
213 var xtype = (cfg['|xns'] || '') + '.' + (cfg.xtype || '');
216 // key is not string?!?!?!!?
218 if (typeof(p) != 'string') {
222 if (typeof(cfg[p]) == 'object') { // listeners!!!
223 this.munge(cfg[p], p == 'listeners');
227 if (p.charAt(0) == '|' || isListener) {
229 if (!cfg[p].length) {
233 var pp = p.charAt(0) == '|' ? p.substring(1) : p;
239 /** eval:var:MOUDULE **/
240 /** eval:var:_this **/
241 /** eval:var:_tmp **/
242 // stupid IE can not return objects evaluated..
243 // console.log('_tmp =(' + cfg[p] + ')');
244 eval('_tmp =(' + cfg[p] + ')');
247 //if (typeof(_tmp) == 'undefined') {
252 console.log('Error evaluating: ' + cfg[p] + "\r\n" + JSON.stringify(e));
263 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
271 if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
272 // xtype contains full path..
273 var bits = cfg.xtype.split('.');
274 bits.shift(); // remove roo..
275 cfg.xtype = bits.pop(); // get the last bit..
277 while (bits.length) {
278 cfg.xns = cfg.xns[bits.shift()];
283 if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
284 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
288 cfg.listeners = cfg.listeners || {};
290 // we can overlay some event handlers here..
293 //console.log('xtype' + xtype)
295 case 'Roo.LayoutDialog':
296 cfg.listeners.resize = function(dlg, w,h)
298 console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
299 console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
308 // now for all the children.. (items)
309 if (xitems === false) {
314 for (var i = 0; i < xitems.length; i++) {
315 // if +builderhide set !!!! drop it!!
319 if (typeof(xi['*prop']) != 'undefined') {
320 //console.log('adding prop:' + xi['*prop']);
322 var pr = xi['*prop'];
324 // if prop is an array - then it's items are really the value..
325 if (pr.match(/\[\]$/)) {
326 //console.log('adding array?:' + pr);
327 pr = pr.replace(/\[\]$/, '');
328 cfg[pr] = cfg[pr] || [];
334 if (xi.xtype && xi.xtype == 'Array') {
337 //console.log('setting property:' + pr);
348 if (cfg.items.length == 0) {
358 cloneConfig : function(config) {
359 if (!config) { return null; }
361 for (var i in config) {
362 if (typeof config[i] == 'object') {
363 newConfig[i] = this.cloneConfig(config[i]);
364 } else if (typeof config[i] != 'function') {
365 newConfig[i] = config[i];
370 dump : function (arr,level) {
371 var dumped_text = "";
372 if(!level) level = 0;
374 return '... TO DEEP ...';
376 //The padding given at the beginning of the line.
377 var level_padding = "";
378 for(var j=0;j<level+1;j++) level_padding += " ";
380 if(typeof(arr) == 'object') { //Array/Hashes/Objects
381 for(var item in arr) {
383 var value = arr[item];
387 if(typeof(value) == 'function') { //If it is an array,
389 dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
392 if(typeof(value) == 'object') { //If it is an array,
393 dumped_text += level_padding + "'" + item + "': {\n";
394 dumped_text += this.dump(value,level+1);
395 dumped_text += level_padding + "}\n";
398 dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
401 } else { //Stings/Chars/Numbers etc.
402 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
406 findNode : function(ftg , method) {
410 // console.log(ftg.id);
411 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
412 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
417 if (ftg.dom.className.match(/[0-9]+/)) {
418 //console.log(ftg.dom.className);
419 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
421 this[method]( cmat[1] );
432 overPos: function(x,y)
435 var el = document.elementFromPoint(x,y);
436 // //console.log(el.id);
437 // console.log(document.body.innerHTML);
439 getTarget : function () {
442 stopEvent : function() {
449 onclick: function(e) {
450 var tg = Roo.get(e.getTarget());
452 //console.log('no target');
456 if (this.findNode(tg,'logClick')) {
459 var dp = Roo.get(tg.up(''));
460 if (dp && this.findNode(dp,'logClick')) {
464 var ns = Roo.get(tg.getNextSibling());
465 if (ns && this.findNode(ns,'logClick')) {
469 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
473 for(var i =0; i < 5; i++) {
474 tg = Roo.get(tg.up(''));
476 //console.log('no parent' + i);
479 if (tg && this.findNode(tg,'logClick')) {
483 //console.log('no target in parents');
486 logClick : function(id)
488 var bid = id.length ? 'builder-' + id : '';
489 console.log('{ "id" : "' + bid + '"}');
493 hover : function(e) {
496 var tg = Roo.get(e.getTarget());
498 //console.log('no target');
503 if (this.findNode(tg,'logMove')) {
507 var dp = Roo.get(tg.up(''));
508 if (dp && this.findNode(dp,'logMove')) {
513 var ns = Roo.get(tg.getNextSibling());
514 if (ns && this.findNode(ns,'logMove')) {
518 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
523 for(var i =0; i < 5; i++) {
524 tg = Roo.get(tg.up(''));
526 //console.log('no parent' + i);
530 if (tg && this.findNode(tg,'logMove')) {
535 //console.log('no target in parents');
538 logMove : function (id) {
539 //console.log("LOGMOVE: " + id);
541 if (this.lastID === id) {
545 var bid = id.length ? 'builder-' + id : '';
546 console.log('{ "hover-node" : "' + bid + '"}');