resources/roo.builder.js
authorAlan Knowles <alan@roojs.com>
Wed, 27 Aug 2014 07:52:47 +0000 (15:52 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 27 Aug 2014 07:52:47 +0000 (15:52 +0800)
resources/roo.builder.js

index e91201f..c0292be 100644 (file)
@@ -12,411 +12,7 @@ Builder  = {
     
     id : 1,
     
-    render : function(data, clsname)
-    {
-        
-       // console.log(data);
-        console.log(clsname);
-        // for debugging 
-        // console.log(data);        return; 
-        //Roo.log(data);
-        //Roo.log(data);
-        // This would be alot simpler if we just use the XComponent code...
-        // data should now be dialog or xcomponent..
-        // only snag here is that we do not know the name currently..
-        //Roo.log(clsname);
-        var  ix = '_src_' + this.id++;
-        // should replace module name with Builder._src_{id}
-        data =  data.replace(clsname, 'Builder.' + ix);
-        // next.. we need to ensure that parent is set correctly..
-        // done by sender... otherwise building becomes difficult..
-        //data  += "\n" + 'Builder.' + ix + ".parent = '#renderel';\n";
-        console.log(data);
-        //Roo.log(data);return;
-        //Roo.log(data);
-        if (this.scriptTag) { 
-            document.body.removeChild(this.scriptTag);
-            this.scriptTag = false;
-        }
-        
-        this.scriptTag = document.body.appendChild(document.createElement('script'));
-        this.scriptTag.setAttribute('type','text/javascript');
-         
-        this.id++;
-        this.scriptTag.appendChild(
-                    document.createTextNode(
-                            data 
-        ));
-         
-        
-        //Roo.log(this.tree);
-        MODULE = { isBuilder : true }; 
-        _this = MODULE;
-        if (!Builder.click) {
-            Builder.click= Roo.get(document.body).on('click', this.onclick, this);
-        }
-        Roo.log('Builder.'+ ix);
-        Roo.XComponent.build();
-        return;
-        
-        return;
-        var  wait_for_tree = function() {
-            
-            Builder.tree = Builder[ix];
-            if (!Builder.tree) {
-                Roo.log("Wating for tree : " + ix);
-                wait_for_tree.defer(100);
-                return;
-            }
-             Builder.redraw(false);
-        }
-        wait_for_tree.defer(100);
-    },
-    
-    
-    
-    tree : {}, 
-    renderObj :  { isBuilder : true },
-    dialogroot : false,
-    
-    redrawClear : function(isAuto)
-    {
-        this.renderObj = { isBuilder : true };
-        
-        this.scroll = {
-            top:0,
-            left:0
-        };
-        
-         
-        
-        //if (this.panelroot) {
-        //    this.scroll = this.panelroot.el.getScroll();
-        //    this.layout.remove('center', this.panelroot);
-        //    this.panelroot = false;
-        //}
-        if (this.dialogroot) {
-            this.dialogroot.remove();
-            this.dialogroot = false;
-        }
-        if (this.layoutbase) {
-            //console.log(Builder.dump(this.layoutbase.el));
-            
-            
-            try {
-                var pan = this.layoutbase.getRegion('center').getPanel(0);
-                if (pan) {
-                    this.layoutbase.remove('center', pan);
-                }
-                
-                
-            } catch( e) {
-                console.log(e);
-                console.log(JSON.stringify(e));
-                // reload!!?
-            }
-            
-            
-            
-            //this.layoutbase= false;
-        }
-         
-        
-    },
-    
-    
-    redraw: function(isAuto)
-    {
-        
-        // top level is not relivant
-        this.redrawClear(isAuto);
-        
-        
-        var cfg =  this.tree;
-        //console.log(this.dump(cfg));
-        if (!cfg) {
-            return;
-        }
-        
-        
-        this.munge(cfg);
-        this.cfg = cfg;
-        //console.log(this.dump(cfg)); 
-        // we draw either a dialog or a tab..
-        
-        if (cfg.xtype == 'LayoutDialog') {
-            
-            cfg.modal = false;
-            //var xy  = Pman.Tab.BuilderPanel.panel.el.getXY();
-            //cfg.items[0].x = xy[0];
-            //cfg.items[0].y = xy[1];
-            //cfg.items[0].constraintoviewport = false;
-        
-            this.dialogroot = Roo.get( document.body).createChild({
-                id : cfg.id
-            });
-            
-            
-            MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
-            //this.dialog.el.on('click', this.panelClick, this);
-            MODULE.dialog.show();
-            return;
-            
-        }
-        
-        // otherwise we are creating a layout area on the document..
-        
-         
-        // handles 
-        // contentpanel, nestedlayoutpanel, contentpanel.. etc. 
-        // force center region..
-        cfg.region = 'center';
-        cfg.background = false;
-        if (!this.layoutbase) {
-                
-            this.layoutbase = new Ext.BorderLayout(document.body, {
-              
-                 center: {
-                    titlebar: false,
-                    autoScroll:false,
-                    closeOnTab: true,
-                    tabPosition: 'top',
-                    //resizeTabs: true,
-                    alwaysShowTabs: true,
-                    minTabWidth: 140
-                }
-            });
-        }
-        try {
-            console.log("ADDING CFG");    
-            console.log(cfg)
-            this.layoutbase.addxtype(  cfg ); 
-        } catch (e) {
-            console.log("GOT ERROR? - saved in Builder.lastError");
-            Builder.lastError = e;
-            console.log(e);
-            console.log(typeof(e));
-            
-            console.log(this.dump(e));
-            console.trace();
-        }
-        
-        
-    },
-  
-    
-    munge :function (cfg, isListener)
-    {
-        var xitems = false;
-        //cfg.cls = cfg.cls || '';
-        //cfg.cls += ' ' + cfg.id;
-        if (!cfg.id) {
-            this.dump(cfg);
-        }
-        
-        //console.log(cfg.xtype + ': ' + cfg.id);
-        
-        if (cfg.items) {
-            xitems = cfg.items;
-            delete cfg.items;
-        }
-        if (typeof(cfg.background) != 'undefined') {
-            cfg.background = false;
-        }
-        
-        var xtype = (cfg['|xns'] || '')  + '.' + (cfg.xtype || '');
-        
-        for(var p in cfg){
-            // key is not string?!?!?!!?
-          
-            if (typeof(p) != 'string') {
-                continue;
-            }
-            
-            if (typeof(cfg[p]) == 'object') { // listeners!!!
-                this.munge(cfg[p], p == 'listeners');
-                continue;
-            }
-            // SPECIAL - PIPE
-            if (p.charAt(0) == '|' || isListener) {
-                
-                if (!cfg[p].length) {
-                    delete cfg[p];
-                    continue;
-                }
-                var pp = p.charAt(0) == '|'  ? p.substring(1) : p;
-                try {
-                    
-                    
-                    var _tmp = false;
-                    
-                    /** eval:var:MOUDULE **/
-                    /** eval:var:_this **/
-                    /** eval:var:_tmp **/
-                    // stupid IE can not return objects evaluated..
-                   // console.log('_tmp =(' + cfg[p] + ')');
-                    eval('_tmp =(' + cfg[p] + ')');
-                    cfg[pp] = _tmp;
-                    
-                    //if (typeof(_tmp) == 'undefined') {
-                    //    alert(cfg[p]);
-                   // }
-                   
-                } catch(e) {  
-                    console.log('Error evaluating: '  + cfg[p] + "\r\n" + JSON.stringify(e)); 
-                };
-                if (pp != p) {
-                    delete cfg[p];
-                }
-                
-                    
-                
-                continue;
-            }
-            // skip '*'
-            if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
-                delete cfg[p];
-                continue;
-            }
-            // normal..
-              
-        }
-        
-        if (cfg.xtype && cfg.xtype.match(/^Roo\./) && !cfg.xns) {
-            // xtype contains full path..
-            var bits = cfg.xtype.split('.');
-            bits.shift(); // remove roo..
-            cfg.xtype = bits.pop(); // get the last bit..
-            cfg.xns = Roo;
-            while (bits.length) {
-                cfg.xns = cfg.xns[bits.shift()]; 
-            }
-             
-        }
-        if (cfg.xtype) {
-            if (!cfg.xns || typeof(cfg.xns[cfg.xtype]) == 'undefined') {
-                throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
-            }
-        }
-        if (!isListener) {
-            cfg.listeners = cfg.listeners || {};
-        }
-        // we can overlay some event handlers here..
-        
-       
-        //console.log('xtype'  + xtype)
-        switch(xtype) {
-            case 'Roo.LayoutDialog':
-                cfg.listeners.resize = function(dlg, w,h)
-                {
-                    console.log('{ "id" : "' + dlg.id + '", "set" : "width", "value": ' + w + '}');
-                    console.log('{ "id" : "' + dlg.id + '", "set" : "height", "value": ' + h + '}');
-                }
-                break;
-        }
-        
-        
-        
-        
-        
-        // now for all the children.. (items)
-        if (xitems === false) {
-            
-            return;
-        }
-        cfg.items = [];
-        for (var i = 0; i < xitems.length; i++) {
-            // if +builderhide set !!!! drop it!!
-            
-            
-            var xi = xitems[i];
-            if (typeof(xi['*prop']) != 'undefined') {
-                //console.log('adding prop:' + xi['*prop']);
-                
-                var pr = xi['*prop'];
-                this.munge(xi);
-                // if prop is an array - then it's items are really the value..
-                if (pr.match(/\[\]$/)) {
-                    //console.log('adding array?:' + pr);
-                    pr = pr.replace(/\[\]$/, '');
-                    cfg[pr] = cfg[pr]  || [];
-                    cfg[pr].push(xi);
-                    continue;
-                }
-                
-                
-                if (xi.xtype && xi.xtype  == 'Array') {
-                    cfg[pr] = xi.items;
-                } else {
-                    //console.log('setting property:' + pr);
-                    cfg[pr] = xi;
-                }
-                
-                
-                continue;
-            }
-            this.munge(xi);
-            cfg.items.push(xi);
-        }
-        
-        if (cfg.items.length == 0) {
-            delete cfg.items;
-        }
-        console.log(cfg);
-        
-        
-    },
-    
-    
-    
-    cloneConfig : function(config) {
-               if (!config) { return null; }
-               var newConfig = {};
-               for (var i in config) {
-                       if (typeof config[i] == 'object') {
-                               newConfig[i] = this.cloneConfig(config[i]);
-                       } else if (typeof config[i] != 'function') {
-                               newConfig[i] = config[i];
-                       }
-               }
-               return newConfig;
-       },
-    dump : function (arr,level) {
-        var dumped_text = "";
-        if(!level) level = 0;
-        if (level >  3) {
-            return '... TO DEEP ...';
-        }
-        //The padding given at the beginning of the line.
-        var level_padding = "";
-        for(var j=0;j<level+1;j++) level_padding += "    ";
-        
-        if(typeof(arr) == 'object') { //Array/Hashes/Objects 
-            for(var item in arr) {
-                
-                var value = arr[item];
-                if (item == 'xns') {
-                    continue;
-                }
-                if(typeof(value) == 'function') { //If it is an array,
-                    // fake dump...
-                    dumped_text += level_padding + "'" + item + "' : function() { ... },\n";
-                    continue;
-                }
-                if(typeof(value) == 'object') { //If it is an array,
-                    dumped_text += level_padding + "'" + item + "': {\n";
-                    dumped_text += this.dump(value,level+1);
-                    dumped_text += level_padding + "}\n";
-                    continue;
-                }
-                dumped_text += level_padding + "'" + item + "' : \"" + value + "\"\n";
-                
-            }
-        } else { //Stings/Chars/Numbers etc.
-            dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
-        }
-        return dumped_text;
-    },
+     
     findNode : function(ftg , method) {
         if (!ftg) {
             return; false