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