1 //<Script type="text/javascript">
5 XObject = imports.XObject.XObject;
8 //----------------------- our roo verison
9 Base = imports.JsRender.Base.Base;
10 File = imports.File.File;
13 //----------------------- our roo verison
21 //"name":"Edit Module Details",
23 //"btype":"FORM", // was to be components...
25 //"module":"Pman.Tab.BuilderTop2"
28 if (!cfg.name || !cfg.fullname ) {
29 cfg.name = cfg.path.split('/').pop().replace(/\.bjs$/, '').replace(/\.js$/, '');
30 //cfg.fullname = (cfg.parent && cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
31 cfg.fullname = cfg.name;
37 var jstr = JSON.parse(cfg.json);
38 this.items = [ jstr ];
39 //console.log(cfg.items.length);
40 delete cfg.json; // not needed!
44 Roo.superclass.constructor.call(this, cfg);
48 this.id = 'roo-file-' + (rid++);
49 // various loader methods..
64 path : '', // the file path..
65 modOrder : '001', /// sequence id that this uses.
68 title : '', // the title on displayed when loading.
69 disable : '', // use a function to that returns false to disable this..
70 permname: '', /// permission name
74 setNSID : function(id)
77 this.items[0]['|module'] = id;
88 loadItems : function(cb, sync)
94 if (this.items !== false) {
100 function loaded(src) {
101 var cfg = JSON.parse(src);
102 print("loaded data");
103 //print(JSON.stringify(cfg, null,4));
104 _this.modOrder = cfg.modOrder || '001';
105 _this.name = cfg.name.replace(/\.bjs/, ''); // BC!
106 _this.parent = cfg.parent;
107 _this.permname = cfg.permname || '';
108 _this.title = cfg.title;
109 _this.items = cfg.items || [];
111 _this.fixItems(_this, false);
118 loaded(File.read(this.path));
123 var file = Gio.file_new_for_path(this.path);
126 file.read_async(0, null, function(source,result) {
127 var stream = source.read_finish(result)
128 var dstream = new Gio.DataInputStream.c_new(stream);
130 loaded (dstream.read_until(""));
141 * old code had broken xtypes and used arrays differently,
142 * this code should try and clean it up..
146 fixItems : function(node, fixthis)
150 var fn = this.guessName(node);
151 //print("guessname got " + fn);
153 var bits = fn.split('.');
154 node.xtype = bits.pop();
155 node['|xns'] = bits.join('.');
162 if (!node.items || !node.items.length) {
168 node.items.forEach(function(i) {
172 _this.fixItems(i, true);
173 if (i.xtype == 'Array') {
181 if (!aitems.length) {
185 aitems.forEach(function(i) {
187 if (!i.items || !i.items.length) {
190 var prop = i['*prop'] + '[]';
192 i.items.forEach(function(c) {
212 Base.prototype.save.call(this);
213 // now write the js file..
214 var js = this.path.replace(/\.bjs$/, '.js');
216 var js_src = this.toSource();
217 print("TO SOURCE in " + ((new Date()) - d) + "ms");
218 File.write(js, js_src);
224 * convert xtype for munged output..
227 mungeXtype : function(xtype, els)
229 var bits = xtype.split('.');
230 // assume it has lenght!
232 els.push("xtype: '"+ bits.pop()+"'");
233 els.push('xns: '+ bits.join('.'));
237 toSourcePreview: function()
240 var top = this.guessName(this.items[0]);
244 if (top.match(/Dialog/)) {
245 return this.toSourceDialog(true);
247 return this.toSourceLayout(true);
254 * This needs to use some options on the project
255 * to determine how the file is output..
257 * At present we are hard coding it..
263 // dump the file tree back out to a string.
265 // we have 2 types = dialogs and components
267 var top = this.guessName(this.items[0]);
271 if (top.match(/Dialog/)) {
272 return this.toSourceDialog();
274 return this.toSourceLayout();
277 eventually support 'classes??'
278 return this.toSourceStdClass();
283 outputHeader : function()
286 "//<script type=\"text/javascript\">",
288 "// Auto generated file - created by app.Builder.js- do not edit directly (at present!)",
294 // a standard dialog module.
295 // fixme - this could be alot neater..
296 toSourceDialog : function(isPreview)
299 isPreview = isPreview || false;
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 + ");",
341 pathToPart : function()
343 var dir = File.basename(File.dirname(this.path));
344 var modname = dir.split('.').pop();
346 // now we have the 'module name'..
347 var fbits = File.basename(this.path).split('.');
348 fbits.pop(); // remove extension..
349 var npart = fbits.pop(); // this should be 'AdminProjectManager' for example...
350 if (npart.substring(0, modname.length) == modname) {
351 npart = npart.substring(modname.length);
353 return [ modname , npart];
361 toSourceLayout : function(isPreview)
363 isPreview = isPreview || false;
364 var topItem = JSON.parse(JSON.stringify(this.items[0]));
366 topItem.region = 'center';
367 topItem.background = false;
370 var o = this.mungeToString(topItem, false, ' ');
372 var modkey = this.modOrder + '-' + this.name.replace(/[^A-Z.]+/ig, '-');
374 var parent = (this.parent ? "'" + this.parent + "'" : 'false');
382 this.name + " = new Roo.XComponent({",
383 " part : "+ JSON.stringify(this.pathToPart()) + ",",
384 /// critical used by builder to associate modules/parts/persm
385 " order : '" +modkey+"',",
386 " region : '" + this.region +"',",
387 " parent : "+ parent + ",",
388 " name : " + JSON.stringify(this.title || "unnamed module") + ",",
389 " disabled : " + (this.disabled || 'false') +", ",
390 " permname : '" + (this.permname|| '') +"', ",
392 // " tree : function() { return this._tree(); },", //BC
393 " _tree : function()",
395 " var _this = this;", // bc
396 " var MODULE = this;", /// this looks like a better name.
397 " return " + o + ';',
406 guessName : function(ar) // turns the object into full name.
408 // eg. xns: Roo, xtype: XXX -> Roo.xxx
413 ret.push(typeof( ar['|xns'] ) == 'undefined' ? 'Roo' : ar['|xns'] );
417 if (typeof( ar['xtype'] ) == 'undefined' || !ar['xtype'].length) {
420 var xtype = ar['xtype'] + '';
421 if (xtype[0] == '*') { // prefixes????
422 xtype = xtype.substring(1);
424 if (xtype.match(/^Roo/)) {
425 // already starts with roo...
429 var str = ret.join('.');
433 var pm = imports.ProjectManager.ProjectManager;
434 return pm.getPalete('Roo').guessName(ret.join('.'));
440 getTree : function( o ) {
446 getHelpUrl : function(cls)
448 return 'http://www.akbkhome.com/roojs1/docs/symbols/' + cls + '.html';