1 //<script type="text/javascript">
4 var MODULE = { isBuilder : true };
15 render : function(data)
18 //console.log(data); return;
20 document.body.removeChild(this.scriptTag);
21 this.scriptTag = false;
24 this.scriptTag = document.body.appendChild(document.createElement('script'));
25 this.scriptTag.setAttribute('type','text/javascript');
28 this.scriptTag.appendChild(
29 document.createTextNode(
30 'Builder._src_' + this.id + ' = ' + JSON.stringify(data, null,4)
34 this.tree = Builder['_src' + this.id];
35 MODULE = { isBuilder : true };
38 Builder.click= Roo.get(document.body).on('click', this.onclick, this);
46 renderObj : { isBuilder : true },
49 redrawClear : function(isAuto)
51 this.renderObj = { isBuilder : true };
60 //if (this.panelroot) {
61 // this.scroll = this.panelroot.el.getScroll();
62 // this.layout.remove('center', this.panelroot);
63 // this.panelroot = false;
65 if (this.dialogroot) {
66 this.dialogroot.remove();
67 this.dialogroot = false;
69 if (this.layoutbase) {
70 //console.log(Builder.dump(this.layoutbase.el));
74 var pan = this.layoutbase.getRegion('center').getPanel(0);
76 this.layoutbase.remove('center', pan);
82 console.log(JSON.stringify(e));
88 //this.layoutbase= false;
95 redraw: function(isAuto)
98 // top level is not relivant
99 this.redrawClear(isAuto);
103 //console.log(this.dump(cfg));
111 //console.log(this.dump(cfg));
112 // we draw either a dialog or a tab..
114 if (cfg.xtype == 'LayoutDialog') {
117 //var xy = Pman.Tab.BuilderPanel.panel.el.getXY();
118 //cfg.items[0].x = xy[0];
119 //cfg.items[0].y = xy[1];
120 //cfg.items[0].constraintoviewport = false;
122 this.dialogroot = Roo.get( document.body).createChild({
127 MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
128 //this.dialog.el.on('click', this.panelClick, this);
129 MODULE.dialog.show();
134 // otherwise we are creating a layout area on the document..
138 // contentpanel, nestedlayoutpanel, contentpanel.. etc.
139 // force center region..
140 cfg.region = 'center';
141 cfg.background = false;
142 if (!this.layoutbase) {
144 this.layoutbase = new Ext.BorderLayout(document.body, {
152 alwaysShowTabs: true,
158 console.log("ADDING CFG");
160 this.layoutbase.addxtype( cfg );
162 console.log("GOT ERROR? - saved in Builder.lastError");
163 Builder.lastError = e;
165 console.log(typeof(e));
167 console.log(this.dump(e));
175 munge :function (cfg, isListener)
178 //cfg.cls = cfg.cls || '';
179 //cfg.cls += ' ' + cfg.id;
184 //console.log(cfg.xtype + ': ' + cfg.id);
190 if (typeof(cfg.background) != 'undefined') {
191 cfg.background = false;
194 var xtype = (cfg['|xns'] || '') + '.' + (cfg.xtype || '');
197 // key is not string?!?!?!!?
199 if (typeof(p) != 'string') {
203 if (typeof(cfg[p]) == 'object') { // listeners!!!
204 this.munge(cfg[p], p == 'listeners');
208 if (p.charAt(0) == '|' || isListener) {
210 if (!cfg[p].length) {
214 var pp = p.charAt(0) == '|' ? p.substring(1) : p;
220 /** eval:var:MOUDULE **/
221 /** eval:var:_this **/
222 /** eval:var:_tmp **/
223 // stupid IE can not return objects evaluated..
224 // console.log('_tmp =(' + cfg[p] + ')');
225 eval('_tmp =(' + cfg[p] + ')');
228 //if (typeof(_tmp) == 'undefined') {
233 console.log('Error evaluating: ' + cfg[p] + "\r\n" + JSON.stringify(e));
244 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
252 if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
253 // xtype contains full path..
254 var bits = cfg.xtype.split('.');
255 bits.shift(); // remove roo..
256 cfg.xtype = bits.pop(); // get the last bit..
258 while (bits.length) {
259 cfg.xns = cfg.xns[bits.shift()];
264 if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
265 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
269 cfg.listeners = cfg.listeners || {};
271 // we can overlay some event handlers here..
274 //console.log('xtype' + xtype)
276 case 'Roo.LayoutDialog':
277 cfg.listeners.resize = function(dlg, w,h)
279 console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
280 console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
289 // now for all the children.. (items)
290 if (xitems === false) {
295 for (var i = 0; i < xitems.length; i++) {
296 // if +builderhide set !!!! drop it!!
300 if (typeof(xi['*prop']) != 'undefined') {
301 //console.log('adding prop:' + xi['*prop']);
303 var pr = xi['*prop'];
305 // if prop is an array - then it's items are really the value..
306 if (pr.match(/\[\]$/)) {
307 //console.log('adding array?:' + pr);
308 pr = pr.replace(/\[\]$/, '');
309 cfg[pr] = cfg[pr] || [];
315 if (xi.xtype && xi.xtype == 'Array') {
318 //console.log('setting property:' + pr);
329 if (cfg.items.length == 0) {
339 cloneConfig : function(config) {
340 if (!config) { return null; }
342 for (var i in config) {
343 if (typeof config[i] == 'object') {
344 newConfig[i] = this.cloneConfig(config[i]);
345 } else if (typeof config[i] != 'function') {
346 newConfig[i] = config[i];
351 dump : function (arr,level) {
352 var dumped_text = "";
353 if(!level) level = 0;
355 return '... TO DEEP ...';
357 //The padding given at the beginning of the line.
358 var level_padding = "";
359 for(var j=0;j<level+1;j++) level_padding += " ";
361 if(typeof(arr) == 'object') { //Array/Hashes/Objects
362 for(var item in arr) {
364 var value = arr[item];
368 if(typeof(value) == 'function') { //If it is an array,
370 dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
373 if(typeof(value) == 'object') { //If it is an array,
374 dumped_text += level_padding + "'" + item + "': {\n";
375 dumped_text += this.dump(value,level+1);
376 dumped_text += level_padding + "}\n";
379 dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
382 } else { //Stings/Chars/Numbers etc.
383 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
387 findNode : function(ftg , method) {
391 // console.log(ftg.id);
392 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
393 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
398 if (ftg.dom.className.match(/[0-9]+/)) {
399 //console.log(ftg.dom.className);
400 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
402 this[method]( cmat[1] );
413 overPos: function(x,y)
416 var el = document.elementFromPoint(x,y);
417 // //console.log(el.id);
418 // console.log(document.body.innerHTML);
420 getTarget : function () {
423 stopEvent : function() {
430 onclick: function(e) {
431 var tg = Roo.get(e.getTarget());
433 //console.log('no target');
437 if (this.findNode(tg,'logClick')) {
440 var dp = Roo.get(tg.up(''));
441 if (dp && this.findNode(dp,'logClick')) {
445 var ns = Roo.get(tg.getNextSibling());
446 if (ns && this.findNode(ns,'logClick')) {
450 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
454 for(var i =0; i < 5; i++) {
455 tg = Roo.get(tg.up(''));
457 //console.log('no parent' + i);
460 if (tg && this.findNode(tg,'logClick')) {
464 //console.log('no target in parents');
467 logClick : function(id)
469 var bid = id.length ? 'builder-' + id : '';
470 console.log('{ "id" : "' + bid + '"}');
474 hover : function(e) {
477 var tg = Roo.get(e.getTarget());
479 //console.log('no target');
484 if (this.findNode(tg,'logMove')) {
488 var dp = Roo.get(tg.up(''));
489 if (dp && this.findNode(dp,'logMove')) {
494 var ns = Roo.get(tg.getNextSibling());
495 if (ns && this.findNode(ns,'logMove')) {
499 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
504 for(var i =0; i < 5; i++) {
505 tg = Roo.get(tg.up(''));
507 //console.log('no parent' + i);
511 if (tg && this.findNode(tg,'logMove')) {
516 //console.log('no target in parents');
519 logMove : function (id) {
520 //console.log("LOGMOVE: " + id);
522 if (this.lastID === id) {
526 var bid = id.length ? 'builder-' + id : '';
527 console.log('{ "hover-node" : "' + bid + '"}');