src/Builder4/DialogPluginWebkit.bjs
[app.Builder.js] / src / Builder4 / DialogPluginWebkit.bjs
1 {
2  "name" : "DialogPluginWebkit",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/alan/gitlive/app.Builder.js/src/Builder4/DialogPluginWebkit.bjs",
6  "permname" : "",
7  "modOrder" : "",
8  "items" : [
9   {
10    "listeners" : {
11     "delete_event" : "(self, event) => {\n    this.el.hide();\n    return true; \n    //test  \n}\n "
12    },
13    "string tmpjs" : "",
14    "utf8 title" : "Add / Edit Component",
15    "id" : "DialogPluginWebkit",
16    "| boolean has_plugin" : "(string cls) {\n\n     return GLib.FileUtils.test(\n            BuilderApplication.configDirectory() + \"/resources/Editors/Editor.\" + cls + \".js\",\n            GLib.FileTest.IS_REGULAR\n      );\n    \n\n\n}\n",
17    "gint default_height" : 500,
18    "gboolean deletable" : true,
19    "xtype" : "Dialog",
20    "| string show" : " (Gtk.Window ?parent, Project.Project project, string cls, string tbl) {// JsRender.Node node) {\n \n    if (parent  != null) {\n        this.el.set_transient_for(parent);\n        this.el.modal = true;\n    }\n     var db = project.roo_database;\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(tbl);\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      \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... (calls back into alert handler)\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",
21    "$ xns" : "Gtk",
22    "gint default_width" : 500,
23    "gboolean modal" : true,
24    "items" : [
25     {
26      "xtype" : "VBox",
27      "$ pack" : "get_content_area().add",
28      "gboolean homogeneous" : false,
29      "$ xns" : "Gtk",
30      "items" : [
31       {
32        "* init" : "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n",
33        "xtype" : "ScrolledWindow",
34        "* pack" : "pack_start,false,true,3",
35        "gboolean expand" : true,
36        "$ xns" : "Gtk",
37        "items" : [
38         {
39          "listeners" : {
40           "script_dialog" : " (dialog) => {\n    if (this.el == null) {\n        return true;\n    }\n    \n     var msg = dialog.get_message();\n     if (msg.length < 4) {\n        return false;\n     }\n     if (msg.substring(0,4) != \"IPC:\") {\n         return false;\n     }\n     var ar = msg.split(\":\", 3);\n    if (ar.length < 3) {\n        return false;\n    }\n    print(\"CMD: %s\\n\",ar[1]);\n        print(\"ARGS: %s\\n\",ar[2]);\n    switch(ar[1]) {\n        case \"SAVEHTML\":\n          print(\"%sw\",ar[2]);\n          //  _this.file.saveHTML(ar[2]);\n            return true;\n        default:\n            return true;\n    }\n    \n}"
41          },
42          "id" : "webview",
43          "* init" : " {\n    // this may not work!?\n    var settings =  this.el.get_settings();\n    settings.enable_write_console_messages_to_stdout = true;\n     \n    var fs= new FakeServer(this.el);\n    fs.ref();\n    // this was an attempt to change the url perms.. did not work..\n    // settings.enable_file_access_from_file_uris = true;\n    // settings.enable_offline_web_application_cache - true;\n    // settings.enable_universal_access_from_file_uris = true;\n   \n     \n    \n    \n    \n\n     // FIXME - base url of script..\n     // we need it so some of the database features work.\n    this.el.load_html( \"Render not ready\" , \n            //fixme - should be a config option!\n            // or should we catch stuff and fix it up..\n            \"xhttp://localhost/app.Builder/\"\n    );\n        \n        \n    \n    \n}\n",
44          "xtype" : "WebView",
45          "* pack" : "add",
46          "$ xns" : "WebKit"
47         }
48        ]
49       }
50      ]
51     },
52     {
53      "label" : "Reload",
54      "* pack" : "add_action_widget,3",
55      "xtype" : "Button",
56      "$ xns" : "Gtk"
57     },
58     {
59      "label" : "Cancel",
60      "xtype" : "Button",
61      "* pack" : "add_action_widget,0",
62      "$ xns" : "Gtk"
63     },
64     {
65      "label" : "OK",
66      "* pack" : "add_action_widget,1",
67      "xtype" : "Button",
68      "$ xns" : "Gtk"
69     }
70    ]
71   }
72  ]
73 }