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