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);
104 // Prints the node tagName, such as <A>, <IMG>, etc
107 for(i = 0; i < currentElement.attributes.length;i++) {
108 var aname = currentElement.attributes.item(i).name;
112 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
116 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
123 var currentElementChild = currentElement.childNodes[i];
125 while (currentElementChild) {
126 // Formatting code (indent the tree so it looks nice on the screen)
128 if (currentElementChild.nodeName == '#text') {
129 cb(currentElementChild.nodeValue);
131 currentElementChild=currentElement.childNodes[i];
136 for (j = 0; j < depth; j++) {
137 // ¦ is just a vertical line
142 // Recursively traverse the tree structure of the child node
143 this.traverseDOMTree(cb, currentElementChild, depth+1);
145 currentElementChild=currentElement.childNodes[i];
148 // The remaining code is mostly for formatting the tree
150 for (j = 0; j < depth - 1; j++) {
155 cb("</"+tagName+">");
162 frameClearAll : function(isAuto) {
163 // this.renderObj = { isBuilder : true };
166 if (this.panelroot) {
167 this.scroll = this.panelroot.el.getScroll();
168 this.layout.remove('center', this.panelroot);
169 this.panelroot = false;
171 if (this.dialogroot) {
172 this.dialogroot.remove();
173 this.dialogroot = false;
175 Roo.select('body > div').remove();
178 munge : function(cfg, keyname, add_xattr) {
179 keyname = keyname || false;
181 this.renderObj = this.renderObj || {};
189 if (typeof(cfg.background) != 'undefined') {
190 cfg.background = false;
195 // key is not string?!?!?!!?
196 if (typeof(p) != 'string') {
200 if (typeof(cfg[p]) == 'object') { // listeners!!!
201 this.munge(cfg[p], p, add_xattr);
205 if (p.charAt(0) == '|' || keyname=='listeners') {
207 if (!cfg[p].length) {
212 if (str.match(/\s*function/)) {
213 var btz = str.split('{');
214 str = btz.shift() +'{ try {' + btz.join('{') +
215 ' catch (e) { Roo.log(e) } }';
218 Roo.log("interpret? " + str);
220 var _this = this.renderObj; /// fake '_this' object..
221 // stupid IE can not return objects evaluated..
228 eval('_tmp =(' + str + ')');
229 cfg[p.replace(/^\|/, '')] = _tmp;
230 if (typeof(_tmp) == 'undefined') {
234 } catch(e) { console.log('Error evaluating: ' + str); };
235 //if (p.charAt(0) == '|' ) {
243 if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
254 if(typeof(cfg.xattr) != 'undefined'){
256 cfg.xattr.xtype = cfg['|xns'] + '.' + cfg.xtype;
259 xtype : cfg['|xns'] + '.' + cfg.xtype
267 // now for all the children.. (items)
268 if (xitems === false) {
272 for (var i = 0; i < xitems.length; i++) {
273 // if +builderhide set !!!! drop it!!
277 if (typeof(xi['*prop']) != 'undefined') {
278 var pr = xi['*prop'];
279 this.munge(xi, false, add_xattr);
280 // if prop is an array - then it's items are really the value..
281 if (pr.match(/\[\]$/)) {
282 pr = pr.replace(/\[\]$/, '');
283 if (typeof(cfg[pr]) == 'undefined') {
289 if (xi.xtype && xi.xtype == 'Array') {
298 this.munge(xi, false, add_xattr);
302 if (cfg.items.length == 0) {
305 // remove listeners if there are none..
306 if (typeof(cfg['listeners']) != 'undefined') {
308 for (var i in cfg.listeners) { n++; }
310 delete cfg['listeners'];
315 if (typeof(cfg.id) != 'undefined') {
316 cfg.id = 'pman-dyn-' + cfg.id;
325 return Pman.Builder.Tree.toJS(Pman.Tab.BuilderTree.tree.root);
329 var ret = Pman.Builder.Tree.cloneConfig(n.elConfig);
331 // flag to prevent rendering..
332 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
336 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
338 if (n.childNodes.length) {
340 n.eachChild(function(cn) {
341 var add = _this.toJS(cn);
354 redraw : function(isAuto)
356 this.container.el.select('iframe',true).first().setSize(this.panel.el.getSize());
359 // top level is not relivant
361 // var btop = Pman.Tab.BuilderTop2;
362 // if (isAuto && btop.redrawBtn && !btop.redrawBtn.auto) {
363 // return; /// auto redraw is turned off..
366 this.clearAll(isAuto);
368 var cfg = this.toJS();
370 this.win().Pman.Builder.View.draw( cfg );
382 this.munge(cfg.items[0],false , true );
386 // we draw either a dialog or a tab..
388 if (cfg.items[0].xtype == 'LayoutDialog') {
390 cfg.items[0].modal = false;
391 var xy = this.el.getXY();
392 cfg.items[0].x = xy[0];
393 cfg.items[0].y = xy[1];
394 cfg.items[0].constraintoviewport = false;
396 this.dialogroot = Roo.get( this.doc).createChild();
398 this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
399 // this.dialog.el.on('click', this.panelClick, this);
401 var dlg = this.dialog;
403 dlg.moveTo(xy[0], xy[1]);
406 Roo.log("Error rendering dialog: " + e.toString());
413 if (cfg.items[0]['|xns'] == 'Roo.bootstrap') {
415 if (cfg.items[0].xtype =='Modal' ) {
416 this.bootstrapModal = Roo.factory(cfg.items[0]);
417 this.bootstrapModal.show();
420 Roo.log("bootstrap build!?");
421 var top = new Roo.bootstrap.Body({});
422 top.onRender(false,false);
424 this.bootstrapModal = top.addxtype(cfg.items[0]);
426 this.applyFlexy(top);
435 // should we render this into a dialog???
436 // force center region..
437 cfg.items[0].region = 'center';
438 cfg.items[0].background = false;
445 this.panelroot = this.layout.addxtype(cfg.items[0]);
448 Roo.log("Error rendering: " + e.toString());
451 //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
453 if (this.panelroot && this.panelroot.el) {
454 this.panelroot.el.scrollTo('top', 0);
455 this.panelroot.el.scrollTo('left', 0);
459 frameUpdateTheme: function(name)
461 return this.win().Pman.Builder.View.updateTheme(name);
463 updateTheme : function(name)
465 Roo.select('head link[rel=stylesheet]').each(function(e) {
466 if (!e.dom.href.match(/bootstrap\.\min.css$/)) {
469 e.dom.setAttribute('href', rootURL +'/themes/' + name + '/bootstrap.min.css' );
475 applyFlexy: function(tree)
477 if (typeof(tree['flexy:foreach']) != 'undefined') {
478 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
480 if (typeof(tree['flexy:if']) != 'undefined') {
481 tree.el.attr('flexy:if', tree['flexy:if']);
483 if (typeof(tree['flexy:nameuses']) != 'undefined') {
484 (tree.inputEl() !== 'undefined') ? tree.inputEl().attr('flexy:nameuses', tree['flexy:nameuses']) : tree.el.attr('flexy:nameuses', tree['flexy:nameuses']);
486 if (!tree.items || !tree.items.length) { return; }
488 for (var i = 0; i < tree.items.length; i++){
489 this.applyFlexy(tree.items[i]);