1 //<Script type="text/javascript">
6 XObject = imports.XObject.XObject;
9 //----------------------- our roo verison
10 Base = imports.JsRender.Base.Base;
11 File = imports.File.File;
14 //----------------------- our roo verison
22 //"name":"Edit Module Details",
24 //"btype":"FORM", // was to be components...
26 //"module":"Pman.Tab.BuilderTop2"
29 if (!cfg.name || !cfg.fullname ) {
30 cfg.name = cfg.path.split('/').pop().replace(/\.bjs$/, '').replace(/\.js$/, '');
31 //cfg.fullname = (cfg.parent && cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
32 cfg.fullname = cfg.name;
38 var jstr = JSON.parse(cfg.json);
39 this.items = [ jstr ];
40 //console.log(cfg.items.length);
41 delete cfg.json; // not needed!
45 Roo.superclass.constructor.call(this, cfg);
49 this.id = 'roo-file-' + (rid++);
50 // various loader methods..
65 path : '', // the file path..
66 modOrder : '001', /// sequence id that this uses.
69 title : '', // the title on displayed when loading.
70 disable : '', // use a function to that returns false to disable this..
71 permname: '', /// permission name
75 setNSID : function(id)
78 this.items[0]['|module'] = id;
89 loadItems : function(cb, sync)
95 if (this.items !== false) {
101 function loaded(src) {
102 var cfg = JSON.parse(src);
103 print("loaded data");
104 //print(JSON.stringify(cfg, null,4));
105 _this.modOrder = cfg.modOrder || '001';
106 _this.name = cfg.name.replace(/\.bjs/, ''); // BC!
107 _this.parent = cfg.parent;
108 _this.permname = cfg.permname || '';
109 _this.title = cfg.title;
110 _this.items = cfg.items || [];
112 _this.fixItems(_this, false);
119 loaded(File.read(this.path));
124 var file = Gio.file_new_for_path(this.path);
127 file.read_async(0, null, function(source,result) {
128 var stream = source.read_finish(result)
129 var dstream = new Gio.DataInputStream.c_new(stream);
131 loaded (dstream.read_until(""));
142 * old code had broken xtypes and used arrays differently,
143 * this code should try and clean it up..
147 fixItems : function(node, fixthis)
151 var fn = this.guessName(node);
152 //print("guessname got " + fn);
154 var bits = fn.split('.');
155 node.xtype = bits.pop();
156 node['|xns'] = bits.join('.');
163 if (!node.items || !node.items.length) {
169 for (var ii = 0; ii < node.items.length;ii++) {
170 var i = node.items[ii];
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) {
213 print("--- JsRender.Roo.save");
214 Base.prototype.save.call(this);
215 // now write the js file..
216 var js = this.path.replace(/\.bjs$/, '.js');
218 var js_src = this.toSource();
219 print("TO SOURCE in " + ((new Date()) - d) + "ms");
220 File.write(js, js_src);
221 // for bootstrap - we can write the HTML to the templates directory..
223 var top = this.guessName(this.items[0]);
224 print ("TOP = " + top)
232 saveHTML : function(frame) {
233 var top = this.guessName(this.items[0]);
234 print ("TOP = " + top)
235 if (top != 'Roo.bootstrap.Body') {
238 print("SAVE HTML -- ");
243 GLib.timeout_add_seconds(0, 1, function() {
244 // print("run refresh?");
245 var html = _this.traversedom(frame);
249 var dir = File.dirname(_this.path) + File.SEPARATOR + 'templates';
251 if (!File.isDirectory(dir)) {
252 print("Skip no template sub-directory");
255 var fn = dir + File.SEPARATOR + File.basename(_this.path).replace(/\.bjs$/, '.html');
257 File.write(fn, html);
260 return false; // only once..
272 traversedom : function(web_frame) {
273 print("TRAVERSE DOM?");
275 var dom = web_frame.get_dom_document().body;
278 //Roo.select('body > div',true).each(function(el) {
279 this.traverseDOMTree(function(s) { ret+=s; }, dom, 1);
284 traverseDOMTree : function(cb, currentElement, depth) {
285 if (!currentElement) {
289 if (currentElement.class_name.match(/roo-dynamic/)) {
293 //Roo.log(currentElement);
295 var nodeName = currentElement.node_name;
296 var tagName = currentElement.tag_name;
298 if (nodeName == '#text') {
299 cb(currentElement.node_value);
306 if(nodeName == 'BR'){
310 if (nodeName != 'BODY') {
315 // Prints the node tagName, such as <A>, <IMG>, etc
318 for(i = 0; i < currentElement.attributes.length;i++) {
319 var aname = currentElement.attributes.item(i).name;
324 if (currentElement.attributes.item(i).value == 'builderel') {
327 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
331 cb("<"+currentElement.tag_name+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
341 var currentElementChild = currentElement.child_nodes.item(i);
343 while (currentElementChild) {
344 // Formatting code (indent the tree so it looks nice on the screen)
346 if (currentElementChild.node_name == '#text') {
347 cb(currentElementChild.node_value);
349 currentElementChild=currentElement.child_nodes.item(i);
354 for (j = 0; j < depth; j++) {
355 // ¦ is just a vertical line
360 // Recursively traverse the tree structure of the child node
361 this.traverseDOMTree(cb, currentElementChild, depth+1);
363 currentElementChild=currentElement.child_nodes.item(i);
366 // The remaining code is mostly for formatting the tree
368 for (j = 0; j < depth - 1; j++) {
373 cb("</"+tagName+">");
381 * convert xtype for munged output..
384 mungeXtype : function(xtype, els)
386 var bits = xtype.split('.');
387 // assume it has lenght!
389 els.push("xtype: '"+ bits.pop()+"'");
390 els.push('xns: '+ bits.join('.'));
391 if (xtype.match(/bootstrap/)) {
392 els.push("'xtype-bootstrap' : '"+ xtype +"'");
401 toSourcePreview: function()
404 var top = this.guessName(this.items[0]);
405 print(JSON.stringify(this.items, null,4));
412 if (top.match(/Dialog/)) {
413 return this.toSourceDialog(true);
416 if (top.match(/Modal/)) {
417 return this.toSourceModal(true);
420 return this.toSourceLayout(true);
427 * This needs to use some options on the project
428 * to determine how the file is output..
430 * At present we are hard coding it..
436 // dump the file tree back out to a string.
438 // we have 2 types = dialogs and components
440 var top = this.guessName(this.items[0]);
444 if (top.match(/Dialog/)) {
445 return this.toSourceDialog();
448 if (top.match(/Modal/)) {
449 return this.toSourceModal(true);
451 return this.toSourceLayout();
454 eventually support 'classes??'
455 return this.toSourceStdClass();
460 outputHeader : function()
463 "//<script type=\"text/javascript\">",
465 "// Auto generated file - created by app.Builder.js- do not edit directly (at present!)",
471 // a standard dialog module.
472 // fixme - this could be alot neater..
473 toSourceDialog : function(isPreview)
476 isPreview = isPreview || false;
477 var items = JSON.parse(JSON.stringify(this.items[0]));
478 var o = this.mungeToString(items, false, ' ');
486 " show : function(data, cb)",
488 " if (!this.dialog) {",
492 " this.callback = cb;",
493 " this.data = data;",
494 " this.dialog.show(this.data._el);",
496 " this.form.reset();",
497 " this.form.setValues(data);",
498 " this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });",
503 " create : function()",
505 " var _this = this;",
506 " this.dialog = Roo.factory(" + o + ");",
517 toSourceModal : function(isPreview)
520 isPreview = isPreview || false;
521 var items = JSON.parse(JSON.stringify(this.items[0]));
522 var o = this.mungeToString(items, false, ' ');
530 " show : function(data, cb)",
532 " if (!this.dialog) {",
536 " this.callback = cb;",
537 " this.data = data;",
538 " this.dialog.show(this.data._el);",
540 " this.form.reset();",
541 " this.form.setValues(data);",
542 " this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });",
547 " create : function()",
549 " var _this = this;",
550 " this.dialog = Roo.factory(" + o + ");",
562 pathToPart : function()
564 var dir = File.basename(File.dirname(this.path));
565 var modname = dir.split('.').pop();
567 // now we have the 'module name'..
568 var fbits = File.basename(this.path).split('.');
569 fbits.pop(); // remove extension..
570 var npart = fbits.pop(); // this should be 'AdminProjectManager' for example...
571 if (npart.substring(0, modname.length) == modname) {
572 npart = npart.substring(modname.length);
574 return [ modname , npart];
582 toSourceLayout : function(isPreview)
584 isPreview = isPreview || false;
585 var topItem = JSON.parse(JSON.stringify(this.items[0]));
587 topItem.region = 'center';
588 topItem.background = false;
591 var o = this.mungeToString(topItem, false, ' ');
593 var modkey = this.modOrder + '-' + this.name.replace(/[^A-Z.]+/ig, '-');
595 var parent = (this.parent ? "'" + this.parent + "'" : 'false');
604 this.name + " = new Roo.XComponent({",
605 " part : "+ JSON.stringify(this.pathToPart()) + ",",
606 /// critical used by builder to associate modules/parts/persm
607 " order : '" +modkey+"',",
608 " region : '" + this.region +"',",
609 " parent : "+ parent + ",",
610 " name : " + JSON.stringify(this.title || "unnamed module") + ",",
611 " disabled : " + (this.disabled || 'false') +", ",
612 " permname : '" + (this.permname|| '') +"', ",
614 // " tree : function() { return this._tree(); },", //BC
615 " _tree : function()",
617 " var _this = this;", // bc
618 " var MODULE = this;", /// this looks like a better name.
619 " return " + o + ';',
628 guessName : function(ar) // turns the object into full name.
630 // eg. xns: Roo, xtype: XXX -> Roo.xxx
635 ret.push(typeof( ar['|xns'] ) == 'undefined' ? 'Roo' : ar['|xns'] );
639 if (typeof( ar['xtype'] ) == 'undefined' || !ar['xtype'].length) {
642 var xtype = ar['xtype'] + '';
643 if (xtype[0] == '*') { // prefixes????
644 xtype = xtype.substring(1);
646 if (xtype.match(/^Roo/)) {
647 // already starts with roo...
651 var str = ret.join('.');
655 var pm = imports.ProjectManager.ProjectManager;
656 return pm.getPalete('Roo').guessName(ret.join('.'));
662 getTree : function( o ) {
668 getHelpUrl : function(cls)
670 return 'http://www.akbkhome.com/roojs1/docs/symbols/' + cls + '.html';