src/Builder4/DialogPluginWebkit.bjs
authorAlan Knowles <alan@roojs.com>
Wed, 22 Apr 2015 07:38:31 +0000 (15:38 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 22 Apr 2015 07:38:31 +0000 (15:38 +0800)
src/Builder4/DialogPluginWebkit.vala

src/Builder4/DialogPluginWebkit.bjs
src/Builder4/DialogPluginWebkit.vala

index 3845a46..110cc86 100644 (file)
@@ -17,7 +17,7 @@
    "gint default_height" : 500,
    "gboolean deletable" : true,
    "xtype" : "Dialog",
-   "| string show" : " (Gtk.Window ?parent, string text) {// JsRender.Node node) {\n \n    if (parent  != null) {\n        this.el.set_transient_for(parent);\n        this.el.modal = true;\n    }\n       var db = new JsRender.RooDatabase.from_cfg (\"MySQL\", \"hydra\", \"root\", \"\");\n     \n    \n     this.el.show_all();\n     var   ret = \"\";\n    while (true) {\n    \n        var runhtml = \"<script type=\\\"text/javascript\\\">\\n\" ;\n        string builderhtml;\n        \n        \n        GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + \"/resources/roo.builder.js\", out builderhtml);\n\n        runhtml += builderhtml + \"\\n\";\n        \n        \n           runhtml += \"\\n\" +\n            \"Builder.saveHTML = function() {};\\n\" + \n\t    \"Roo.onReady(function() {\\n\" +\n\n\t    \"Roo.XComponent.build();\\n\" +\n\t    \"});\\n\";\n\t\n\t\n        \n\n        var ar = db.readForeignKeys(\"Person\");\n        var  generator = new Json.Generator ();\n        var  root = new Json.Node(Json.NodeType.OBJECT);\n        root.init_object(ar);\n        generator.set_root (root);\n        \n        generator.pretty = true;\n        generator.indent = 4;\n        \n        runhtml += \"\\n\" +\n        \" Roo.XComponent.on('buildcomplete', function() {\\n\" +\n         \"    Editor.Roo.grid.Grid.panel.loadData(\" + generator.to_data (null) + \"); \" +\n        \"});\\n\";\n\n        \n\t\n\t\n\n        runhtml += \"</script>\\n\" ;\n\n        print(runhtml);\n        // fix to make sure they are the same..\n        \n        // need to modify paths\n\n        string inhtml;\n        \n        GLib.FileUtils.get_contents(\n            BuilderApplication.configDirectory() + \"/resources/roo.builder.html\"\n                , out inhtml);\n        \n        \n        // fetch the json from the database...\n        \n        //print(runhtml);\n        \n        var html = inhtml.replace(\"</head>\", runhtml + // + this.runhtml + \n            \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost/app.Builder.js/resources/Editors/Editor.Roo.grid.Grid.js\\\"></script>\" + \n      //      \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost\" + fc.fname + \"\\\"></script>\" +   \n              //  \"<script type=\\\"text/javascript\\\">\\n\" +\n              //  js_src + \"\\n\" + \n              //  \"</script>\" + \n                        \n        \"</head>\");\n        //print(\"LOAD HTML \" + html);\n        \n         //var rootURL = _this.file.project.rootURL;\n   \n        \n        \n        this.webview.el.load_html( html , \n            //fixme - should be a config option!\n            \"xhttp://localhost/app.Builder.js/\"\n        );\n    \n        \n    \n   \n         var response_id = this.el.run();\n        \n         if (response_id == 1) { // OK...\n             var loop = new MainLoop();\n             this.webview.el.run_javascript.begin(\"Editor.Roo.grid.Grid.panel.toBJS();\", null, (obj, res) => {\n  //              print(\"GOT END?\");\n                     this.webview.el.run_javascript.end(res);\n//                                    print(\"GOT DATA?\");\n                    loop.quit();\n                });\n             loop.run();\n    //           print(\"LOOP END?\");\n             // try and get the resopse...\n            break;\n         }\n        if (response_id < 1) {\n            this.el.hide();\n             return \"\";\n        }\n        // keep showing...?\n        continue;\n    }\n    \n    // now we save it..\n    this.el.hide();\n    \n    return ret;\n    \n    \n    \n}\n",
+   "| string show" : " (Gtk.Window ?parent, string cls) {// JsRender.Node node) {\n \n    if (parent  != null) {\n        this.el.set_transient_for(parent);\n        this.el.modal = true;\n    }\n       var db = new JsRender.RooDatabase.from_cfg (\"MySQL\", \"hydra\", \"root\", \"\");\n     \n    \n     this.el.show_all();\n     var   ret = \"\";\n    while (true) {\n    \n        var runhtml = \"<script type=\\\"text/javascript\\\">\\n\" ;\n        string builderhtml;\n        \n        \n        GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + \"/resources/roo.builder.js\", out builderhtml);\n\n        runhtml += builderhtml + \"\\n\";\n        \n        \n           runhtml += \"\\n\" +\n            \"Builder.saveHTML = function() {};\\n\" + \n\t    \"Roo.onReady(function() {\\n\" +\n\n\t    \"Roo.XComponent.build();\\n\" +\n\t    \"});\\n\";\n\t\n\t\n        \n\n        var ar = db.readForeignKeys(\"Person\");\n        var  generator = new Json.Generator ();\n        var  root = new Json.Node(Json.NodeType.OBJECT);\n        root.init_object(ar);\n        generator.set_root (root);\n        \n        generator.pretty = true;\n        generator.indent = 4;\n        \n        runhtml += \"\\n\" +\n        \" Roo.XComponent.on('buildcomplete', function() {\\n\" +\n         \"    Editor.\" + cls + \".panel.loadData(\" + generator.to_data (null) + \"); \" +\n        \"});\\n\";\n\n        \n\t\n\t\n\n        runhtml += \"</script>\\n\" ;\n\n        print(runhtml);\n        // fix to make sure they are the same..\n        \n        // need to modify paths\n\n        string inhtml;\n        \n        GLib.FileUtils.get_contents(\n            BuilderApplication.configDirectory() + \"/resources/roo.builder.html\"\n                , out inhtml);\n        \n        \n        // fetch the json from the database...\n        \n        //print(runhtml);\n        \n        var html = inhtml.replace(\"</head>\", runhtml + // + this.runhtml + \n            \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost/app.Builder.js/resources/Editors/Editor.\" + cls + \".js\\\"></script>\" + \n      //      \"<script type=\\\"text/javascript\\\" src=\\\"xhttp://localhost\" + fc.fname + \"\\\"></script>\" +   \n              //  \"<script type=\\\"text/javascript\\\">\\n\" +\n              //  js_src + \"\\n\" + \n              //  \"</script>\" + \n                        \n        \"</head>\");\n        //print(\"LOAD HTML \" + html);\n        \n         //var rootURL = _this.file.project.rootURL;\n   \n        \n        \n        this.webview.el.load_html( html , \n            //fixme - should be a config option!\n            \"xhttp://localhost/app.Builder.js/\"\n        );\n    \n        \n    \n   \n         var response_id = this.el.run();\n        \n         if (response_id == 1) { // OK...\n             var loop = new MainLoop();\n             // run toBJS to get the data...\n               this.webview.el.run_javascript.begin(\"Editor.\" + cls + \".panel.toBJS();\", null, (obj, res) => {\n\n                 this.webview.el.run_javascript.end(res);\n\n                    loop.quit();\n                });\n             loop.run();\n    //           print(\"LOOP END?\");\n             // try and get the resopse...\n            break;\n         }\n        if (response_id < 1) {\n            this.el.hide();\n             return \"\";\n        }\n        // keep showing...?\n        continue;\n    }\n    \n    // now we save it..\n    this.el.hide();\n    \n    return ret;\n    \n    \n    \n}\n",
    "$ xns" : "Gtk",
    "gint default_width" : 500,
    "gboolean modal" : true,
index 54e963a..3338036 100644 (file)
@@ -63,7 +63,7 @@ public class Xcls_DialogPluginWebkit : Object
     
     
     }
