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