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