dbgenerate.js
[app.Builder.js] / dbgenerate.js
1 //<script type="text/javascript">
2
3 /**
4  * This is a hacky generator to generate element definitions for the Roo version from the database
5  * 
6  * Let's see if libgda can be used to generate our Readers for roo...
7  * 
8  * Concept - conect to database..
9  * 
10  * list tables
11  * 
12  * extra schemas..
13  * 
14  * write readers..
15  * 
16  * usage: seed generate.js
17  *
18  *
19  *
20  *
21  *Hack needed to latest GLib-2.0.gir 
22  *
23  * <record name="KeyFile" c:type="GKeyFile" disguised="1">
24         <constructor name="new" c:identifier="g_key_file_new">
25         <return-value transfer-ownership="full">
26           <type name="KeyFile" c:type="GKeyFile*"/>
27         </return-value>
28       </constructor>
29  *
30  *
31  * remove introspectable =0 from g_key_file_get_groups
32  *   and add transfer-owneership = none to return value
33  * remove introspectable =0 from g_key_file_get_keys
34  *   and add transfer-owneership = none to return value* 
35  * 
36  */
37 Gda  = imports.gi.Gda;
38 GObject = imports.gi.GObject;
39
40 GLib = imports.gi.GLib;
41
42 console = imports.console;
43 File = imports.File.File;
44 Options = imports.Options.Options;
45
46 //Gda.init();
47
48 var prov = Gda.Config.list_providers ();
49 //print(prov.dump_as_string());
50
51 var o = new Options({
52     help_description : 'Element builder for App Builder based on database schema',
53     
54     options:  [
55         { arg_long : 'DBTYPE' , arg_short : 't', description : 'Database Type (eg. MySQL or PostgreSQL ' },
56         { arg_long : 'DBNAME' , arg_short : 'd', description : 'Database Name' },
57         { arg_long : 'USERNAME' , arg_short : 'u', description : 'Username'},
58         { arg_long : 'PASSWORD' , arg_short : 'p', description : '' , arg_default :'' },
59         { arg_long : 'INI' , arg_short : 'I', description :
60                     'Either base directory which has Pman/***/DataObjects/***.links.ini or location of ini file.' },
61     ]
62            
63 })
64
65
66
67 var cfg = o.parse(Seed.argv);
68 print(JSON.stringify(cfg, null,4));
69
70 var   cnc = Gda.Connection.open_from_string (cfg.DBTYPE,
71          "DB_NAME=" + cfg.DBNAME, 
72         "USERNAME=" + cfg.USERNAME + ';PASSWORD=' + cfg.PASSWORD,
73         Gda.ConnectionOptions.NONE, null);
74
75
76
77                                               
78
79  
80 Gda.DataSelect.prototype.fetchAll = function()
81 {
82     var cols = [];
83     
84     for (var i =0;i < this.get_n_columns(); i++) {
85         cols.push(this.get_column_name(i));
86     }
87     //print(JSON.stringify(cols, null,4));
88     var iter = this.create_iter();
89     var res = [];
90     //print(this.get_n_rows());
91     var _this = this;
92     for (var r = 0; r < this.get_n_rows(); r++) {
93         
94         // single clo..
95         //print("GOT ROW");
96         if (cols.length == 1) {
97             res.push(this.get_value_at(0,r).get_string());
98             continue;
99         }
100         var add = { };
101         
102         cols.forEach(function(n,i) {
103             var val = _this.get_value_at(i,r);
104             var type = GObject.type_name(val.g_type) ;
105             var vs = ['GdaBinary', 'GdaBlob' ].indexOf(type) > -1 ? val.value.to_string(1024) : val.value;
106             //print(n + " : TYPE: " + GObject.type_name(val.g_type) + " : " + vs);
107             //print (n + '=' + iter.get_value_at(i).value);
108             add[n] = vs;
109         });
110         
111         res.push(add);
112         
113     }
114     return res;
115
116 }
117
118 var map = {
119     'date' : 'date',
120     'datetime' : 'date',
121     'time' : 'string', //bogus
122     'int' : 'int',
123     'bigint' : 'int',
124     'double' : 'float',
125     'tinyint' : 'int',
126     'smallint' : 'int',
127     'decimal' : 'float',
128     'float' : 'float',
129     'char' : 'string',
130     'varchar' : 'string',
131     'text' : 'string',
132     'longtext' : 'string',
133     'tinytext' : 'string',
134     'mediumtext' : 'string',
135     'enum' : 'string',
136     'timestamp' : 'number',
137     'blob' : 'text'
138     
139 }
140
141 var ini = { }
142
143 function readIni(fn)
144 {
145     print('Read INI : ' + fn);
146     var key_file = new GLib.KeyFile.c_new();
147     if (!key_file.load_from_file (fn , GLib.KeyFileFlags.NONE )) {
148         return;
149     }
150    
151     var groups = key_file.get_groups();
152     groups.forEach(function(g) {
153         ini[g] = {}
154            print("KEY:"+g);
155         var keys = key_file.get_keys(g);
156         if (!keys) { return; }
157          keys.forEach(function(k) {
158             ini[g][k] = key_file.get_value(g,k);
159         })
160     })
161     
162 }
163 if (File.isFile(cfg.INI)) {
164     if (cfg.INI.match(/links\.ini$/)) {
165         readIni(cfg.INI);
166     } else {
167         readIni(cfg.INI.replace(/\.ini$/, ".links.ini"));
168     }
169 }
170
171
172 if (File.isDirectory(cfg.INI)) {
173         
174
175     //--- load ini files..
176     // this is very specific.
177     
178     var dirs = File.list( cfg.INI + '/Pman').filter( 
179         function(e) { 
180             if (!File.isDirectory(cfg.INI + '/Pman/' + e + '/DataObjects')) {
181                 return false;
182             }
183             return true;
184         }
185     );
186     
187      
188     dirs.forEach(function(d) {
189         // this currently misses the web.*/Pman/XXXX/DataObjects..
190         var path = cfg.INI + '/Pman/' + d + '/DataObjects';
191          
192         if (!File.isDirectory(path)) {
193             return; //skip
194         }
195         var inis = File.list(path).filter(
196             function(e) { return e.match(/\.links\.ini$/); }
197         );
198         if (!inis.length) {
199             return;
200         }
201         
202         inis.forEach(function(i) {
203             readIni(path + '/' + i); 
204             
205         })
206  
207     });
208     // look at web.XXXX/Pman/XXX/DataObjects/*.ini
209     var inis = File.list(cfg.INI).filter(
210         function(e) { return e.match(/\.links\.ini$/); }
211     )
212     
213      inis.forEach(function(i) {
214         readIni(path + '/' + i); 
215         
216     })
217     
218     
219 }
220 //print(JSON.stringify(ini, null,4));
221  //console.dump(ini);
222
223
224  //Seed.quit();
225
226 //GLib.key_file_load_from_file (key_file, String file, KeyFileFlags flags) : Boolean
227
228
229 switch(cfg.DBTYPE) {
230     case "MySQL":
231         query_tables = "SHOW TABLES";
232         query_describe_table = "DESCRIBE `%s`";
233         break;
234     
235     case 'PostgreSQL':
236         query_tables = "select c.relname FROM pg_catalog.pg_class c " + 
237             "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " + 
238             "WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')" +
239             "AND pg_catalog.pg_table_is_visible(c.oid) ";
240          query_describe_table =  "SELECT " + 
241                 "attname , typname FROM pg_attribute , pg_type WHERE   " +
242                 "typrelid=attrelid AND typname = '%s' ";
243         break;
244
245     
246     
247 }
248
249
250  
251
252 var tables = Gda.execute_select_command(cnc, query_tables).fetchAll();
253 print(JSON.stringify(tables));
254
255 var readers = [];
256 tables.forEach(function(table) {
257     //print(table);
258     var schema = Gda.execute_select_command(cnc,
259             query_describe_table.replace(/%s/, table) ).fetchAll();
260     
261     
262     var reader = []; 
263     var colmodel = []; 
264     var combofields= [ { name : 'id', type: 'int' } ]; // technically the primary key..
265          
266     var form = {}
267        
268     var firstTxtCol = '';
269     
270     print(JSON.stringify(schema, null,4));
271     Seed.quit();
272     
273     schema.forEach(function(e)  {
274         var type = e.Type.match(/([^(]+)\(([^\)]+)\)/);
275         var row  = { }; 
276         if (type) {
277             e.Type = type[1];
278             e.Size = type[2];
279         }
280         
281         
282         
283         row.name = e.Field;
284         
285         
286         if (typeof(map[e.Type]) == 'undefined') {
287            console.dump(e);
288            throw {
289                 name: "ArgumentError", 
290                 message: "Unknown mapping for type : " + e.Type
291             };
292         }
293         row.type = map[e.Type];
294         
295         if (row.type == 'string' && !firstTxtCol.length) {
296             firstTxtCol = row.name;
297         }
298         
299         if (row.type == 'date') {
300             row.dateFormat = 'Y-m-d';
301         }
302         reader.push(row);
303         
304         if (combofields.length == 1 && row.type == 'string') {
305             combofields.push(row);
306         }
307         
308         
309         var title = row.name.replace(/_id/, '').replace(/_/g, ' ');
310         title  = title[0].toUpperCase() + title.substring(1);
311         
312         colmodel.push({
313             "xtype": "ColumnModel",
314             "header": title,
315             "width":  row.type == 'string' ? 200 : 75,
316             "dataIndex": row.name,
317             "|renderer": row.type != 'date' ? 
318                     "function(v) { return String.format('{0}', v); }" :
319                     "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }" , // special for date
320             "|xns": "Roo.grid",
321             "*prop": "colModel[]"
322         });
323         var xtype = 'TextField';
324         if (row.type == 'number') {
325             xtype = 'NumberField';
326         }
327         if (row.type == 'date') {
328             xtype = 'DateField';
329         }
330         if (e.Type == 'text') {
331             xtype = 'TextArea';
332         }
333         if (row.name == 'id') {
334             xtype = 'Hidden';
335         } 
336         // what about booleans.. -> checkboxes..
337         
338         
339         
340         form[row.name] = {
341             fieldLabel : title,
342             name : row.name,
343             width : row.type == 'string' ? 200 : 75,
344             '|xns' : 'Roo.form',
345             xtype : xtype
346         }
347         if (xtype == 'TextArea') {
348             form[row.name].height = 100;
349         }
350         if (xtype == 'Hidden') {
351             delete form[row.name].fieldLabel;
352             delete form[row.name].width;
353         }
354         
355     });
356     
357     var combo = {
358         '|xns' : 'Roo.form',
359         xtype: 'ComboBox',
360         allowBlank : 'false',
361         editable : 'false',
362         emptyText : 'Select ' + table,
363         forceSelection : true,
364         listWidth : 400,
365         loadingText: 'Searching...',
366         minChars : 2,
367         pageSize : 20,
368         qtip: 'Select ' + table,
369         selectOnFocus: true,
370         triggerAction : 'all',
371         typeAhead: true,
372         
373         width: 300,
374         
375         
376         
377         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>', // SET WHEN USED
378         queryParam : '',// SET WHEN USED
379         fieldLabel : table,  // SET WHEN USED
380         valueField : 'id',
381         displayField : '', // SET WHEN USED eg. project_id_name
382         hiddenName : '', // SET WHEN USED eg. project_id
383         name : '', // SET WHEN USED eg. project_id_name
384         items : [
385             {
386                     
387                 '*prop' : 'store',
388                 'xtype' : 'Store',
389                 '|xns' : 'Roo.data',
390                 'remoteSort' : true,
391                 '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
392                 listeners : {
393                     '|beforeload' : 'function (_self, o)' +
394                     "{\n" +
395                     "    o.params = o.params || {};\n" +
396                     "    // set more here\n" +
397                     "}\n"
398                 },
399                 items : [
400                     {
401                         '*prop' : 'proxy',
402                         'xtype' : 'HttpProxy',
403                         'method' : 'GET',
404                         '|xns' : 'Roo.data',
405                         '|url' : "baseURL + '/Roo/" + table + ".php'",
406                     },
407                     
408                     {
409                         '*prop' : 'reader',
410                         'xtype' : 'JsonReader',
411                         '|xns' : 'Roo.data',
412                         'id' : 'id',
413                         'root' : 'data',
414                         'totalProperty' : 'total',
415                         '|fields' : JSON.stringify(combofields)
416                         
417                     }
418                 ]
419             }
420         ]
421     }
422     
423     
424     
425     
426     //print(JSON.stringify(reader,null,4));
427     readers.push({
428         table : table ,
429         combo : combo,
430         combofields : combofields,
431         reader :  reader,
432         oreader : JSON.parse(JSON.stringify(reader)), // dupe it..
433         colmodel : colmodel,
434         firstTxtCol : firstTxtCol,
435         form : form
436     });
437     
438     //console.dump(schema );
439     
440      
441 });
442
443
444
445 // merge in the linked tables..
446 readers.forEach(function(reader) {
447     if (typeof(ini[reader.table]) == 'undefined') {
448      
449         return;
450     }
451     print("OVERLAY - " + reader.table);
452     // we have a map..
453     for (var col in ini[reader.table]) {
454         var kv = ini[reader.table][col].split(':');
455         
456         
457         var add = readers.filter(function(r) { return r.table == kv[0] })[0];
458         if (!add) {
459             continue;
460         }
461         // merge in data (eg. project_id => project_id_*****
462      
463         add.oreader.forEach(function(or) {
464             reader.reader.push({
465                 name : col + '_' + or.name,
466                 type : or.type
467             });
468         });
469         
470         // col is mapped to something..
471         var combofields = add.combofields;
472         if (add.combofields.length < 2) {
473             continue;
474         }
475         if (typeof(reader.form[col]) == 'undefined') {
476             print (JSON.stringify(reader.form, null,4));
477             print("missing linked column " + col);
478             continue;
479         }
480         
481         var combofields_name = add.combofields[1].name;
482         var old =   reader.form[col];
483         reader.form[col] = JSON.parse(JSON.stringify(add.combo)); // clone
484         reader.form[col].queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
485         reader.form[col].fieldLabel = old.fieldLabel;  // SET WHEN USED
486         reader.form[col].hiddenName = old.name; // SET WHEN USED eg. project_id
487         reader.form[col].displayField = combofields_name; // SET WHEN USED eg. project_id
488         reader.form[col].name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
489         reader.form[col].tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
490         
491              
492     };
493     
494     
495 });
496
497 //readers.forEach(function(reader) {
498 //    delete reader.oreader;
499 //});
500
501  
502
503
504
505 //print(JSON.stringify(readers, null, 4));
506
507 readers.forEach(function(reader) {
508     
509
510     var dir = GLib.get_home_dir() + '/.Builder/Roo.data.JsonReader'; 
511     if (!File.isDirectory(dir)) {
512         print("mkdir " + dir);
513         File.mkdir(dir);
514     }
515     
516     // READERS
517     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
518     
519                 
520     var jreader = {
521         '|xns' : 'Roo.data',
522         xtype : "JsonReader",
523         totalProperty : "total",
524         root : "data",
525         '*prop' : "reader",
526         id : 'id', // maybe no..
527        
528         '|fields' :  JSON.stringify(reader.reader, null,4).replace(/"/g,"'")
529     };
530     
531     File.write(
532         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
533         JSON.stringify(jreader, null, 4)
534     )
535     
536     
537     // GRIDS
538     dir = GLib.get_home_dir() + '/.Builder/Roo.GridPanel'; 
539     if (!File.isDirectory(dir)) {
540         print("mkdir " + dir);
541         File.mkdir(dir);
542     }
543     
544
545     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
546     
547     File.write(
548         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
549             
550        
551         JSON.stringify({
552             '|xns' : 'Roo',
553             xtype : "GridPanel",
554             "title": reader.table,
555             "fitToframe": true,
556             "fitContainer": true,
557             "tableName": reader.table,
558             "background": true,
559             "region" : 'center',
560             "listeners": {
561                 "|activate": "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
562             },
563             "items": [
564                 {
565                     "*prop": "grid",
566                     "xtype": "Grid",
567                     "autoExpandColumn": reader.firstTxtCol,
568                     "loadMask": true,
569                     "listeners": {
570                         "|render": "function() \n" +
571                             "{\n" +
572                             "    _this.grid = this; \n" +
573                             "    //_this.dialog = Pman.Dialog.FILL_IN\n" +
574                             "    if (_this.panel.active) {\n" +
575                             "       this.footer.onClick('first');\n" +
576                             "    }\n" +
577                             "}",
578                         "|rowdblclick": "function (_self, rowIndex, e)\n" + 
579                             "{\n" + 
580                             "    if (!_this.dialog) return;\n" + 
581                             "    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + 
582                             "        _this.grid.footer.onClick('first');\n" + 
583                             "    }); \n" + 
584                             "}\n"
585                     },
586                     "|xns": "Roo.grid",
587
588                     "items": [
589                         {
590                             "*prop": "dataSource",
591                             "xtype": "Store",
592                              remoteSort : true,
593                             '|sortInfo' : "{ field : '" + reader.firstTxtCol  +  "', direction: 'ASC' }", 
594                             "|xns": "Roo.data",
595                             "items": [
596                                 
597                                 {
598                                     "*prop": "proxy",
599                                     "xtype": "HttpProxy",
600                                     "method": "GET",
601                                     "|url": "baseURL + '/Roo/" + reader.table + ".php'",
602                                     "|xns": "Roo.data"
603                                 },
604                                 jreader
605                             ]
606                         },
607                         {
608                             "*prop": "footer",
609                             "xtype": "PagingToolbar",
610                             "pageSize": 25,
611                             "displayInfo": true,
612                             "displayMsg": "Displaying " + reader.table + "{0} - {1} of {2}",
613                             "emptyMsg": "No " + reader.table + " found",
614                             "|xns": "Roo"
615                         },
616                         {
617                             "*prop": "toolbar",
618                             "xtype": "Toolbar",
619                             "|xns": "Roo",
620                             "items": [
621                                 {
622                                     "text": "Add",
623                                     "xtype": "Button",
624                                     "cls": "x-btn-text-icon",
625                                     "|icon": "Roo.rootURL + 'images/default/dd/drop-add.gif'",
626                                     "listeners": {
627                                         "|click": "function()\n"+
628                                             "{\n"+
629                                             "    if (!_this.dialog) return;\n" +
630                                             "    _this.dialog.show( { id : 0 } , function() {\n"+
631                                             "        _this.grid.footer.onClick('first');\n"+
632                                             "   }); \n"+
633                                             "}\n"
634                                     },
635                                     "|xns": "Roo.Toolbar"
636                                 },
637                                 {
638                                     "text": "Edit",
639                                     "xtype": "Button",
640                                     "cls": "x-btn-text-icon",
641                                     "|icon": "Roo.rootURL + 'images/default/tree/leaf.gif'",
642                                     "listeners": {
643                                         "|click": "function()\n"+
644                                             "{\n"+
645                                             "    var s = _this.grid.getSelectionModel().getSelections();\n"+
646                                             "    if (!s.length || (s.length > 1))  {\n"+
647                                             "        Roo.MessageBox.alert(\"Error\", s.length ? \"Select only one Row\" : \"Select a Row\");\n"+
648                                             "        return;\n"+
649                                             "    }\n"+
650                                             "    if (!_this.dialog) return;\n" +
651                                             "    _this.dialog.show(s[0].data, function() {\n"+
652                                             "        _this.grid.footer.onClick('first');\n"+
653                                             "    }); \n"+
654                                             "    \n"+
655                                             "}\n" 
656                                         
657                                     },
658                                     "|xns": "Roo.Toolbar"
659                                 },
660                                 {
661                                     "text": "Delete",
662                                     "cls": "x-btn-text-icon",
663                                     "|icon": "rootURL + '/Pman/templates/images/trash.gif'",
664                                     "xtype": "Button",
665                                     "listeners": {
666                                         "|click": "function()\n"+
667                                             "{\n"+
668                                             "     Pman.genericDelete(_this, '" + reader.table + "'); \n"+
669                                             "}\n"+
670                                             "        "
671                                     },
672                                     "|xns": "Roo.Toolbar"
673                                 }
674                             ]
675                         }, // end toolbar
676                     ].concat( reader.colmodel)
677                 }
678             ]
679             
680             
681         }, null, 4)
682     )
683     
684     /// FORMS..
685     
686     dir = GLib.get_home_dir() + '/.Builder/Roo.form.Form'; 
687     if (!File.isDirectory(dir)) {
688         print("mkdir " + dir);
689         File.mkdir(dir);
690     }
691     var formElements = [];
692     var formHeight = 50;
693     for (var k in reader.form) {
694         if (k == 'id') { // should really do primary key testing..
695             continue;
696         }
697         formHeight += reader.form[k].xtype == 'TextArea' ? 100 : 30;
698         
699         formElements.push(reader.form[k]);
700     }
701     if (reader.form['id']) {
702         formElements.push(reader.form['id']);
703     }
704     
705
706     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
707     var frmCfg = 
708     {
709         '|xns' : 'Roo.form',
710         xtype : "Form",
711         listeners : {
712             "|actioncomplete" : "function(_self,action)\n"+
713                 "{\n"+
714                 "    if (action.type == 'setdata') {\n"+
715                 "       //_this.dialog.el.mask(\"Loading\");\n"+
716                 "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
717                 "       return;\n"+
718                 "    }\n"+
719                 "    if (action.type == 'load') {\n"+
720                 "        _this.dialog.el.unmask();\n"+
721                 "        return;\n"+
722                 "    }\n"+
723                 "    if (action.type =='submit') {\n"+
724                 "    \n"+
725                 "        _this.dialog.el.unmask();\n"+
726                 "        _this.dialog.hide();\n"+
727                 "    \n"+
728                 "         if (_this.callback) {\n"+
729                 "            _this.callback.call(_this, _this.form.getValues());\n"+
730                 "         }\n"+
731                 "         _this.form.reset();\n"+
732                 "         return;\n"+
733                 "    }\n"+
734                 "}\n",
735             
736             "|rendered" : "function (form)\n"+
737                 "{\n"+
738                 "    _this.form= form;\n"+
739                 "}\n"
740         },
741         method : "POST",
742         style : "margin:10px;",
743         "|url" : "baseURL + '/Roo/" + reader.table + ".php'",
744         items : formElements
745     };
746     
747     
748     File.write(
749         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
750             
751        
752         JSON.stringify( frmCfg, null, 4)
753     );
754             
755             
756    
757    
758    
759      /// COMBO..
760     
761     dir = GLib.get_home_dir() + '/.Builder/Roo.form.ComboBox'; 
762     if (!File.isDirectory(dir)) {
763         print("mkdir " + dir);
764         File.mkdir(dir);
765     }
766    
767     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
768     
769     File.write(
770         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
771             
772        
773         JSON.stringify(reader.combo, null, 4)
774     );
775             
776    
777    
778    
779    
780    
781     // DIALOG.
782    
783    
784     dir = GLib.get_home_dir() + '/.Builder/Roo.LayoutDialog'; 
785     if (!File.isDirectory(dir)) {
786         print("mkdir " + dir);
787         File.mkdir(dir);
788     }
789     var formElements = [];
790     for (var k in reader.form) {
791         if (k == 'id') { // should really do primary key testing..
792             continue;
793         }
794         formElements.push(reader.form[k]);
795     }
796     formElements.push(reader.form['id']);
797
798     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
799     
800     File.write(
801         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
802             
803        
804         JSON.stringify({
805        
806             "closable": false,
807             "collapsible": false,
808             "height": formHeight,
809             "resizable": false,
810             "title": "Edit / Create " + reader.table,
811             "width": 400,
812             "xtype": "LayoutDialog",
813             "|xns": "Roo",
814             "items": [
815                 {
816                     "|xns": "Roo",
817                     "xtype": "LayoutRegion",
818                     "*prop": "center"
819                 },
820                 {
821                     "region": "center",
822                     "xtype": "ContentPanel",
823                     "|xns": "Roo",
824                     "items": [
825                         frmCfg
826                     ]
827                 },
828                 
829                 {
830                     "listeners": {
831                         "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
832                     },
833                     "*prop": "buttons[]",
834                     "text": "Cancel",
835                     "xtype": "Button",
836                     "|xns": "Roo"
837                 },
838                 {
839                     "listeners": {
840                         "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
841                     },
842                     "*prop": "buttons[]",
843                     "text": "Save",
844                     "xtype": "Button",
845                     "|xns": "Roo"
846                 }
847             ]
848         }, null,4)
849     );
850    
851    
852    
853 });
854
855