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;
55 clearAll : function(isAuto) {
57 this.win().Pman.Builder.View.frameClearAll(isAuto);
65 frameToHTML : function()
67 return this.win().Pman.Builder.View.toHTML();
72 toHTML : function () {
74 Roo.select('body > div',true).each(function(el) {
75 this.traverseDOMTree(function(s) { ret+=s; }, el.dom, 1);
81 traverseDOMTree : function(cb, currentElement, depth) {
84 if (currentElement.className.match(/roo-dynamic/)) {
87 //Roo.log(currentElement);
89 var nodeName = currentElement.nodeName;
90 var tagName = currentElement.tagName;
92 if (nodeName == '#text') {
93 cb(currentElement.nodeValue);
98 // Prints the node tagName, such as <A>, <IMG>, etc
101 for(i = 0; i < currentElement.attributes.length;i++) {
102 var aname = currentElement.attributes.item(i).name;
106 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
110 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
117 var currentElementChild = currentElement.childNodes[i];
119 while (currentElementChild) {
120 // Formatting code (indent the tree so it looks nice on the screen)
122 if (currentElementChild.nodeName == '#text') {
123 cb(currentElementChild.nodeValue);
125 currentElementChild=currentElement.childNodes[i];
130 for (j = 0; j < depth; j++) {
131 // ¦ is just a vertical line
136 // Recursively traverse the tree structure of the child node
137 this.traverseDOMTree(cb, currentElementChild, depth+1);
139 currentElementChild=currentElement.childNodes[i];
142 // The remaining code is mostly for formatting the tree
144 for (j = 0; j < depth - 1; j++) {
149 cb("</"+tagName+">");
156 frameClearAll : function(isAuto) {
157 // this.renderObj = { isBuilder : true };
160 if (this.panelroot) {
161 this.scroll = this.panelroot.el.getScroll();
162 this.layout.remove('center', this.panelroot);
163 this.panelroot = false;
165 if (this.dialogroot) {
166 this.dialogroot.remove();
167 this.dialogroot = false;
169 Roo.select('body > div').remove();
172 munge : function(cfg, keyname, add_xattr) {
173 keyname = keyname || false;
175 this.renderObj = this.renderObj || {};
183 if (typeof(cfg.background) != 'undefined') {
184 cfg.background = false;
189 // key is not string?!?!?!!?
190 if (typeof(p) != 'string') {
194 if (typeof(cfg[p]) == 'object') { // listeners!!!
195 this.munge(cfg[p], p, add_xattr);
199 if (p.charAt(0) == '|' || keyname=='listeners') {
201 if (!cfg[p].length) {
206 if (str.match(/\s*function/)) {
207 var btz = str.split('{');
208 str = btz.shift() +'{ try {' + btz.join('{') +
209 ' catch (e) { Roo.log(e) } }';
212 Roo.log("interpret? " + str);
214 var _this = this.renderObj; /// fake '_this' object..
215 // stupid IE can not return objects evaluated..
222 eval('_tmp =(' + str + ')');
223 cfg[p.replace(/^\|/, '')] = _tmp;
224 if (typeof(_tmp) == 'undefined') {
228 } catch(e) { console.log('Error evaluating: ' + str); };
229 //if (p.charAt(0) == '|' ) {
237 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
248 xtype : cfg['|xns'] + '.' + cfg.xtype
255 // now for all the children.. (items)
256 if (xitems === false) {
260 for (var i = 0; i < xitems.length; i++) {
261 // if +builderhide set !!!! drop it!!
265 if (typeof(xi['*prop']) != 'undefined') {
266 var pr = xi['*prop'];
267 this.munge(xi, false, add_xattr);
268 // if prop is an array - then it's items are really the value..
269 if (pr.match(/\[\]$/)) {
270 pr = pr.replace(/\[\]$/, '');
271 if (typeof(cfg[pr]) == 'undefined') {
277 if (xi.xtype && xi.xtype == 'Array') {
286 this.munge(xi, false, add_xattr);
290 if (cfg.items.length == 0) {
293 // remove listeners if there are none..
294 if (typeof(cfg['listeners']) != 'undefined') {
296 for (var i in cfg.listeners) { n++; }
298 delete cfg['listeners'];
303 if (typeof(cfg.id) != 'undefined') {
304 cfg.id = 'pman-dyn-' + cfg.id;
313 return Pman.Builder.Tree.toJS(Pman.Tab.BuilderTree.tree.root);
317 var ret = Pman.Builder.Tree.cloneConfig(n.elConfig);
319 // flag to prevent rendering..
320 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
324 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
326 if (n.childNodes.length) {
328 n.eachChild(function(cn) {
329 var add = _this.toJS(cn);
342 redraw : function(isAuto)
344 this.container.el.select('iframe',true).first().setSize(this.panel.el.getSize());
347 // top level is not relivant
349 // var btop = Pman.Tab.BuilderTop2;
350 // if (isAuto && btop.redrawBtn && !btop.redrawBtn.auto) {
351 // return; /// auto redraw is turned off..
354 this.clearAll(isAuto);
356 var cfg = this.toJS();
358 this.win().Pman.Builder.View.draw( cfg );
370 this.munge(cfg.items[0],false , true );
374 // we draw either a dialog or a tab..
376 if (cfg.items[0].xtype == 'LayoutDialog') {
378 cfg.items[0].modal = false;
379 var xy = this.el.getXY();
380 cfg.items[0].x = xy[0];
381 cfg.items[0].y = xy[1];
382 cfg.items[0].constraintoviewport = false;
384 this.dialogroot = Roo.get( this.doc).createChild();
386 this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
387 // this.dialog.el.on('click', this.panelClick, this);
389 var dlg = this.dialog;
391 dlg.moveTo(xy[0], xy[1]);
394 Roo.log("Error rendering dialog: " + e.toString());
401 if (cfg.items[0]['|xns'] == 'Roo.bootstrap') {
405 Roo.log("bootstrap build!?");
406 var top = new Roo.bootstrap.Body({});
407 top.onRender(false,false);
408 Roo.log('cfg is here');
409 Roo.log(cfg.items[0]);
410 this.bootstrapModal = top.addxtype(cfg.items[0]).items[0];
411 Roo.log("config after is now");
414 this.applyFlexy(top);
416 if (cfg.items[0].xtype =='Modal' ) {
417 this.bootstrapModal.show();
425 // should we render this into a dialog???
426 // force center region..
427 cfg.items[0].region = 'center';
428 cfg.items[0].background = false;
435 this.panelroot = this.layout.addxtype(cfg.items[0]);
438 Roo.log("Error rendering: " + e.toString());
441 //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
443 if (this.panelroot && this.panelroot.el) {
444 this.panelroot.el.scrollTo('top', 0);
445 this.panelroot.el.scrollTo('left', 0);
449 frameUpdateTheme: function(name)
451 return this.win().Pman.Builder.View.updateTheme(name);
453 updateTheme : function(name)
455 Roo.select('head link[rel=stylesheet]').each(function(e) {
456 if (!e.dom.href.match(/bootstrap\.\min.css$/)) {
459 e.dom.setAttribute('href', rootURL +'/bootswatch/' + name + '/bootstrap.min.css' );
465 applyFlexy: function(tree)
467 if (typeof(tree['flexy:foreach']) != 'undefined') {
468 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
470 if (typeof(tree['flexy:if']) != 'undefined') {
471 tree.el.attr('flexy:if', tree['flexy:if']);
473 if (!tree.items || !tree.items.length) { return; }
475 for (var i = 0; i < tree.items.length; i++){
476 this.applyFlexy(tree.items[i]);