Builder/Provider/File/Roo.js
[app.Builder.js] / Builder / Provider / File / Roo.js
1 //<Script type="text/javascript">
2 console = imports['console.js']; 
3 Roo = imports['Roo.js']; 
4 Gio = imports.gi.Gio;
5 XN = imports.xnew;
6  
7 Builder = imports['Builder.js'];
8 JSDOC =  imports['JSDOC.js'];
9 //----------------------- our roo verison
10
11
12
13 Builder.Provider.File.Roo = function(cfg) {
14     
15     // id ,
16     //"name":"Edit Module Details",
17     // items : 
18     //"btype":"FORM", // was to be components...
19     //"app":"Builder",
20     //"module":"Pman.Tab.BuilderTop2"
21     //console.dump(cfg);
22     
23     if (!cfg.name || !cfg.fullname ) {
24         cfg.name = cfg.path.split('/').pop().replace(/\.js$/, '');
25         cfg.fullname = (cfg.parent && cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
26     }
27     
28     
29     this.items = [];
30     if (cfg.json) {
31         var jstr =  JSON.parse(cfg.json);
32         this.items = [ jstr ];
33         //console.log(cfg.items.length);
34         delete cfg.json; // not needed!
35     }
36     this.cn = [];
37      /*
38     var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
39     
40     // ensure real data is set...
41     Roo.apply(this, {
42         name : cfg.module,
43         parent : p,
44         title : cfg.name,
45         project : cfg.app
46         
47     });
48     
49     this.cn = [];
50     */
51     Builder.Provider.File.Roo.superclass.constructor.call(this, cfg);
52
53     
54     // super?!?!
55     this.id = Roo.id();
56     // various loader methods..
57    
58 }
59
60 Roo.extend(Builder.Provider.File.Roo, Builder.Provider.File,   {
61     setNSID : function(id)
62     {
63         
64         this.items[0]['|module'] = id;
65    
66         
67     },
68      
69     loadItems : function(cb)
70     {
71         console.log("load Items!");
72         if (this.items.length) {
73             return false;
74         }
75         var file = Gio.file_new_for_path(this.path);
76         
77         var _this = this;                        
78         file.read_async(0, null, function(source,result) {
79             var stream = source.read_finish(result)
80             var dstream = new Gio.DataInputStream.c_new(stream);
81             
82             var src = dstream.read_until("")
83             var tstream =  new JSDOC.TextStream(src);
84             var tr = new  JSDOC.TokenReader( {
85                 keepWhite : true,
86                 keepComments : true
87             });
88             var toks = tr.tokenize(tstream);
89             var ts = new JSDOC.Collapse(toks);
90             //console.dump(ts.tokens);
91             var rd = new JSDOC.RooFile(ts.tokens);
92             try {
93                 rd.parse();
94             } catch (e) {
95                 console.log(e);
96                 _this.items = [ src ];
97                 cb();
98                 return;
99             }
100              
101             console.dump(rd.cfg);
102             //!!??? have we got engouth!
103             // try parsing self..
104             _this.items = [ rd.cfg ];
105             cb();
106             
107             
108         });
109         
110         
111         
112     },
113     
114     
115     
116     toSource: function()
117     {
118         // dump the file tree back out to a string.
119         
120         if (typeof(this.items[0]['|module']) != 'undefined') {
121             return this.toSourceStdClass();
122         }
123         
124         if (this.items[0].region) {
125             return this.toSourceLayout();
126         }
127         return this.toSourceDialog();
128         
129         
130             
131                 
132             
133                 
134                
135         
136     },
137    
138     outputHeader : function()
139     {
140         return [
141             "//<script type=\"text/javascript\">",
142             "",
143             "// Auto generated file - created by Builder Module - do not edit directly",
144             ""
145         ].join("\n");
146         
147    
148     },
149     // a standard dialog module.
150     toSourceDialog : function() 
151     {
152         var b = this.items[0]; 
153         var o = this.mungePropObj(this.items[0]);
154         return [
155             this.outputHeader(),
156             b['|module'] + " = {",
157             "",
158             "    dialog : false,",
159             "    callback:  false,",
160             "",   
161             "    show : function(data, cb)",
162             "    {",
163             "        if (!this.dialog) {",
164             "            this.create();",
165             "        }",
166             "",
167             "        this.callback = cb;",
168             "        this.data = data;",
169             "        this.dialog.show();",
170             "        if (this.form) {",
171             "           this.form.reset();",
172             "           this.form.setValues(data);",
173             "           this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });",
174             "        }",
175             "",   
176             "    },",
177             "",
178             "    create : function()",
179             "    {",
180             "        var _this = this;",
181             "        this.dialog = Roo.factory(" + this.objectToJsString(o,3) +  ");",
182             "    }",
183             "};",
184             ""
185             
186          ].join("\n");
187          
188          
189          
190     },
191     // a layout compoent 
192     toSourceLayout : function() 
193     {
194         var b = this.items[0]; 
195         var o = this.mungePropObj(this.items[0]);
196         
197         var disabled = typeof(b['|disabled']) == 'undefined' ? (b.disabled || false) : b['disabled'];
198         
199         return [
200             this.outputHeader(),
201             "",
202             "",
203             "// register the module first",
204             "Pman.on('beforeload', function()",
205             "{",
206             "    Pman.register({",
207             "        modKey : '" + (b.modkey  || "000-unnumbered module") +"',",
208             "        module : " + b['|module']  + ",",
209             "        region : '" + (b.region  || '') +"',",
210             "        parent : " + (b.parent  || false) + ",",
211             "        name : \"" + (b.name  || "unnamed module") + "\"",
212             "        disabled : " + disabled +" ",
213             "    });",
214             "});",
215             "",
216             
217             b['|module']  +  " = new Roo.util.Observable({",
218             "",
219             "    panel : false,",
220             "    disabled : false,",
221             "    parentLayout:  false,",
222             "",
223             "    add : function(parentLayout, region)",
224             "    {",
225             "",
226             "        var _this = this;", // standard avaialbe..
227             "        this.parentLayout = parentLayout;",
228             "",
229             "        this.panel = parentLayout.addxtype(" + this.objectToJsString(o,3) +  ");",
230             "        this.layout = this.panel.layout;",
231             "",
232             "    }",
233             "});",
234             ""
235              
236             
237          ].join("\n");
238     }
239         
240     
241     /*
242     getTree : function( o ) {
243         
244         
245         
246     }
247     */
248     
249 });