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 if(typeof(cfg.xattr) != 'undefined'){
250 cfg.xattr.xtype = cfg['|xns'] + '.' + cfg.xtype;
253 xtype : cfg['|xns'] + '.' + cfg.xtype
261 // now for all the children.. (items)
262 if (xitems === false) {
266 for (var i = 0; i < xitems.length; i++) {
267 // if +builderhide set !!!! drop it!!
271 if (typeof(xi['*prop']) != 'undefined') {
272 var pr = xi['*prop'];
273 this.munge(xi, false, add_xattr);
274 // if prop is an array - then it's items are really the value..
275 if (pr.match(/\[\]$/)) {
276 pr = pr.replace(/\[\]$/, '');
277 if (typeof(cfg[pr]) == 'undefined') {
283 if (xi.xtype && xi.xtype == 'Array') {
292 this.munge(xi, false, add_xattr);
296 if (cfg.items.length == 0) {
299 // remove listeners if there are none..
300 if (typeof(cfg['listeners']) != 'undefined') {
302 for (var i in cfg.listeners) { n++; }
304 delete cfg['listeners'];
309 if (typeof(cfg.id) != 'undefined') {
310 cfg.id = 'pman-dyn-' + cfg.id;
319 return Pman.Builder.Tree.toJS(Pman.Tab.BuilderTree.tree.root);
323 var ret = Pman.Builder.Tree.cloneConfig(n.elConfig);
325 // flag to prevent rendering..
326 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
330 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
332 if (n.childNodes.length) {
334 n.eachChild(function(cn) {
335 var add = _this.toJS(cn);
348 redraw : function(isAuto)
350 this.container.el.select('iframe',true).first().setSize(this.panel.el.getSize());
353 // top level is not relivant
355 // var btop = Pman.Tab.BuilderTop2;
356 // if (isAuto && btop.redrawBtn && !btop.redrawBtn.auto) {
357 // return; /// auto redraw is turned off..
360 this.clearAll(isAuto);
362 var cfg = this.toJS();
364 this.win().Pman.Builder.View.draw( cfg );
376 this.munge(cfg.items[0],false , true );
380 // we draw either a dialog or a tab..
382 if (cfg.items[0].xtype == 'LayoutDialog') {
384 cfg.items[0].modal = false;
385 var xy = this.el.getXY();
386 cfg.items[0].x = xy[0];
387 cfg.items[0].y = xy[1];
388 cfg.items[0].constraintoviewport = false;
390 this.dialogroot = Roo.get( this.doc).createChild();
392 this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
393 // this.dialog.el.on('click', this.panelClick, this);
395 var dlg = this.dialog;
397 dlg.moveTo(xy[0], xy[1]);
400 Roo.log("Error rendering dialog: " + e.toString());
407 if (cfg.items[0]['|xns'] == 'Roo.bootstrap') {
409 if (cfg.items[0].xtype =='Modal' ) {
410 this.bootstrapModal = Roo.factory(cfg.items[0]);
411 this.bootstrapModal.show();
414 Roo.log("bootstrap build!?");
415 var top = new Roo.bootstrap.Body({});
416 top.onRender(false,false);
418 this.bootstrapModal = top.addxtype(cfg.items[0]);
420 this.applyFlexy(top);
429 // should we render this into a dialog???
430 // force center region..
431 cfg.items[0].region = 'center';
432 cfg.items[0].background = false;
439 this.panelroot = this.layout.addxtype(cfg.items[0]);
442 Roo.log("Error rendering: " + e.toString());
445 //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
447 if (this.panelroot && this.panelroot.el) {
448 this.panelroot.el.scrollTo('top', 0);
449 this.panelroot.el.scrollTo('left', 0);
453 frameUpdateTheme: function(name)
455 return this.win().Pman.Builder.View.updateTheme(name);
457 updateTheme : function(name)
459 Roo.select('head link[rel=stylesheet]').each(function(e) {
460 if (!e.dom.href.match(/bootstrap\.\min.css$/)) {
463 e.dom.setAttribute('href', rootURL +'/bootswatch/' + name + '/bootstrap.min.css' );
469 applyFlexy: function(tree)
471 if (typeof(tree['flexy:foreach']) != 'undefined') {
472 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
474 if (typeof(tree['flexy:if']) != 'undefined') {
475 tree.el.attr('flexy:if', tree['flexy:if']);
477 if (!tree.items || !tree.items.length) { return; }
479 for (var i = 0; i < tree.items.length; i++){
480 this.applyFlexy(tree.items[i]);