Builder/Provider/File/Roo.js
authorAlan Knowles <alan@akbkhome.com>
Thu, 29 Apr 2010 05:06:59 +0000 (13:06 +0800)
committerAlan Knowles <alan@akbkhome.com>
Thu, 29 Apr 2010 05:06:59 +0000 (13:06 +0800)
Builder/Provider/File/Roo.js [new file with mode: 0755]

diff --git a/Builder/Provider/File/Roo.js b/Builder/Provider/File/Roo.js
new file mode 100755 (executable)
index 0000000..871627d
--- /dev/null
@@ -0,0 +1,249 @@
+//<Script type="text/javascript">
+console = imports['console.js']; 
+Roo = imports['Roo.js']; 
+Gio = imports.gi.Gio;
+XN = imports.xnew;
+Builder = imports['Builder.js'];
+JSDOC =  imports['JSDOC.js'];
+//----------------------- our roo verison
+
+
+
+Builder.Provider.File.Roo = function(cfg) {
+    
+    // id ,
+    //"name":"Edit Module Details",
+    // items : 
+    //"btype":"FORM", // was to be components...
+    //"app":"Builder",
+    //"module":"Pman.Tab.BuilderTop2"
+    //console.dump(cfg);
+    
+    if (!cfg.name || !cfg.fullname ) {
+        cfg.name = cfg.path.split('/').pop().replace(/\.js$/, '');
+        cfg.fullname = (cfg.parent && cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
+    }
+    
+    
+    this.items = [];
+    if (cfg.json) {
+        var jstr =  JSON.parse(cfg.json);
+        this.items = [ jstr ];
+        //console.log(cfg.items.length);
+        delete cfg.json; // not needed!
+    }
+    this.cn = [];
+     /*
+    var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
+    
+    // ensure real data is set...
+    Roo.apply(this, {
+        name : cfg.module,
+        parent : p,
+        title : cfg.name,
+        project : cfg.app
+        
+    });
+    
+    this.cn = [];
+    */
+    Builder.Provider.File.Roo.superclass.constructor.call(this, cfg);
+
+    
+    // super?!?!
+    this.id = Roo.id();
+    // various loader methods..
+   
+}
+
+Roo.extend(Builder.Provider.File.Roo, Builder.Provider.File,   {
+    setNSID : function(id)
+    {
+        
+        this.items[0]['|module'] = id;
+   
+        
+    },
+     
+    loadItems : function(cb)
+    {
+        console.log("load Items!");
+        if (this.items.length) {
+            return false;
+        }
+        var file = Gio.file_new_for_path(this.path);
+        
+        var _this = this;                        
+        file.read_async(0, null, function(source,result) {
+            var stream = source.read_finish(result)
+            var dstream = new Gio.DataInputStream.c_new(stream);
+            
+            var src = dstream.read_until("")
+            var tstream =  new JSDOC.TextStream(src);
+            var tr = new  JSDOC.TokenReader( {
+                keepWhite : true,
+                keepComments : true
+            });
+            var toks = tr.tokenize(tstream);
+            var ts = new JSDOC.Collapse(toks);
+            //console.dump(ts.tokens);
+            var rd = new JSDOC.RooFile(ts.tokens);
+            try {
+                rd.parse();
+            } catch (e) {
+                console.log(e);
+                _this.items = [ src ];
+                cb();
+                return;
+            }
+             
+            console.dump(rd.cfg);
+            //!!??? have we got engouth!
+            // try parsing self..
+            _this.items = [ rd.cfg ];
+            cb();
+            
+            
+        });
+        
+        
+        
+    },
+    
+    
+    
+    toSource: function()
+    {
+        // dump the file tree back out to a string.
+        
+        if (typeof(this.items[0]['|module']) != 'undefined') {
+            return this.toSourceStdClass();
+        }
+        
+        if (this.items[0].region) {
+            return this.toSourceLayout();
+        }
+        return this.toSourceDialog();
+        
+        
+            
+                
+            
+                
+               
+        
+    },
+   
+    outputHeader : function()
+    {
+        return [
+            "//<script type=\"text/javascript\">",
+            "",
+            "// Auto generated file - created by Builder Module - do not edit directly",
+            ""
+        ].join("\n");
+        
+   
+    },
+    // a standard dialog module.
+    toSourceDialog : function() 
+    {
+        var b = this.items[0]; 
+        var o = this.mungePropObj(this.items[0]);
+        return [
+            this.outputHeader(),
+            b['|module'] + " = {",
+            "",
+            "    dialog : false,",
+            "    callback:  false,",
+            "",   
+            "    show : function(data, cb)",
+            "    {",
+            "        if (!this.dialog) {",
+            "            this.create();",
+            "        }",
+            "",
+            "        this.callback = cb;",
+            "        this.data = data;",
+            "        this.dialog.show();",
+            "        if (this.form) {",
+            "           this.form.reset();",
+            "           this.form.setValues(data);",
+            "           this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });",
+            "        }",
+            "",   
+            "    },",
+            "",
+            "    create : function()",
+            "    {",
+            "        var _this = this;",
+            "        this.dialog = Roo.factory(" + this.objectToJsString(o,3) +  ");",
+            "    }",
+            "};",
+            ""
+            
+         ].join("\n");
+         
+         
+         
+    },
+    // a layout compoent 
+    toSourceLayout : function() 
+    {
+        var b = this.items[0]; 
+        var o = this.mungePropObj(this.items[0]);
+        
+        var disabled = typeof(b['|disabled']) == 'undefined' ? (b.disabled || false) : b['disabled'];
+        
+        return [
+            this.outputHeader(),
+            "",
+            "",
+            "// register the module first",
+            "Pman.on('beforeload', function()",
+            "{",
+            "    Pman.register({",
+            "        modKey : '" + (b.modkey  || "000-unnumbered module") +"',",
+            "        module : " + b['|module']  + ",",
+            "        region : '" + (b.region  || '') +"',",
+            "        parent : " + (b.parent  || false) + ",",
+            "        name : \"" + (b.name  || "unnamed module") + "\"",
+            "        disabled : " + disabled +" ",
+            "    });",
+            "});",
+            "",
+            
+            b['|module']  +  " = new Roo.util.Observable({",
+            "",
+            "    panel : false,",
+            "    disabled : false,",
+            "    parentLayout:  false,",
+            "",
+            "    add : function(parentLayout, region)",
+            "    {",
+            "",
+            "        var _this = this;", // standard avaialbe..
+            "        this.parentLayout = parentLayout;",
+            "",
+            "        this.panel = parentLayout.addxtype(" + this.objectToJsString(o,3) +  ");",
+            "        this.layout = this.panel.layout;",
+            "",
+            "    }",
+            "});",
+            ""
+             
+            
+         ].join("\n");
+    }
+        
+    
+    /*
+    getTree : function( o ) {
+        
+        
+        
+    }
+    */
+    
+});
\ No newline at end of file