tests/TreeBuilder.vala
[app.Builder.js] / builder.html.js
index bf03495..ec722e5 100644 (file)
@@ -1,26 +1,80 @@
 //<script type="text/javascript">
  
-var _this = { isBuilder : true };
-   
+
+var MODULE = { isBuilder : true };
+// BC
+var _this = MODULE;
+
+// the apprenderer.
 Builder  = {
     
-    render : function(data)
+    scriptTag : false,
+    
+    id : 1,
+    
+    render : function(data, clsname)
     {
-        // for debugging 
-         console.log(data);        return;
         
+       // 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 
+        ));
+         
         
-        this.tree = data;
-        _this = { isBuilder : true };
+        //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;
         
-        this.redraw(false);
+        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,
@@ -103,9 +157,9 @@ Builder  = {
             });
             
             
-            this.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
+            MODULE.dialog = new Roo[cfg.xtype](this.dialogroot, cfg);
             //this.dialog.el.on('click', this.panelClick, this);
-            this.dialog.show();
+            MODULE.dialog.show();
             return;
             
         }
@@ -138,11 +192,13 @@ Builder  = {
             console.log(cfg)
             this.layoutbase.addxtype(  cfg ); 
         } catch (e) {
-            console.log("GOT ERROR?");    
+            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();
         }
         
         
@@ -194,7 +250,7 @@ Builder  = {
                     
                     var _tmp = false;
                     
-                    
+                    /** eval:var:MOUDULE **/
                     /** eval:var:_this **/
                     /** eval:var:_tmp **/
                     // stupid IE can not return objects evaluated..
@@ -242,9 +298,11 @@ Builder  = {
                 throw "Invalid Xtype " + cfg.xtype + ' on ' + cfg.xtreepath;
             }
         }
-        
+        if (!isListener) {
+            cfg.listeners = cfg.listeners || {};
+        }
         // we can overlay some event handlers here..
-        cfg.listeners = cfg.listeners || {};
+        
        
         //console.log('xtype'  + xtype)
         switch(xtype) {
@@ -263,6 +321,7 @@ Builder  = {
         
         // now for all the children.. (items)
         if (xitems === false) {
+            
             return;
         }
         cfg.items = [];
@@ -500,8 +559,66 @@ Builder  = {
        var bid = id.length ? 'builder-' + id : '';
        console.log('{ "hover-node" :  "' + bid + '"}');
        this.lastID = id;
+    },
+    clearBootstrap : function()
+    {
+        // if the page is not bootstrap
+        
+        if ( typeof(BuilderUseBootstrap) != 'undefined' ) {
+            Roo.log("it's boostrap - BuilderUseBootstrap is defined ");
+            // it's bootstrap - probably remove roo's css..
+            return;
+        }
+        Roo.log("remove css = BuilderUseBootstrap is not defined");
+        var rem = [];
+        var ar = document.getElementsByTagName('link');
+        for (var i = 0; i < ar.length;i++) {
+            var l = ar[i];
+            Roo.log(l.getAttribute('href'));
+            if (l.getAttribute('href').match(/bootstrap/)) {
+                rem.push(l);
+                
+                
+            }
+            //code
+        }
+        Roo.each(rem, function(l) { l.parentNode.removeChild(l);});
+    },
+    
+    applyFlexy: function(tree)
+    {
+        if (typeof(tree['flexy:foreach']) != 'undefined') {
+            //Roo.log("add flexy:foreach");
+            tree.el.attr('flexy:foreach', tree['flexy:foreach']);
+        }
+        if (typeof(tree['flexy:if']) != 'undefined') {
+            //Roo.log("add flexy:if");
+            tree.el.attr('flexy:if', tree['flexy:if']);
+        }
+        if (typeof(tree['flexy:include']) != 'undefined') {
+            //Roo.log("add flexy:if");
+            tree.el.attr('flexy:include', tree['flexy:include']);
+        }
+        
+        if (typeof(tree['xtype-bootstrap']) != 'undefined') {
+            //Roo.log("add flexy:if");
+            tree.el.attr('xtype', tree['xtype-bootstrap']);
+        }
+        
+        
+        if (!tree.items || !tree.items.length) { return; }
+        
+        for (var i = 0; i < tree.items.length; i++){
+            this.applyFlexy(tree.items[i]);
+        }
     }
-            
+    
+     
     
 };
-    
\ No newline at end of file
+Roo.onReady(function() { Builder.clearBootstrap(); });
+Roo.XComponent.on('buildcomplete', function() {
+    Roo.log("xcomponent built!");
+    
+    Builder.applyFlexy(Roo.XComponent.modules[0].el);
+});
\ No newline at end of file