X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=old-javascript%2FJsRender%2FRoo.vala;fp=old-javascript%2FJsRender%2FRoo.vala;h=c28c22c83ad3e84bc82228862e2df6cc3dff7f54;hp=0000000000000000000000000000000000000000;hb=48c8b2fc9bda5825704ed41611a97932d0a854a1;hpb=cff05da1384a13d4370ac8bb57df171875f6c583 diff --git a/old-javascript/JsRender/Roo.vala b/old-javascript/JsRender/Roo.vala new file mode 100644 index 000000000..c28c22c83 --- /dev/null +++ b/old-javascript/JsRender/Roo.vala @@ -0,0 +1,640 @@ + +namespace JsRender { + + static int rid = 0; + + class Roo : JsRender + { + string region; + bool disabled; + + public Roo(Project.Project project, string path) { + base( project, path); + this.xtype = "Roo"; + this.language = "js"; + + + //this.items = false; + //if (cfg.json) { + // var jstr = JSON.parse(cfg.json); + // this.items = [ jstr ]; + // //console.log(cfg.items.length); + // delete cfg.json; // not needed! + // } + this.modOrder = "001"; /// sequence id that this uses. + this.region = "center"; + this.disabled = false; + + // super?!?! + this.id = "file-roo-%d".printf(rid++); + //console.dump(this); + // various loader methods.. + + string[] dsp = { "title", + "legend", + "loadingText", + "emptyText", + "qtip", + "value", + "text", + "emptyMsg", + "displayMsg" }; + for (var i=0;i 0 + ) { + this.tree = new Node(); + var ar = obj.get_array_member("items"); + var tree_base = ar.get_object_element(0); + this.tree.loadFromJson(tree_base, int.parse(bjs_version_str)); + } + + + + } + /** + * old code had broken xtypes and used arrays differently, + * this code should try and clean it up.. + * + * + * / + fixItems : function(node, fixthis) + { + if (fixthis) { + // fix xtype. + var fn = this.guessName(node); + //print("guessname got " + fn); + if (fn) { + var bits = fn.split('.'); + node.xtype = bits.pop(); + node['|xns'] = bits.join('.'); + + } + // fix array??? + + + } + if (!node.items || !node.items.length) { + return; + } + var _this = this; + var aitems = []; + var nitems = []; + node.items.forEach(function(i) { + + + + _this.fixItems(i, true); + if (i.xtype == 'Array') { + aitems.push(i); + return; + } + nitems.push(i); + }); + node.items = nitems; + + if (!aitems.length) { + return; + } + + aitems.forEach(function(i) { + + if (!i.items || !i.items.length) { + return; + } + var prop = i['*prop'] + '[]'; + // colModel to cm? + i.items.forEach(function(c) { + c['*prop'] = prop; + node.items.push(c); + + }); + + + }); + + + // array handling.. + + + + + + }, + */ + + public override void save() + { + + print("--- JsRender.Roo.save"); + this.saveBJS(); + + // no tree.. + if (this.tree == null) { + return; + } + // now write the js file.. + string js; + try { + Regex regex = new Regex("\\.(bjs|js)$"); + + js = regex.replace(this.path,this.path.length , 0 , ".js"); + } catch (RegexError e) { + this.name = "???"; + print("count not make filename from path"); + return; + } + + + //var d = new Date(); + var js_src = this.toSource(); + //print("TO SOURCE in " + ((new Date()) - d) + "ms"); + try { + this.writeFile(js, js_src); + } catch (FileError e ) { + print("Save failed\n"); + } + // for bootstrap - we can write the HTML to the templates directory.. + + //var top = this.guessName(this.items[0]); + //print ("TOP = " + top) + + + + + } + + + + + public override void saveHTML ( string html ) + { + + var top = this.tree.fqn(); + print ("TOP = " + top + "\n" ); + if (top.index_of("Roo.bootstrap.") < 0 && + top.index_of("Roo.mailer.") < 0 + ) { + return; + } + + +// now write the js file.. + string fn; + try { + Regex regex = new Regex("\\.(bjs|js)$"); + + fn = regex.replace(this.path,this.path.length , 0 , ".html"); + } catch (RegexError e) { + this.name = "???"; + print("count not make filename from path"); + return; + } + var bn = GLib.Path.get_basename(fn); + var dn = GLib.Path.get_dirname(fn); + + var targetdir = dn + ( + top.index_of("Roo.mailer.") < 0 ? "/templates" : "" ); + + + if (!FileUtils.test(targetdir, FileTest.IS_DIR)) { + print("Skip save - templates folder does not exist : %s\n", targetdir); + return; + } + print("SAVE HTML -- %s\n%s\n",targetdir + "/" + bn, html); + try { + this.writeFile(targetdir + "/" + bn , html); + } catch (FileError e ) { + print("SaveHtml failed\n"); + } + + + + } + + public Gee.ArrayList findxincludes(Node node, Gee.ArrayList ret) + { + + if (node.props.has_key("* xinclude")) { + ret.add(node.props.get("* xinclude")); + } + for (var i =0; i < node.items.size; i++) { + this.findxincludes(node.items.get(i), ret); + } + return ret; + + } + + /** + * javascript used in Webkit preview + */ + + public override string toSourcePreview() + { + print("to source preview\n"); + if (this.tree == null) { + return ""; + } + var top = this.tree.fqn(); + var xinc = new Gee.ArrayList(); + + this.findxincludes(this.tree, xinc); + print("got %d xincludes\n", xinc.size); + var prefix_data = ""; + if (xinc.size > 0 ) { + for(var i = 0; i < xinc.size; i++) { + print("check xinclude: %s\n", xinc.get(i)); + var sf = this.project.getByName(xinc.get(i)); + if (sf == null) { + print("Failed to find file by name?\n"); + continue; + } + + sf.loadItems(); + var xinc_str = sf.toSource(); + + //string xinc_str; + //FileUtils.get_contents(js, out xinc_str); + prefix_data += "\n" + xinc_str + "\n"; + + } + + } + + + + //print(JSON.stringify(this.items, null,4)); + + if (top == null) { + print ("guessname returned false"); + return ""; + } + + + if (top.contains("Dialog")) { + return prefix_data + this.toSourceDialog(true); + } + + if (top.contains("Modal")) { + return prefix_data + this.toSourceModal(true); + } + + return prefix_data + this.toSourceLayout(true); + + + + } + + /** + * This needs to use some options on the project + * to determine how the file is output.. + * + * At present we are hard coding it.. + * + * + */ + public override string toSource() + { + // dump the file tree back out to a string. + + // we have 2 types = dialogs and components + // + if (this.tree == null) { + return ""; + } + var top = this.tree.fqn(); + if (top == null) { + return ""; + } + if (top.contains("Dialog")) { + return this.toSourceDialog(false); + } + + if (top.contains("Modal")) { + return this.toSourceModal(false); + } + return this.toSourceLayout(false); + + /* + eventually support 'classes??' + return this.toSourceStdClass(); + */ + + } + + public string outputHeader() + { + string[] s = { + "//