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;
56 clearAll : function(isAuto) {
58 this.win().Pman.Builder.View.frameClearAll(isAuto);
66 frameToHTML : function()
68 return this.win().Pman.Builder.View.toHTML();
73 toHTML : function () {
75 Roo.select('body > div',true).each(function(el) {
76 this.traverseDOMTree(function(s) { ret+=s; }, el.dom, 1);
82 traverseDOMTree : function(cb, currentElement, depth) {
85 if (currentElement.className.match(/roo-dynamic/)) {
88 //Roo.log(currentElement);
90 var nodeName = currentElement.nodeName;
91 var tagName = currentElement.tagName;
93 if (nodeName == '#text') {
94 cb(currentElement.nodeValue);
99 // Prints the node tagName, such as <A>, <IMG>, etc
102 for(i = 0; i < currentElement.attributes.length;i++) {
103 var aname = currentElement.attributes.item(i).name;
107 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
111 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
118 var currentElementChild = currentElement.childNodes[i];
120 while (currentElementChild) {
121 // Formatting code (indent the tree so it looks nice on the screen)
123 if (currentElementChild.nodeName == '#text') {
124 cb(currentElementChild.nodeValue);
126 currentElementChild=currentElement.childNodes[i];
131 for (j = 0; j < depth; j++) {
132 // ¦ is just a vertical line
137 // Recursively traverse the tree structure of the child node
138 this.traverseDOMTree(cb, currentElementChild, depth+1);
140 currentElementChild=currentElement.childNodes[i];
143 // The remaining code is mostly for formatting the tree
145 for (j = 0; j < depth - 1; j++) {
150 cb("</"+tagName+">");
157 frameClearAll : function(isAuto) {
158 // this.renderObj = { isBuilder : true };
161 if (this.panelroot) {
162 this.scroll = this.panelroot.el.getScroll();
163 this.layout.remove('center', this.panelroot);
164 this.panelroot = false;
166 if (this.dialogroot) {
167 this.dialogroot.remove();
168 this.dialogroot = false;
170 Roo.select('body > div').remove();
173 munge : function(cfg, keyname, add_xattr) {
174 keyname = keyname || false;
176 this.renderObj = this.renderObj || {};
184 if (typeof(cfg.background) != 'undefined') {
185 cfg.background = false;
190 // key is not string?!?!?!!?
191 if (typeof(p) != 'string') {
195 if (typeof(cfg[p]) == 'object') { // listeners!!!
196 this.munge(cfg[p], p, add_xattr);
200 if (p.charAt(0) == '|' || keyname=='listeners') {
202 if (!cfg[p].length) {
207 if (str.match(/\s*function/)) {
208 var btz = str.split('{');
209 str = btz.shift() +'{ try {' + btz.join('{') +
210 ' catch (e) { Roo.log(e) } }';
213 Roo.log("interpret? " + str);
215 var _this = this.renderObj; /// fake '_this' object..
216 // stupid IE can not return objects evaluated..
223 eval('_tmp =(' + str + ')');
224 cfg[p.replace(/^\|/, '')] = _tmp;
225 if (typeof(_tmp) == 'undefined') {
229 } catch(e) { console.log('Error evaluating: ' + str); };
230 //if (p.charAt(0) == '|' ) {
238 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
249 xtype : cfg['|xns'] + '.' + cfg.xtype
256 // now for all the children.. (items)
257 if (xitems === false) {
261 for (var i = 0; i < xitems.length; i++) {
262 // if +builderhide set !!!! drop it!!
266 if (typeof(xi['*prop']) != 'undefined') {
267 var pr = xi['*prop'];
268 this.munge(xi, false, add_xattr);
269 // if prop is an array - then it's items are really the value..
270 if (pr.match(/\[\]$/)) {
271 pr = pr.replace(/\[\]$/, '');
272 if (typeof(cfg[pr]) == 'undefined') {
278 if (xi.xtype && xi.xtype == 'Array') {
287 this.munge(xi, false, add_xattr);
291 if (cfg.items.length == 0) {
294 // remove listeners if there are none..
295 if (typeof(cfg['listeners']) != 'undefined') {
297 for (var i in cfg.listeners) { n++; }
299 delete cfg['listeners'];
304 if (typeof(cfg.id) != 'undefined') {
305 cfg.id = 'pman-dyn-' + cfg.id;
314 return Pman.Builder.Tree.toJS(Pman.Tab.BuilderTree.tree.root);
318 var ret = Pman.Builder.Tree.cloneConfig(n.elConfig);
320 // flag to prevent rendering..
321 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
325 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
327 if (n.childNodes.length) {
329 n.eachChild(function(cn) {
330 var add = _this.toJS(cn);
343 redraw : function(isAuto)
345 this.container.el.select('iframe',true).first().setSize(this.panel.el.getSize());
348 // top level is not relivant
350 // var btop = Pman.Tab.BuilderTop2;
351 // if (isAuto && btop.redrawBtn && !btop.redrawBtn.auto) {
352 // return; /// auto redraw is turned off..
355 this.clearAll(isAuto);
357 var cfg = this.toJS();
359 this.win().Pman.Builder.View.draw( cfg );
371 this.munge(cfg.items[0],false , true );
375 // we draw either a dialog or a tab..
377 if (cfg.items[0].xtype == 'LayoutDialog') {
379 cfg.items[0].modal = false;
380 var xy = this.el.getXY();
381 cfg.items[0].x = xy[0];
382 cfg.items[0].y = xy[1];
383 cfg.items[0].constraintoviewport = false;
385 this.dialogroot = Roo.get( this.doc).createChild();
387 this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
388 // this.dialog.el.on('click', this.panelClick, this);
390 var dlg = this.dialog;
392 dlg.moveTo(xy[0], xy[1]);
395 Roo.log("Error rendering dialog: " + e.toString());
402 if (cfg.items[0]['|xns'] == 'Roo.bootstrap') {
404 Roo.log('----------------------------run draw----------------------------');
405 Roo.log(cfg.items[0]);return;
406 // if xtype = 'modal...'
407 // construct the modal..
411 Roo.log("bootstrap build!?");
412 var top = new Roo.bootstrap.Body({});
413 top.onRender(false,false);
415 this.bootstrapModal = top.addxtype(cfg.items[0]).items[0];
417 this.applyFlexy(top);
419 if (cfg.items[0].xtype =='Modal' ) {
420 this.bootstrapModal.show();
428 // should we render this into a dialog???
429 // force center region..
430 cfg.items[0].region = 'center';
431 cfg.items[0].background = false;
438 this.panelroot = this.layout.addxtype(cfg.items[0]);
441 Roo.log("Error rendering: " + e.toString());
444 //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
446 if (this.panelroot && this.panelroot.el) {
447 this.panelroot.el.scrollTo('top', 0);
448 this.panelroot.el.scrollTo('left', 0);
452 frameUpdateTheme: function(name)
454 return this.win().Pman.Builder.View.updateTheme(name);
456 updateTheme : function(name)
458 Roo.select('head link[rel=stylesheet]').each(function(e) {
459 if (!e.dom.href.match(/bootstrap\.\min.css$/)) {
462 e.dom.setAttribute('href', rootURL +'/bootswatch/' + name + '/bootstrap.min.css' );
468 applyFlexy: function(tree)
470 if (typeof(tree['flexy:foreach']) != 'undefined') {
471 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
473 if (typeof(tree['flexy:if']) != 'undefined') {
474 tree.el.attr('flexy:if', tree['flexy:if']);
476 if (!tree.items || !tree.items.length) { return; }
478 for (var i = 0; i < tree.items.length; i++){
479 this.applyFlexy(tree.items[i]);