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