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