-    public string show (Gtk.Window ?parent, string text) {// JsRender.Node node) {
+    public string show (Gtk.Window ?parent, string cls) {// JsRender.Node node) {
      
         if (parent  != null) {
             this.el.set_transient_for(parent);
@@ -106,7 +106,7 @@ public class Xcls_DialogPluginWebkit : Object
             
             runhtml += "\n" +
             " Roo.XComponent.on('buildcomplete', function() {\n" +
-             "    Editor.Roo.grid.Grid.panel.loadData(" + generator.to_data (null) + "); " +
+             "    Editor." + cls + ".panel.loadData(" + generator.to_data (null) + "); " +
             "});\n";
     
             
@@ -132,7 +132,7 @@ public class Xcls_DialogPluginWebkit : Object
             //print(runhtml);
             
             var html = inhtml.replace("</head>", runhtml + // + this.runhtml + 
-                "<script type=\"text/javascript\" src=\"xhttp://localhost/app.Builder.js/resources/Editors/Editor.Roo.grid.Grid.js\"></script>" + 
+                "<script type=\"text/javascript\" src=\"xhttp://localhost/app.Builder.js/resources/Editors/Editor." + cls + ".js\"></script>" + 
           //      "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
                   //  "<script type=\"text/javascript\">\n" +
                   //  js_src + "\n" + 
@@ -157,10 +157,11 @@ public class Xcls_DialogPluginWebkit : Object
             
              if (response_id == 1) { // OK...
                  var loop = new MainLoop();
-                 this.webview.el.run_javascript.begin("Editor.Roo.grid.Grid.panel.toBJS();", null, (obj, res) => {
-      //              print("GOT END?");
-                         this.webview.el.run_javascript.end(res);
-    //                                    print("GOT DATA?");
+                 // run toBJS to get the data...
+                   this.webview.el.run_javascript.begin("Editor." + cls + ".panel.toBJS();", null, (obj, res) => {
+    
+                     this.webview.el.run_javascript.end(res);
+    
                         loop.quit();
                     });
                  loop.run();