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