Builder3/Window.js
[app.Builder.js] / dbgenerate.js
index 231246f..e81c5ae 100644 (file)
  * 
  * write readers..
  * 
- * usage: seed generate.js  
+ * usage: seed generate.js
+ *
+ *
+ *
+ *
+ *Hack needed to latest GLib-2.0.gir 
+ *
+ * <record name="KeyFile" c:type="GKeyFile" disguised="1">
+       <constructor name="new" c:identifier="g_key_file_new">
+        <return-value transfer-ownership="full">
+          <type name="KeyFile" c:type="GKeyFile*"/>
+        </return-value>
+      </constructor>
+ *
+ *
+ * remove introspectable =0 from g_key_file_get_groups
+ *   and add transfer-owneership = none to return value
+ * remove introspectable =0 from g_key_file_get_keys
+ *   and add transfer-owneership = none to return value* 
  * 
  */
 Gda  = imports.gi.Gda;
@@ -25,7 +43,7 @@ console = imports.console;
 File = imports.File.File;
 Options = imports.Options.Options;
 
-Gda.init();
+//Gda.init();
 
 var prov = Gda.Config.list_providers ();
 //print(prov.dump_as_string());
@@ -96,11 +114,13 @@ Gda.DataSelect.prototype.fetchAll = function()
 
 var map = {
     'date' : 'date',
-    'datetime' : 'string',
+    'datetime' : 'date',
+    'time' : 'string', //bogus
     'int' : 'int',
     'bigint' : 'int',
-    
+    'double' : 'float',
     'tinyint' : 'int',
+    'smallint' : 'int',
     'decimal' : 'float',
     'float' : 'float',
     'char' : 'string',
@@ -128,9 +148,10 @@ function readIni(fn)
     var groups = key_file.get_groups();
     groups.forEach(function(g) {
         ini[g] = {}
-           
+           print("KEY:"+g);
         var keys = key_file.get_keys(g);
-        keys.forEach(function(k) {
+        if (!keys) { return; }
+         keys.forEach(function(k) {
             ini[g][k] = key_file.get_value(g,k);
         })
     })
@@ -144,6 +165,7 @@ if (File.isFile(cfg.INI)) {
     }
 }
 
+
 if (File.isDirectory(cfg.INI)) {
         
 
@@ -458,6 +480,7 @@ readers.forEach(function(reader) {
 
     var dir = GLib.get_home_dir() + '/.Builder/Roo.data.JsonReader'; 
     if (!File.isDirectory(dir)) {
+        print("mkdir " + dir);
         File.mkdir(dir);
     }
     
@@ -472,6 +495,7 @@ readers.forEach(function(reader) {
         root : "data",
         '*prop' : "reader",
         id : 'id', // maybe no..
+       
         '|fields' :  JSON.stringify(reader.reader, null,4).replace(/"/g,"'")
     };
     
@@ -484,6 +508,7 @@ readers.forEach(function(reader) {
     // GRIDS
     dir = GLib.get_home_dir() + '/.Builder/Roo.GridPanel'; 
     if (!File.isDirectory(dir)) {
+        print("mkdir " + dir);
         File.mkdir(dir);
     }
     
@@ -502,6 +527,7 @@ readers.forEach(function(reader) {
             "fitContainer": true,
             "tableName": reader.table,
             "background": true,
+            "region" : 'center',
             "listeners": {
                 "|activate": "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
             },
@@ -514,12 +540,19 @@ readers.forEach(function(reader) {
                     "listeners": {
                         "|render": "function() \n" +
                             "{\n" +
-                            "   _this.grid = this; \n" +
+                            "    _this.grid = this; \n" +
                             "    //_this.dialog = Pman.Dialog.FILL_IN\n" +
                             "    if (_this.panel.active) {\n" +
                             "       this.footer.onClick('first');\n" +
                             "    }\n" +
-                            "}"
+                            "}",
+                        "|rowdblclick": "function (_self, rowIndex, e)\n" + 
+                            "{\n" + 
+                            "    if (!_this.dialog) return;\n" + 
+                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + 
+                            "        _this.grid.footer.onClick('first');\n" + 
+                            "    }); \n" + 
+                            "}\n"
                     },
                     "|xns": "Roo.grid",
 
@@ -527,7 +560,8 @@ readers.forEach(function(reader) {
                         {
                             "*prop": "dataSource",
                             "xtype": "Store",
-                            
+                             remoteSort : true,
+                            '|sortInfo' : "{ field : '" + reader.firstTxtCol  +  "', direction: 'ASC' }", 
                             "|xns": "Roo.data",
                             "items": [
                                 
@@ -563,9 +597,10 @@ readers.forEach(function(reader) {
                                     "listeners": {
                                         "|click": "function()\n"+
                                             "{\n"+
-                                            "   //yourdialog.show( { id : 0 } , function() {\n"+
-                                            "   //  _this.grid.footer.onClick('first');\n"+
-                                            "   //}); \n"+
+                                            "    if (!_this.dialog) return;\n" +
+                                            "    _this.dialog.show( { id : 0 } , function() {\n"+
+                                            "        _this.grid.footer.onClick('first');\n"+
+                                            "   }); \n"+
                                             "}\n"
                                     },
                                     "|xns": "Roo.Toolbar"
@@ -583,10 +618,10 @@ readers.forEach(function(reader) {
                                             "        Roo.MessageBox.alert(\"Error\", s.length ? \"Select only one Row\" : \"Select a Row\");\n"+
                                             "        return;\n"+
                                             "    }\n"+
-                                            "    \n"+
-                                            "    //_this.dialog.show(s[0].data, function() {\n"+
-                                            "    //    _this.grid.footer.onClick('first');\n"+
-                                            "    //   }); \n"+
+                                            "    if (!_this.dialog) return;\n" +
+                                            "    _this.dialog.show(s[0].data, function() {\n"+
+                                            "        _this.grid.footer.onClick('first');\n"+
+                                            "    }); \n"+
                                             "    \n"+
                                             "}\n" 
                                         
@@ -601,7 +636,7 @@ readers.forEach(function(reader) {
                                     "listeners": {
                                         "|click": "function()\n"+
                                             "{\n"+
-                                            "   //Pman.genericDelete(_this, _this.grid.tableName); \n"+
+                                            "     Pman.genericDelete(_this, '" + reader.table + "'); \n"+
                                             "}\n"+
                                             "        "
                                     },
@@ -621,16 +656,23 @@ readers.forEach(function(reader) {
     
     dir = GLib.get_home_dir() + '/.Builder/Roo.form.Form'; 
     if (!File.isDirectory(dir)) {
+        print("mkdir " + dir);
         File.mkdir(dir);
     }
     var formElements = [];
+    var formHeight = 50;
     for (var k in reader.form) {
         if (k == 'id') { // should really do primary key testing..
             continue;
         }
+        formHeight += reader.form[k].xtype == 'TextArea' ? 100 : 30;
+        
         formElements.push(reader.form[k]);
     }
-    formElements.push(reader.form['id']);
+    if (reader.form['id']) {
+        formElements.push(reader.form['id']);
+    }
+    
 
     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
     var frmCfg = 
@@ -689,6 +731,7 @@ readers.forEach(function(reader) {
     
     dir = GLib.get_home_dir() + '/.Builder/Roo.form.ComboBox'; 
     if (!File.isDirectory(dir)) {
+        print("mkdir " + dir);
         File.mkdir(dir);
     }
    
@@ -711,6 +754,7 @@ readers.forEach(function(reader) {
    
     dir = GLib.get_home_dir() + '/.Builder/Roo.LayoutDialog'; 
     if (!File.isDirectory(dir)) {
+        print("mkdir " + dir);
         File.mkdir(dir);
     }
     var formElements = [];
@@ -732,9 +776,9 @@ readers.forEach(function(reader) {
        
             "closable": false,
             "collapsible": false,
-            "height": 120,
+            "height": formHeight,
             "resizable": false,
-            "title": "Edit / Create Port",
+            "title": "Edit / Create " + reader.table,
             "width": 400,
             "xtype": "LayoutDialog",
             "|xns": "Roo",
@@ -751,20 +795,8 @@ readers.forEach(function(reader) {
                     "items": [
                         frmCfg
                     ]
-                }
-            ]
-        }, null,4);
-   
-   
-   
-   
-   
-   
-   
-   
-   
-   
-    
+                },
+                
                 {
                     "listeners": {
                         "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
@@ -784,7 +816,11 @@ readers.forEach(function(reader) {
                     "|xns": "Roo"
                 }
             ]
-        }
-    ]
-}
+        }, null,4)
+    );
+   
+   
+   
+});
+