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