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