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