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     
272     schema.forEach(function(e)  {
273         var type = e.Type.match(/([^(]+)\(([^\)]+)\)/);
274         var row  = { }; 
275         if (type) {
276             e.Type = type[1];
277             e.Size = type[2];
278         }
279         
280         
281         
282         row.name = e.Field;
283         
284         
285         if (typeof(map[e.Type]) == 'undefined') {
286            console.dump(e);
287            throw {
288                 name: "ArgumentError", 
289                 message: "Unknown mapping for type : " + e.Type
290             };
291         }
292         row.type = map[e.Type];
293         
294         if (row.type == 'string' && !firstTxtCol.length) {
295             firstTxtCol = row.name;
296         }
297         
298         if (row.type == 'date') {
299             row.dateFormat = 'Y-m-d';
300         }
301         reader.push(row);
302         
303         if (combofields.length == 1 && row.type == 'string') {
304             combofields.push(row);
305         }
306         
307         
308         var title = row.name.replace(/_id/, '').replace(/_/g, ' ');
309         title  = title[0].toUpperCase() + title.substring(1);
310         
311         colmodel.push({
312             "xtype": "ColumnModel",
313             "header": title,
314             "width":  row.type == 'string' ? 200 : 75,
315             "dataIndex": row.name,
316             "|renderer": row.type != 'date' ? 
317                     "function(v) { return String.format('{0}', v); }" :
318                     "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }" , // special for date
319             "|xns": "Roo.grid",
320             "*prop": "colModel[]"
321         });
322         var xtype = 'TextField';
323         if (row.type == 'number') {
324             xtype = 'NumberField';
325         }
326         if (row.type == 'date') {
327             xtype = 'DateField';
328         }
329         if (e.Type == 'text') {
330             xtype = 'TextArea';
331         }
332         if (row.name == 'id') {
333             xtype = 'Hidden';
334         } 
335         // what about booleans.. -> checkboxes..
336         
337         
338         
339         form[row.name] = {
340             fieldLabel : title,
341             name : row.name,
342             width : row.type == 'string' ? 200 : 75,
343             '|xns' : 'Roo.form',
344             xtype : xtype
345         }
346         if (xtype == 'TextArea') {
347             form[row.name].height = 100;
348         }
349         if (xtype == 'Hidden') {
350             delete form[row.name].fieldLabel;
351             delete form[row.name].width;
352         }
353         
354     });
355     
356     var combo = {
357         '|xns' : 'Roo.form',
358         xtype: 'ComboBox',
359         allowBlank : 'false',
360         editable : 'false',
361         emptyText : 'Select ' + table,
362         forceSelection : true,
363         listWidth : 400,
364         loadingText: 'Searching...',
365         minChars : 2,
366         pageSize : 20,
367         qtip: 'Select ' + table,
368         selectOnFocus: true,
369         triggerAction : 'all',
370         typeAhead: true,
371         
372         width: 300,
373         
374         
375         
376         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>', // SET WHEN USED
377         queryParam : '',// SET WHEN USED
378         fieldLabel : table,  // SET WHEN USED
379         valueField : 'id',
380         displayField : '', // SET WHEN USED eg. project_id_name
381         hiddenName : '', // SET WHEN USED eg. project_id
382         name : '', // SET WHEN USED eg. project_id_name
383         items : [
384             {
385                     
386                 '*prop' : 'store',
387                 'xtype' : 'Store',
388                 '|xns' : 'Roo.data',
389                 'remoteSort' : true,
390                 '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
391                 listeners : {
392                     '|beforeload' : 'function (_self, o)' +
393                     "{\n" +
394                     "    o.params = o.params || {};\n" +
395                     "    // set more here\n" +
396                     "}\n"
397                 },
398                 items : [
399                     {
400                         '*prop' : 'proxy',
401                         'xtype' : 'HttpProxy',
402                         'method' : 'GET',
403                         '|xns' : 'Roo.data',
404                         '|url' : "baseURL + '/Roo/" + table + ".php'",
405                     },
406                     
407                     {
408                         '*prop' : 'reader',
409                         'xtype' : 'JsonReader',
410                         '|xns' : 'Roo.data',
411                         'id' : 'id',
412                         'root' : 'data',
413                         'totalProperty' : 'total',
414                         '|fields' : JSON.stringify(combofields)
415                         
416                     }
417                 ]
418             }
419         ]
420     }
421     
422     
423     
424     
425     //print(JSON.stringify(reader,null,4));
426     readers.push({
427         table : table ,
428         combo : combo,
429         combofields : combofields,
430         reader :  reader,
431         oreader : JSON.parse(JSON.stringify(reader)), // dupe it..
432         colmodel : colmodel,
433         firstTxtCol : firstTxtCol,
434         form : form
435     });
436     
437     //console.dump(schema );
438     
439      
440 });
441
442
443
444 // merge in the linked tables..
445 readers.forEach(function(reader) {
446     if (typeof(ini[reader.table]) == 'undefined') {
447      
448         return;
449     }
450     print("OVERLAY - " + reader.table);
451     // we have a map..
452     for (var col in ini[reader.table]) {
453         var kv = ini[reader.table][col].split(':');
454         
455         
456         var add = readers.filter(function(r) { return r.table == kv[0] })[0];
457         if (!add) {
458             continue;
459         }
460         // merge in data (eg. project_id => project_id_*****
461      
462         add.oreader.forEach(function(or) {
463             reader.reader.push({
464                 name : col + '_' + or.name,
465                 type : or.type
466             });
467         });
468         
469         // col is mapped to something..
470         var combofields = add.combofields;
471         if (add.combofields.length < 2) {
472             continue;
473         }
474         if (typeof(reader.form[col]) == 'undefined') {
475             print (JSON.stringify(reader.form, null,4));
476             print("missing linked column " + col);
477             continue;
478         }
479         
480         var combofields_name = add.combofields[1].name;
481         var old =   reader.form[col];
482         reader.form[col] = JSON.parse(JSON.stringify(add.combo)); // clone
483         reader.form[col].queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
484         reader.form[col].fieldLabel = old.fieldLabel;  // SET WHEN USED
485         reader.form[col].hiddenName = old.name; // SET WHEN USED eg. project_id
486         reader.form[col].displayField = combofields_name; // SET WHEN USED eg. project_id
487         reader.form[col].name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
488         reader.form[col].tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
489         
490              
491     };
492     
493     
494 });
495
496 //readers.forEach(function(reader) {
497 //    delete reader.oreader;
498 //});
499
500  
501
502
503
504 //print(JSON.stringify(readers, null, 4));
505
506 readers.forEach(function(reader) {
507     
508
509     var dir = GLib.get_home_dir() + '/.Builder/Roo.data.JsonReader'; 
510     if (!File.isDirectory(dir)) {
511         print("mkdir " + dir);
512         File.mkdir(dir);
513     }
514     
515     // READERS
516     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
517     
518                 
519     var jreader = {
520         '|xns' : 'Roo.data',
521         xtype : "JsonReader",
522         totalProperty : "total",
523         root : "data",
524         '*prop' : "reader",
525         id : 'id', // maybe no..
526        
527         '|fields' :  JSON.stringify(reader.reader, null,4).replace(/"/g,"'")
528     };
529     
530     File.write(
531         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
532         JSON.stringify(jreader, null, 4)
533     )
534     
535     
536     // GRIDS
537     dir = GLib.get_home_dir() + '/.Builder/Roo.GridPanel'; 
538     if (!File.isDirectory(dir)) {
539         print("mkdir " + dir);
540         File.mkdir(dir);
541     }
542     
543
544     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
545     
546     File.write(
547         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
548             
549        
550         JSON.stringify({
551             '|xns' : 'Roo',
552             xtype : "GridPanel",
553             "title": reader.table,
554             "fitToframe": true,
555             "fitContainer": true,
556             "tableName": reader.table,
557             "background": true,
558             "region" : 'center',
559             "listeners": {
560                 "|activate": "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
561             },
562             "items": [
563                 {
564                     "*prop": "grid",
565                     "xtype": "Grid",
566                     "autoExpandColumn": reader.firstTxtCol,
567                     "loadMask": true,
568                     "listeners": {
569                         "|render": "function() \n" +
570                             "{\n" +
571                             "    _this.grid = this; \n" +
572                             "    //_this.dialog = Pman.Dialog.FILL_IN\n" +
573                             "    if (_this.panel.active) {\n" +
574                             "       this.footer.onClick('first');\n" +
575                             "    }\n" +
576                             "}",
577                         "|rowdblclick": "function (_self, rowIndex, e)\n" + 
578                             "{\n" + 
579                             "    if (!_this.dialog) return;\n" + 
580                             "    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + 
581                             "        _this.grid.footer.onClick('first');\n" + 
582                             "    }); \n" + 
583                             "}\n"
584                     },
585                     "|xns": "Roo.grid",
586
587                     "items": [
588                         {
589                             "*prop": "dataSource",
590                             "xtype": "Store",
591                              remoteSort : true,
592                             '|sortInfo' : "{ field : '" + reader.firstTxtCol  +  "', direction: 'ASC' }", 
593                             "|xns": "Roo.data",
594                             "items": [
595                                 
596                                 {
597                                     "*prop": "proxy",
598                                     "xtype": "HttpProxy",
599                                     "method": "GET",
600                                     "|url": "baseURL + '/Roo/" + reader.table + ".php'",
601                                     "|xns": "Roo.data"
602                                 },
603                                 jreader
604                             ]
605                         },
606                         {
607                             "*prop": "footer",
608                             "xtype": "PagingToolbar",
609                             "pageSize": 25,
610                             "displayInfo": true,
611                             "displayMsg": "Displaying " + reader.table + "{0} - {1} of {2}",
612                             "emptyMsg": "No " + reader.table + " found",
613                             "|xns": "Roo"
614                         },
615                         {
616                             "*prop": "toolbar",
617                             "xtype": "Toolbar",
618                             "|xns": "Roo",
619                             "items": [
620                                 {
621                                     "text": "Add",
622                                     "xtype": "Button",
623                                     "cls": "x-btn-text-icon",
624                                     "|icon": "Roo.rootURL + 'images/default/dd/drop-add.gif'",
625                                     "listeners": {
626                                         "|click": "function()\n"+
627                                             "{\n"+
628                                             "    if (!_this.dialog) return;\n" +
629                                             "    _this.dialog.show( { id : 0 } , function() {\n"+
630                                             "        _this.grid.footer.onClick('first');\n"+
631                                             "   }); \n"+
632                                             "}\n"
633                                     },
634                                     "|xns": "Roo.Toolbar"
635                                 },
636                                 {
637                                     "text": "Edit",
638                                     "xtype": "Button",
639                                     "cls": "x-btn-text-icon",
640                                     "|icon": "Roo.rootURL + 'images/default/tree/leaf.gif'",
641                                     "listeners": {
642                                         "|click": "function()\n"+
643                                             "{\n"+
644                                             "    var s = _this.grid.getSelectionModel().getSelections();\n"+
645                                             "    if (!s.length || (s.length > 1))  {\n"+
646                                             "        Roo.MessageBox.alert(\"Error\", s.length ? \"Select only one Row\" : \"Select a Row\");\n"+
647                                             "        return;\n"+
648                                             "    }\n"+
649                                             "    if (!_this.dialog) return;\n" +
650                                             "    _this.dialog.show(s[0].data, function() {\n"+
651                                             "        _this.grid.footer.onClick('first');\n"+
652                                             "    }); \n"+
653                                             "    \n"+
654                                             "}\n" 
655                                         
656                                     },
657                                     "|xns": "Roo.Toolbar"
658                                 },
659                                 {
660                                     "text": "Delete",
661                                     "cls": "x-btn-text-icon",
662                                     "|icon": "rootURL + '/Pman/templates/images/trash.gif'",
663                                     "xtype": "Button",
664                                     "listeners": {
665                                         "|click": "function()\n"+
666                                             "{\n"+
667                                             "     Pman.genericDelete(_this, '" + reader.table + "'); \n"+
668                                             "}\n"+
669                                             "        "
670                                     },
671                                     "|xns": "Roo.Toolbar"
672                                 }
673                             ]
674                         }, // end toolbar
675                     ].concat( reader.colmodel)
676                 }
677             ]
678             
679             
680         }, null, 4)
681     )
682     
683     /// FORMS..
684     
685     dir = GLib.get_home_dir() + '/.Builder/Roo.form.Form'; 
686     if (!File.isDirectory(dir)) {
687         print("mkdir " + dir);
688         File.mkdir(dir);
689     }
690     var formElements = [];
691     var formHeight = 50;
692     for (var k in reader.form) {
693         if (k == 'id') { // should really do primary key testing..
694             continue;
695         }
696         formHeight += reader.form[k].xtype == 'TextArea' ? 100 : 30;
697         
698         formElements.push(reader.form[k]);
699     }
700     if (reader.form['id']) {
701         formElements.push(reader.form['id']);
702     }
703     
704
705     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
706     var frmCfg = 
707     {
708         '|xns' : 'Roo.form',
709         xtype : "Form",
710         listeners : {
711             "|actioncomplete" : "function(_self,action)\n"+
712                 "{\n"+
713                 "    if (action.type == 'setdata') {\n"+
714                 "       //_this.dialog.el.mask(\"Loading\");\n"+
715                 "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
716                 "       return;\n"+
717                 "    }\n"+
718                 "    if (action.type == 'load') {\n"+
719                 "        _this.dialog.el.unmask();\n"+
720                 "        return;\n"+
721                 "    }\n"+
722                 "    if (action.type =='submit') {\n"+
723                 "    \n"+
724                 "        _this.dialog.el.unmask();\n"+
725                 "        _this.dialog.hide();\n"+
726                 "    \n"+
727                 "         if (_this.callback) {\n"+
728                 "            _this.callback.call(_this, _this.form.getValues());\n"+
729                 "         }\n"+
730                 "         _this.form.reset();\n"+
731                 "         return;\n"+
732                 "    }\n"+
733                 "}\n",
734             
735             "|rendered" : "function (form)\n"+
736                 "{\n"+
737                 "    _this.form= form;\n"+
738                 "}\n"
739         },
740         method : "POST",
741         style : "margin:10px;",
742         "|url" : "baseURL + '/Roo/" + reader.table + ".php'",
743         items : formElements
744     };
745     
746     
747     File.write(
748         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
749             
750        
751         JSON.stringify( frmCfg, null, 4)
752     );
753             
754             
755    
756    
757    
758      /// COMBO..
759     
760     dir = GLib.get_home_dir() + '/.Builder/Roo.form.ComboBox'; 
761     if (!File.isDirectory(dir)) {
762         print("mkdir " + dir);
763         File.mkdir(dir);
764     }
765    
766     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
767     
768     File.write(
769         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
770             
771        
772         JSON.stringify(reader.combo, null, 4)
773     );
774             
775    
776    
777    
778    
779    
780     // DIALOG.
781    
782    
783     dir = GLib.get_home_dir() + '/.Builder/Roo.LayoutDialog'; 
784     if (!File.isDirectory(dir)) {
785         print("mkdir " + dir);
786         File.mkdir(dir);
787     }
788     var formElements = [];
789     for (var k in reader.form) {
790         if (k == 'id') { // should really do primary key testing..
791             continue;
792         }
793         formElements.push(reader.form[k]);
794     }
795     formElements.push(reader.form['id']);
796
797     print("WRITE: " +  dir + '/' + cfg.DBNAME + '_' + reader.table + '.json');
798     
799     File.write(
800         dir + '/' + cfg.DBNAME + '_' + reader.table + '.json',
801             
802        
803         JSON.stringify({
804        
805             "closable": false,
806             "collapsible": false,
807             "height": formHeight,
808             "resizable": false,
809             "title": "Edit / Create " + reader.table,
810             "width": 400,
811             "xtype": "LayoutDialog",
812             "|xns": "Roo",
813             "items": [
814                 {
815                     "|xns": "Roo",
816                     "xtype": "LayoutRegion",
817                     "*prop": "center"
818                 },
819                 {
820                     "region": "center",
821                     "xtype": "ContentPanel",
822                     "|xns": "Roo",
823                     "items": [
824                         frmCfg
825                     ]
826                 },
827                 
828                 {
829                     "listeners": {
830                         "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
831                     },
832                     "*prop": "buttons[]",
833                     "text": "Cancel",
834                     "xtype": "Button",
835                     "|xns": "Roo"
836                 },
837                 {
838                     "listeners": {
839                         "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
840                     },
841                     "*prop": "buttons[]",
842                     "text": "Save",
843                     "xtype": "Button",
844                     "|xns": "Roo"
845                 }
846             ]
847         }, null,4)
848     );
849    
850    
851    
852 });
853
854