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         
77         
78          
79         loadItems : function(cb)
80         {
81             console.log("load Items!");
82             if (this.items.length) {
83                 return false;
84             }
85             var file = Gio.file_new_for_path(this.path);
86             
87             var _this = this;                        
88             file.read_async(0, null, function(source,result) {
89                 var stream = source.read_finish(result)
90                 var dstream = new Gio.DataInputStream.c_new(stream);
91                 
92                 var src = dstream.read_until("")
93                 var tstream =  new JSDOC.TextStream(src);
94                 var tr = new  JSDOC.TokenReader( {
95                     keepWhite : true,
96                     keepComments : true
97                 });
98                 var toks = tr.tokenize(tstream);
99                 var ts = new JSDOC.Collapse(toks);
100                 //console.dump(ts.tokens);
101                 var rd = new JSDOC.RooFile(ts.tokens);
102                 try {
103                     rd.parse();
104                 } catch (e) {
105                     console.log(e);
106                     _this.items = [ src ];
107                     cb();
108                     return;
109                 }
110                  
111                 console.dump(rd.cfg);
112                 //!!??? have we got engouth!
113                 // try parsing self..
114                 _this.items = [ rd.cfg ];
115                 cb();
116                 
117                 
118             });
119             
120             
121             
122         },
123         
124         
125         
126         toSource: function()
127         {
128             // dump the file tree back out to a string.
129             
130             if (typeof(this.items[0]['|module']) != 'undefined') {
131                 return this.toSourceStdClass();
132             }
133             
134             if (this.items[0].region) {
135                 return this.toSourceLayout();
136             }
137             return this.toSourceDialog();
138             
139             
140                 
141                     
142                 
143                     
144                    
145             
146         },
147        
148         outputHeader : function()
149         {
150             return [
151                 "//<script type=\"text/javascript\">",
152                 "",
153                 "// Auto generated file - created by Builder Module - do not edit directly",
154                 ""
155             ].join("\n");
156             
157        
158         },
159         // a standard dialog module.
160         toSourceDialog : function() 
161         {
162             var b = this.items[0]; 
163             var o = this.mungePropObj(this.items[0]);
164             return [
165                 this.outputHeader(),
166                 b['|module'] + " = {",
167                 "",
168                 "    dialog : false,",
169                 "    callback:  false,",
170                 "",   
171                 "    show : function(data, cb)",
172                 "    {",
173                 "        if (!this.dialog) {",
174                 "            this.create();",
175                 "        }",
176                 "",
177                 "        this.callback = cb;",
178                 "        this.data = data;",
179                 "        this.dialog.show();",
180                 "        if (this.form) {",
181                 "           this.form.reset();",
182                 "           this.form.setValues(data);",
183                 "           this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });",
184                 "        }",
185                 "",   
186                 "    },",
187                 "",
188                 "    create : function()",
189                 "    {",
190                 "        var _this = this;",
191                 "        this.dialog = Roo.factory(" + this.objectToJsString(o,3) +  ");",
192                 "    }",
193                 "};",
194                 ""
195                 
196              ].join("\n");
197              
198              
199              
200         },
201         // a layout compoent 
202         toSourceLayout : function() 
203         {
204             var b = this.items[0]; 
205             var o = this.mungePropObj(this.items[0]);
206             
207             var disabled = typeof(b['|disabled']) == 'undefined' ? (b.disabled || false) : b['disabled'];
208             
209             return [
210                 this.outputHeader(),
211                 "",
212                 "",
213                 "// register the module first",
214                 "Pman.on('beforeload', function()",
215                 "{",
216                 "    Pman.register({",
217                 "        modKey : '" + (b.modkey  || "000-unnumbered module") +"',",
218                 "        module : " + b['|module']  + ",",
219                 "        region : '" + (b.region  || '') +"',",
220                 "        parent : " + (b.parent  || false) + ",",
221                 "        name : \"" + (b.name  || "unnamed module") + "\"",
222                 "        disabled : " + disabled +" ",
223                 "    });",
224                 "});",
225                 "",
226                 
227                 b['|module']  +  " = new Roo.util.Observable({",
228                 "",
229                 "    panel : false,",
230                 "    disabled : false,",
231                 "    parentLayout:  false,",
232                 "",
233                 "    add : function(parentLayout, region)",
234                 "    {",
235                 "",
236                 "        var _this = this;", // standard avaialbe..
237                 "        this.parentLayout = parentLayout;",
238                 "",
239                 "        this.panel = parentLayout.addxtype(" + this.objectToJsString(o,3) +  ");",
240                 "        this.layout = this.panel.layout;",
241                 "",
242                 "    }",
243                 "});",
244                 ""
245                  
246                 
247              ].join("\n");
248         }
249             
250         
251         /*
252         getTree : function( o ) {
253             
254             
255             
256         }
257         */
258         
259 });