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 node.items.forEach(function(i) {
173 _this.fixItems(i, true);
174 if (i.xtype == 'Array') {
182 if (!aitems.length) {
186 aitems.forEach(function(i) {
188 if (!i.items || !i.items.length) {
191 var prop = i['*prop'] + '[]';
193 i.items.forEach(function(c) {
214 print("--- JsRender.Roo.save");
215 Base.prototype.save.call(this);
216 // now write the js file..
217 var js = this.path.replace(/\.bjs$/, '.js');
219 var js_src = this.toSource();
220 print("TO SOURCE in " + ((new Date()) - d) + "ms");
221 File.write(js, js_src);
222 // for bootstrap - we can write the HTML to the templates directory..
224 var top = this.guessName(this.items[0]);
225 print ("TOP = " + top)
233 saveHTML : function(frame) {
234 var top = this.guessName(this.items[0]);
235 print ("TOP = " + top)
236 if (top != 'Roo.bootstrap.Body') {
239 print("SAVE HTML -- ");
244 GLib.timeout_add_seconds(0, 1, function() {
245 // print("run refresh?");
246 var html = _this.traversedom(frame);
250 var dir = File.dirname(_this.path) + File.SEPARATOR + 'templates';
252 if (!File.isDirectory(dir)) {
253 print("Skip no template sub-directory");
256 var fn = dir + File.SEPARATOR + File.basename(_this.path).replace(/\.bjs$/, '.html');
258 File.write(fn, html);
261 return false; // only once..
273 traversedom : function(web_frame) {
274 print("TRAVERSE DOM?");
276 var dom = web_frame.get_dom_document().body;
279 //Roo.select('body > div',true).each(function(el) {
280 this.traverseDOMTree(function(s) { ret+=s; }, dom, 1);
285 traverseDOMTree : function(cb, currentElement, depth) {
286 if (!currentElement) {
290 if (currentElement.class_name.match(/roo-dynamic/)) {
294 //Roo.log(currentElement);
296 var nodeName = currentElement.node_name;
297 var tagName = currentElement.tag_name;
299 if (nodeName == '#text') {
300 cb(currentElement.node_value);
307 if(nodeName == 'BR'){
311 if (nodeName != 'BODY') {
316 // Prints the node tagName, such as <A>, <IMG>, etc
319 for(i = 0; i < currentElement.attributes.length;i++) {
320 var aname = currentElement.attributes.item(i).name;
325 if (currentElement.attributes.item(i).value == 'builderel') {
328 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
332 cb("<"+currentElement.tag_name+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
342 var currentElementChild = currentElement.child_nodes.item(i);
344 while (currentElementChild) {
345 // Formatting code (indent the tree so it looks nice on the screen)
347 if (currentElementChild.node_name == '#text') {
348 cb(currentElementChild.node_value);
350 currentElementChild=currentElement.child_nodes.item(i);
355 for (j = 0; j < depth; j++) {
356 // ¦ is just a vertical line
361 // Recursively traverse the tree structure of the child node
362 this.traverseDOMTree(cb, currentElementChild, depth+1);
364 currentElementChild=currentElement.child_nodes.item(i);
367 // The remaining code is mostly for formatting the tree
369 for (j = 0; j < depth - 1; j++) {
374 cb("</"+tagName+">");
382 * convert xtype for munged output..
385 mungeXtype : function(xtype, els)
387 var bits = xtype.split('.');
388 // assume it has lenght!
390 els.push("xtype: '"+ bits.pop()+"'");
391 els.push('xns: '+ bits.join('.'));
392 if (xtype.match(/bootstrap/)) {
393 els.push("'xtype-bootstrap' : '"+ xtype +"'");
402 toSourcePreview: function()
405 var top = this.guessName(this.items[0]);
406 print(JSON.stringify(this.items, null,4));
413 if (top.match(/Dialog/)) {
414 return this.toSourceDialog(true);
417 if (top.match(/Modal/)) {
418 return this.toSourceModal(true);
421 return this.toSourceLayout(true);
428 * This needs to use some options on the project
429 * to determine how the file is output..
431 * At present we are hard coding it..
437 // dump the file tree back out to a string.
439 // we have 2 types = dialogs and components
441 var top = this.guessName(this.items[0]);
445 if (top.match(/Dialog/)) {
446 return this.toSourceDialog();
449 if (top.match(/Modal/)) {
450 return this.toSourceModal(true);
452 return this.toSourceLayout();
455 eventually support 'classes??'
456 return this.toSourceStdClass();
461 outputHeader : function()
464 "//<script type=\"text/javascript\">",
466 "// Auto generated file - created by app.Builder.js- do not edit directly (at present!)",
472 // a standard dialog module.
473 // fixme - this could be alot neater..
474 toSourceDialog : function(isPreview)
477 isPreview = isPreview || false;
478 var items = JSON.parse(JSON.stringify(this.items[0]));
479 var o = this.mungeToString(items, false, ' ');
487 " show : function(data, cb)",
489 " if (!this.dialog) {",
493 " this.callback = cb;",
494 " this.data = data;",
495 " this.dialog.show(this.data._el);",
497 " this.form.reset();",
498 " this.form.setValues(data);",
499 " this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });",
504 " create : function()",
506 " var _this = this;",
507 " this.dialog = Roo.factory(" + o + ");",
518 toSourceModal : function(isPreview)
521 isPreview = isPreview || false;
522 var items = JSON.parse(JSON.stringify(this.items[0]));
523 var o = this.mungeToString(items, false, ' ');
531 " show : function(data, cb)",
533 " if (!this.dialog) {",
537 " this.callback = cb;",
538 " this.data = data;",
539 " this.dialog.show(this.data._el);",
541 " this.form.reset();",
542 " this.form.setValues(data);",
543 " this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });",
548 " create : function()",
550 " var _this = this;",
551 " this.dialog = Roo.factory(" + o + ");",
563 pathToPart : function()
565 var dir = File.basename(File.dirname(this.path));
566 var modname = dir.split('.').pop();
568 // now we have the 'module name'..
569 var fbits = File.basename(this.path).split('.');
570 fbits.pop(); // remove extension..
571 var npart = fbits.pop(); // this should be 'AdminProjectManager' for example...
572 if (npart.substring(0, modname.length) == modname) {
573 npart = npart.substring(modname.length);
575 return [ modname , npart];
583 toSourceLayout : function(isPreview)
585 isPreview = isPreview || false;
586 var topItem = JSON.parse(JSON.stringify(this.items[0]));
588 topItem.region = 'center';
589 topItem.background = false;
592 var o = this.mungeToString(topItem, false, ' ');
594 var modkey = this.modOrder + '-' + this.name.replace(/[^A-Z.]+/ig, '-');
596 var parent = (this.parent ? "'" + this.parent + "'" : 'false');
605 this.name + " = new Roo.XComponent({",
606 " part : "+ JSON.stringify(this.pathToPart()) + ",",
607 /// critical used by builder to associate modules/parts/persm
608 " order : '" +modkey+"',",
609 " region : '" + this.region +"',",
610 " parent : "+ parent + ",",
611 " name : " + JSON.stringify(this.title || "unnamed module") + ",",
612 " disabled : " + (this.disabled || 'false') +", ",
613 " permname : '" + (this.permname|| '') +"', ",
615 // " tree : function() { return this._tree(); },", //BC
616 " _tree : function()",
618 " var _this = this;", // bc
619 " var MODULE = this;", /// this looks like a better name.
620 " return " + o + ';',
629 guessName : function(ar) // turns the object into full name.
631 // eg. xns: Roo, xtype: XXX -> Roo.xxx
636 ret.push(typeof( ar['|xns'] ) == 'undefined' ? 'Roo' : ar['|xns'] );
640 if (typeof( ar['xtype'] ) == 'undefined' || !ar['xtype'].length) {
643 var xtype = ar['xtype'] + '';
644 if (xtype[0] == '*') { // prefixes????
645 xtype = xtype.substring(1);
647 if (xtype.match(/^Roo/)) {
648 // already starts with roo...
652 var str = ret.join('.');
656 var pm = imports.ProjectManager.ProjectManager;
657 return pm.getPalete('Roo').guessName(ret.join('.'));
663 getTree : function( o ) {
669 getHelpUrl : function(cls)
671 return 'http://www.akbkhome.com/roojs1/docs/symbols/' + cls + '.html';