1 //<Script type="text/javascript">
5 console = imports.console;
6 XObject = imports.XObject.XObject;
9 //----------------------- our roo verison
10 Base = imports.Builder.Provider.File.Base.Base;
12 File = imports.File.File;
14 //JSDOC = imports['JSDOC.js'];
15 //----------------------- our roo verison
23 //"name":"Edit Module Details",
25 //"btype":"FORM", // was to be components...
27 //"module":"Pman.Tab.BuilderTop2"
30 if (!cfg.name || !cfg.fullname ) {
31 cfg.name = cfg.path.split('/').pop().replace(/\.bjs$/, '');
32 //cfg.fullname = (cfg.parent && cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
33 cfg.fullname = cfg.name;
39 var jstr = JSON.parse(cfg.json);
40 this.items = [ jstr ];
41 //console.log(cfg.items.length);
42 delete cfg.json; // not needed!
46 var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
48 // ensure real data is set...
59 Roo.superclass.constructor.call(this, cfg);
63 this.id = 'roo-file-' + (rid++);
64 // various loader methods..
77 modOrder : '001', /// sequence id that this uses.
80 title : '', // the title on displayed when loading.
81 disable : '', // use a function to that returns false to disable this..
82 permname: '', /// permission name
84 setNSID : function(id)
87 this.items[0]['|module'] = id;
98 loadItems : function(cb)
100 console.log("load Items!");
101 if (this.items !== false) {
104 var file = Gio.file_new_for_path(this.path);
107 file.read_async(0, null, function(source,result) {
108 var stream = source.read_finish(result)
109 var dstream = new Gio.DataInputStream.c_new(stream);
111 var src = dstream.read_until("")
113 var cfg = JSON.parse(src);
114 print("loaded data");
116 _this.modOrder = cfg.modOrder || '001';
117 _this.name = cfg.name.replace(/\.bjs/, ''); // BC!
118 _this.parent = cfg.parent;
119 _this.permname = cfg.permname || '';
120 _this.title = cfg.title;
121 _this.items = cfg.items || [];
123 _this.fixItems(_this, false);
129 var tstream = new JSDOC.TextStream(src);
130 var tr = new JSDOC.TokenReader( {
134 var toks = tr.tokenize(tstream);
135 var ts = new JSDOC.Collapse(toks);
136 //console.dump(ts.tokens);
137 var rd = new JSDOC.RooFile(ts.tokens);
142 _this.items = [ src ];
147 console.dump(rd.cfg);
148 //!!??? have we got engouth!
149 // try parsing self..
150 _this.items = [ rd.cfg ];
160 * old code had broken xtypes and used arrays differently,
161 * this code should try and clean it up..
165 fixItems : function(node, fixthis)
169 var fn = this.guessName(node);
170 //print("guessname got " + fn);
172 var bits = fn.split('.');
173 node.xtype = bits.pop();
174 node['|xns'] = bits.join('.');
181 if (!node.items || !node.items.length) {
187 node.items.forEach(function(i) {
191 _this.fixItems(i, true);
192 if (i.xtype == 'Array') {
200 if (!aitems.length) {
204 aitems.forEach(function(i) {
206 if (!i.items || !i.items.length) {
209 var prop = i['*prop'] + '[]';
211 i.items.forEach(function(c) {
231 Base.prototype.save.call(this);
232 // now write the js file..
233 var js = this.path.replace(/\.bjs$/, '.js');
235 var js_src = this.toSource();
236 print("TO SOURCE in " + ((new Date()) - d) + "ms");
237 File.write(js, js_src);
243 * convert xtype for munged output..
246 mungeXtype : function(xtype, els)
248 var bits = xtype.split('.');
249 // assume it has lenght!
251 els.push("xtype: '"+ bits.pop()+"'");
252 els.push('xns: '+ bits.join('.'));
256 * This needs to use some options on the project
257 * to determine how the file is output..
259 * At present we are hard coding it..
265 // dump the file tree back out to a string.
267 // we have 2 types = dialogs and components
269 var top = this.guessName(this.items[0]);
273 if (top.match(/Dialog/)) {
274 return this.toSourceDialog();
276 return this.toSourceLayout();
279 eventually support 'classes??'
280 return this.toSourceStdClass();
285 outputHeader : function()
288 "//<script type=\"text/javascript\">",
290 "// Auto generated file - created by app.Builder.js- do not edit directly (at present!)",
296 // a standard dialog module.
297 // fixme - this could be alot neater..
298 toSourceDialog : function()
300 var items = JSON.parse(JSON.stringify(this.items[0]));
301 var o = this.mungeToString(items, false, ' ');
309 " show : function(data, cb)",
311 " if (!this.dialog) {",
315 " this.callback = cb;",
316 " this.data = data;",
317 " this.dialog.show(this.data._el);",
319 " this.form.reset();",
320 " this.form.setValues(data);",
321 " this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });",
326 " create : function()",
328 " var _this = this;",
329 " this.dialog = Roo.factory(" + o + ");",
340 toSourceLayout : function()
342 var items = JSON.parse(JSON.stringify(this.items[0]));
343 var o = this.mungeToString(items, false, ' ');
345 var modkey = this.modOrder + '-' + this.name.replace('/[^A-Z]+/ig', '-');
348 if (this.name.match(/^Pman/)) {
351 // old BC way we did things..
356 "// register the module first",
357 "Pman.on('beforeload', function()",
360 " modKey : '" +modkey+"',",
361 " module : " + this.name + ",",
362 " moduleName : '" + this.name + "',",
363 " region : '" + this.region +"',",
364 " parent : " + (this.parent || 'false') + ",",
365 " name : " + JSON.stringify(this.title || "unnamed module") + ",",
366 " disabled : " + (this.disabled || 'false') +", ",
367 " permname: '" + (this.permname|| '') +"' ",
372 this.name + " = new Roo.util.Observable({",
375 " disabled : false,",
376 " parentLayout: false,",
378 " add : function(parentLayout, region)",
381 " var _this = this;", // standard avaialbe..
382 " this.parentLayout = parentLayout;",
384 " this.panel = parentLayout.addxtype(" + o + ");",
385 " this.layout = this.panel.layout;",
399 this.name + " = new Roo.XComponent({",
400 " order : '" +modkey+"',",
401 " region : '" + this.region +"',",
402 " parent : "+ (this.parent ? "'" + this.parent + "'" : 'false') + ",",
403 " name : " + JSON.stringify(this.title || "unnamed module") + ",",
404 " disabled : " + (this.disabled || 'false') +", ",
405 " tree : function()",
407 " var _this = this;", // bc
408 " var MODULE = this;", /// this looks like a better name.
409 " return " + o + ';',
418 guessName : function(ar) // turns the object into full name.
420 // eg. xns: Roo, xtype: XXX -> Roo.xxx
425 ret.push(typeof( ar['|xns'] ) == 'undefined' ? 'Roo' : ar['|xns'] );
429 if (typeof( ar['xtype'] ) == 'undefined' || !ar['xtype'].length) {
432 var xtype = ar['xtype'] + '';
433 if (xtype[0] == '*') { // prefixes????
434 xtype = xtype.substring(1);
436 if (xtype.match(/^Roo/)) {
437 // already starts with roo...
441 var str = ret.join('.');
445 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
446 return pm.getPalete('Roo').guessName(ret.join('.'));
452 getTree : function( o ) {
458 getHelpUrl : function(cls)
460 return 'http://www.akbkhome.com/roojs1/docs/symbols/' + cls + '.html';