2 * The code that renders the view - used to be in the Builder.View etc...
4 * used to be inside the Interface, but has proved to be to difficult to manage.
6 * In principle, simple event handling code is put in the interface, and any hard
7 * lifting is done in nice files...
9 * It might be better to just extend 'tree', and use the extended class..
24 var iframe = this.container.el.select('iframe',true).first().dom;
26 return iframe.contentDocument || iframe.contentWindow.document;
29 var iframe = this.container.el.select('iframe',true).first().dom;
30 return iframe.contentWindow;
33 init : function (comp) {
34 if (this.panel || !comp.layout) {
37 this.panel = comp.panel;
38 this.layout = comp.panel.layout;
39 // see if we can render a iframe..
43 this.container = comp.layout.getRegion('center').getPanel(0);
44 this.container.setContent(
45 '<iframe width="100%" height="100%" src="'+baseURL+'/Builder/App/' + app + '?no_parts=1"></iframe>'
47 var iframe = this.container.el.select('iframe',true).first()
49 iframe.setSize( this.panel.el.getSize());
51 //this.doc = iframe.contentDocument || iframe.contentWindow.document;
58 clearAll : function(isAuto) {
60 this.win().Pman.Builder.View.frameClearAll(isAuto);
68 frameToHTML : function()
70 return this.win().Pman.Builder.View.toHTML();
75 toHTML : function () {
77 Roo.select('body > div',true).each(function(el) {
78 this.traverseDOMTree(function(s) { ret+=s; }, el.dom, 1);
84 traverseDOMTree : function(cb, currentElement, depth) {
87 if (currentElement.className.match(/roo-dynamic/)) {
90 //Roo.log(currentElement);
92 var nodeName = currentElement.nodeName;
93 var tagName = currentElement.tagName;
95 if (nodeName == '#text') {
96 cb(currentElement.nodeValue);
101 // Prints the node tagName, such as <A>, <IMG>, etc
104 for(i = 0; i < currentElement.attributes.length;i++) {
105 attr.push(currentElement.attributes.item(i).name + '="' + currentElement.attributes.item(i).value + '"' );
109 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
116 var currentElementChild = currentElement.childNodes[i];
118 while (currentElementChild) {
119 // Formatting code (indent the tree so it looks nice on the screen)
121 if (currentElementChild.nodeName == '#text') {
122 cb(currentElementChild.nodeValue);
124 currentElementChild=currentElement.childNodes[i];
129 for (j = 0; j < depth; j++) {
130 // ¦ is just a vertical line
135 // Recursively traverse the tree structure of the child node
136 this.traverseDOMTree(cb, currentElementChild, depth+1);
138 currentElementChild=currentElement.childNodes[i];
141 // The remaining code is mostly for formatting the tree
143 for (j = 0; j < depth - 1; j++) {
148 cb("</"+tagName+">");
155 frameClearAll : function(isAuto) {
156 // this.renderObj = { isBuilder : true };
159 if (this.panelroot) {
160 this.scroll = this.panelroot.el.getScroll();
161 this.layout.remove('center', this.panelroot);
162 this.panelroot = false;
164 if (this.dialogroot) {
165 this.dialogroot.remove();
166 this.dialogroot = false;
168 Roo.select('body > div').remove();
171 munge : function(cfg, keyname, add_xattr) {
172 keyname = keyname || false;
174 this.renderObj = this.renderObj || {};
182 if (typeof(cfg.background) != 'undefined') {
183 cfg.background = false;
188 // key is not string?!?!?!!?
189 if (typeof(p) != 'string') {
193 if (typeof(cfg[p]) == 'object') { // listeners!!!
194 this.munge(cfg[p], p, add_xattr);
198 if (p.charAt(0) == '|' || keyname=='listeners') {
200 if (!cfg[p].length) {
205 if (str.match(/\s*function/)) {
206 var btz = str.split('{');
207 str = btz.shift() +'{ try {' + btz.join('{') +
208 ' catch (e) { Roo.log(e) } }';
211 Roo.log("interpret? " + str);
213 var _this = this.renderObj; /// fake '_this' object..
214 // stupid IE can not return objects evaluated..
221 eval('_tmp =(' + str + ')');
222 cfg[p.replace(/^\|/, '')] = _tmp;
223 if (typeof(_tmp) == 'undefined') {
227 } catch(e) { console.log('Error evaluating: ' + str); };
228 //if (p.charAt(0) == '|' ) {
236 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
247 xtype : cfg['|xns'] + '.' + cfg.xtype
254 // now for all the children.. (items)
255 if (xitems === false) {
259 for (var i = 0; i < xitems.length; i++) {
260 // if +builderhide set !!!! drop it!!
264 if (typeof(xi['*prop']) != 'undefined') {
265 var pr = xi['*prop'];
266 this.munge(xi, false, add_xattr);
267 // if prop is an array - then it's items are really the value..
268 if (pr.match(/\[\]$/)) {
269 pr = pr.replace(/\[\]$/, '');
270 if (typeof(cfg[pr]) == 'undefined') {
276 if (xi.xtype && xi.xtype == 'Array') {
285 this.munge(xi, false, add_xattr);
289 if (cfg.items.length == 0) {
292 // remove listeners if there are none..
293 if (typeof(cfg['listeners']) != 'undefined') {
295 for (var i in cfg.listeners) { n++; }
297 delete cfg['listeners'];
302 if (typeof(cfg.id) != 'undefined') {
303 cfg.id = 'pman-dyn-' + cfg.id;
312 return Pman.Builder.Tree.toJS(Pman.Tab.BuilderTree.tree.root);
316 var ret = Pman.Builder.Tree.cloneConfig(n.elConfig);
318 // flag to prevent rendering..
319 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
323 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
325 if (n.childNodes.length) {
327 n.eachChild(function(cn) {
328 var add = _this.toJS(cn);
341 redraw : function(isAuto)
343 this.container.el.select('iframe',true).first().setSize(this.panel.el.getSize());
346 // top level is not relivant
348 // var btop = Pman.Tab.BuilderTop2;
349 // if (isAuto && btop.redrawBtn && !btop.redrawBtn.auto) {
350 // return; /// auto redraw is turned off..
353 this.clearAll(isAuto);
355 var cfg = this.toJS();
357 this.win().Pman.Builder.View.draw( cfg );
369 this.munge(cfg.items[0],false , true );
373 // we draw either a dialog or a tab..
375 if (cfg.items[0].xtype == 'LayoutDialog') {
377 cfg.items[0].modal = false;
378 var xy = this.el.getXY();
379 cfg.items[0].x = xy[0];
380 cfg.items[0].y = xy[1];
381 cfg.items[0].constraintoviewport = false;
383 this.dialogroot = Roo.get( this.doc).createChild();
385 this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
386 // this.dialog.el.on('click', this.panelClick, this);
388 var dlg = this.dialog;
390 dlg.moveTo(xy[0], xy[1]);
393 Roo.log("Error rendering dialog: " + e.toString());
400 if (cfg.items[0]['|xns'] == 'Roo.bootstrap') {
404 Roo.log("bootstrap build!?");
405 var top = new Roo.bootstrap.Body({});
406 top.onRender(false,false);
407 this.bootstrapModal = top.addxtype(cfg.items[0]).items[0];
409 if (cfg.items[0].xtype =='Modal' ) {
410 this.bootstrapModal.show();
418 // should we render this into a dialog???
419 // force center region..
420 cfg.items[0].region = 'center';
421 cfg.items[0].background = false;
428 this.panelroot = this.layout.addxtype(cfg.items[0]);
431 Roo.log("Error rendering: " + e.toString());
434 //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
436 if (this.panelroot && this.panelroot.el) {
437 this.panelroot.el.scrollTo('top', 0);
438 this.panelroot.el.scrollTo('left', 0);
442 frameUpdateTheme: function(name)
444 return this.win().Pman.Builder.View.updateTheme(name);
446 updateTheme : function(name)
448 Roo.select('head link[rel=stylesheet]').each(function(e) {
449 if (!e.dom.href.match(/bootstrap\.\min.css$/)) {
452 e.dom.setAttribute('href', rootURL +'/bootswatch/' + name + '/bootstrap.min.css' );