resources/Editors/Editor.Roo.grid.Grid.bjs
[app.Builder.js] / resources / Editors / Editor.Roo.grid.Grid.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Editor.Roo.grid');
6
7 Editor.Roo.grid.Grid = new Roo.XComponent({
8
9  _strings : {
10   '4ce58cbe362a5d7b156992a496d55bf3' :"Database Column",
11   'b78a3223503896721cca1303f776159b' :"Title",
12   '2f616612593df62aeed112de4f03110e' :"Edit a Grid",
13   '0ccc2bf3fb98387c23b6ca5500244d6e' :"Use ",
14   'c671c787b49f50a3ace9fdc5bd597825' :"core_enum",
15   '32954654ac8fe66a1d09be19001de2d4' :"Width",
16   'a1fa27779242b4902f7ae3bdd5c6d508' :"Type",
17   '6e7376dca68a2386a8737944196ab491' :"Create / Edit Grid"
18  },
19
20   part     :  ["Editors", "Grid" ],
21   order    : '001-Editor.Roo.grid.Grid',
22   region   : 'center',
23   parent   : false,
24   name     : "unnamed module",
25   disabled : false, 
26   permname : '', 
27   _tree : function()
28   {
29    var _this = this;
30    var MODULE = this;
31    return {
32    grid : {
33     ds : {
34      '|xns' : 'Roo.data',
35      data : [
36        [ 1, 'test', 'test', 110 ]
37        
38      
39      ],
40      fields : [ 'active', 'dataIndex', 'type','title', 'width' ],
41      id : 'dataindex',
42      xns : Roo.data,
43      xtype : 'SimpleStore'
44     },
45     toolbar : {
46      '|xns' : 'Roo',
47      xns : Roo,
48      xtype : 'Toolbar',
49      items : [
50       {
51        '|xns' : 'Roo.Toolbar',
52        text : _this._strings['2f616612593df62aeed112de4f03110e'],
53        xns : Roo.Toolbar,
54        xtype : 'TextItem'
55       }
56      ]
57
58     },
59     '|xns' : 'Roo.grid',
60     autoExpandColumn : 'title',
61     clicksToEdit : 1,
62     loadMask : true,
63     xns : Roo.grid,
64     xtype : 'EditorGrid',
65     cm : [
66       {
67        '|xns' : 'Roo.grid',
68        dataIndex : 'active',
69        header : _this._strings['0ccc2bf3fb98387c23b6ca5500244d6e'],
70        renderer : function(v) {  
71            var state = v *1 > 0 ?  '-checked' : '';
72        
73            return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
74                        
75         },
76        width : 75,
77        xns : Roo.grid,
78        xtype : 'ColumnModel'
79       },
80 {
81        '|xns' : 'Roo.grid',
82        dataIndex : 'dataIndex',
83        header : _this._strings['4ce58cbe362a5d7b156992a496d55bf3'],
84        renderer : function(v) { return String.format('{0}', v); },
85        width : 150,
86        xns : Roo.grid,
87        xtype : 'ColumnModel'
88       },
89 {
90        '|xns' : 'Roo.grid',
91        dataIndex : 'type',
92        header : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'],
93        renderer : function(v) { return String.format('{0}', v); },
94        width : 100,
95        xns : Roo.grid,
96        xtype : 'ColumnModel'
97       },
98 {
99        editor : {
100         field : {
101          '|xns' : 'Roo.form',
102          xns : Roo.form,
103          xtype : 'TextField'
104         },
105         '|xns' : 'Roo.grid',
106         xns : Roo.grid,
107         xtype : 'GridEditor',
108         items : [
109
110         ]
111
112        },
113        '|xns' : 'Roo.grid',
114        dataIndex : 'title',
115        header : _this._strings['b78a3223503896721cca1303f776159b'],
116        renderer : function(v) { return String.format('{0}', v); },
117        width : 75,
118        xns : Roo.grid,
119        xtype : 'ColumnModel',
120        items : [
121
122        ]
123
124       },
125 {
126        editor : {
127         field : {
128          '|xns' : 'Roo.form',
129          decimalPrecision : 0,
130          xns : Roo.form,
131          xtype : 'NumberField'
132         },
133         '|xns' : 'Roo.grid',
134         xns : Roo.grid,
135         xtype : 'GridEditor',
136         items : [
137
138         ]
139
140        },
141        '|xns' : 'Roo.grid',
142        dataIndex : 'width',
143        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
144        renderer : function(v) { return String.format('{0}', v); },
145        width : 75,
146        xns : Roo.grid,
147        xtype : 'ColumnModel',
148        items : [
149
150        ]
151
152       }
153     ],
154     listeners : {
155      cellclick : function (_self, rowIndex, columnIndex, e)
156       {
157       
158               var di = this.colModel.getDataIndex(columnIndex);
159               if (di != 'active') {
160                   return;
161               }
162                
163               var rec = _this.grid.ds.getAt(rowIndex);
164               
165               rec.set('active', rec.data.active * 1 ? 0 : 1);
166               rec.commit();
167                
168               
169       },
170      render : function() 
171       {
172           _this.grid = this; 
173           //_this.dialog = Pman.Dialog.FILL_IN
174       
175       },
176      rowdblclick : function (_self, rowIndex, e)
177       {
178           if (!_this.dialog) return;
179         
180       }
181     },
182     items : [
183
184     ]
185
186    },
187    '|xns' : 'Roo',
188    background : false,
189    fitContainer : true,
190    fitToframe : true,
191    loadData : function(data) { 
192    
193         alert("IPC:TEST:" + JSON.stringify(data,null,4));
194        var ar = [];
195        for (var k in data) { 
196            var r = data[k];
197            var has_s = typeof(r.relates_to_schema) != 'undefined'
198            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100] );
199            if (!has_s) {
200                continue;
201            }
202            for (var kk in r.relates_to_schema) {         
203                var rr = r.relates_to_schema[kk];
204                if (rr.Field == r.relates_to_col) {
205                    continue;
206                }
207                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
208            }
209        }
210        
211        alert("IPC:TEST:" + JSON.stringify(ar));
212        this.grid.dataSource.loadData(ar);
213    },
214    region : 'center',
215    tableName : 'core_enum',
216    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
217    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
218    toBJS : function() { 
219    
220    // convert the selected cells into a BJS data ready to send back to the UI..
221       
222        this.table = "XXX";
223        this.firstTxtCol = "XXX";
224       
225       
226        var map = {
227            'date' : 'date',
228            'datetime' : 'date',
229            'timestamp with time zone' : 'date',
230            'timestamp without time zone' : 'date',
231            'time' : 'string', //bogus
232            'int' : 'int',
233            'integer' : 'int',
234            'bigint' : 'int',
235            'double' : 'float',
236            'tinyint' : 'int',
237            'smallint' : 'int',
238            'decimal' : 'float',
239            'float' : 'float',
240            'numeric' : 'float',
241            'char' : 'string',
242            'character' : 'string',
243            'character varying' : 'string',
244            'varchar' : 'string',
245            'text' : 'string',
246            'longtext' : 'string',
247            'tinytext' : 'string',
248            'mediumtext' : 'string',
249            'enum' : 'string',
250            'timestamp' : 'number',
251            'blob' : 'text',
252            'bytea' : 'text',
253            'boolean' : 'int',
254            'text[]' : 'string',
255            
256        }
257        var jreader = {};
258        var     colmodel = [];
259        this.grid.dataStore.each(function(rec) {
260            if (!rec.data.active) {
261                return;
262            }
263            
264            
265            
266            colmodel.push({
267                "xtype": "ColumnModel",
268                "header": rec.data.title,
269                "width":  row.data.width * 1,
270                "dataIndex": row.Field,
271                "|renderer": !row.Type.match(/date/i) ? 
272                        "function(v) { return String.format('{0}', v); }" :
273                        "function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }" , // special for date
274                "|xns": "Roo.grid",
275                "*prop": "colModel[]"
276            });
277        });
278        
279        
280        
281    
282        alert("IPC:OUT:" + JSON.stringify({
283            '|xns' : 'Roo',
284            xtype : "GridPanel",
285            "title": this.table,
286            "fitToframe": true,
287            "fitContainer": true,
288            "tableName": this.table,
289            "background": true,
290            "region" : 'center',
291            "listeners": {
292                "|activate": "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
293            },
294            "items": [
295                {
296                    "*prop": "grid",
297                    "xtype": "Grid",
298                    "autoExpandColumn": this.firstTxtCol,
299                    "loadMask": true,
300                    "listeners": {
301                        "|render": "function() \n" +
302                            "{\n" +
303                            "    _this.grid = this; \n" +
304                            "    //_this.dialog = Pman.Dialog.FILL_IN\n" +
305                            "    if (_this.panel.active) {\n" +
306                            "       this.footer.onClick('first');\n" +
307                            "    }\n" +
308                            "}",
309                        "|rowdblclick": "function (_self, rowIndex, e)\n" + 
310                            "{\n" + 
311                            "    if (!_this.dialog) return;\n" + 
312                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n" + 
313                            "        _this.grid.footer.onClick('first');\n" + 
314                            "    }); \n" + 
315                            "}\n"
316                    },
317                    "|xns": "Roo.grid",
318    
319                    "items": [
320                        {
321                            "*prop": "dataSource",
322                            "xtype": "Store",
323                             remoteSort : true,
324                            '|sortInfo' : "{ field : '" + this.firstTxtCol  +  "', direction: 'ASC' }", 
325                            "|xns": "Roo.data",
326                            "items": [
327                                
328                                {
329                                    "*prop": "proxy",
330                                    "xtype": "HttpProxy",
331                                    "method": "GET",
332                                    "|url": "baseURL + '/Roo/" + this.table + ".php'",
333                                    "|xns": "Roo.data"
334                                },
335                                {
336                                    '*prop' : 'reader',
337                                    'xtype' : 'JsonReader',
338                                    '|xns' : 'Roo.data',
339                                    'id' : 'id',
340                                    'root' : 'data',
341                                    'totalProperty' : 'total'
342                                }
343                            ]
344                        },
345                        {
346                            "*prop": "footer",
347                            "xtype": "PagingToolbar",
348                            "pageSize": 25,
349                            "displayInfo": true,
350                            "displayMsg": "Displaying " + this.table + "{0} - {1} of {2}",
351                            "emptyMsg": "No " + this.table + " found",
352                            "|xns": "Roo"
353                        },
354                        {
355                            "*prop": "toolbar",
356                            "xtype": "Toolbar",
357                            "|xns": "Roo",
358                            "items": [
359                                {
360                                    "text": "Add",
361                                    "xtype": "Button",
362                                    "cls": "x-btn-text-icon",
363                                    "|icon": "Roo.rootURL + 'images/default/dd/drop-add.gif'",
364                                    "listeners": {
365                                        "|click": "function()\n"+
366                                            "{\n"+
367                                            "    if (!_this.dialog) return;\n" +
368                                            "    _this.dialog.show( { id : 0 } , function() {\n"+
369                                            "        _this.grid.footer.onClick('first');\n"+
370                                            "   }); \n"+
371                                            "}\n"
372                                    },
373                                    "|xns": "Roo.Toolbar"
374                                },
375                                 // fill ????
376                                {
377                                    "text": "Delete",
378                                    "cls": "x-btn-text-icon",
379                                    "|icon": "rootURL + '/Pman/templates/images/trash.gif'",
380                                    "xtype": "Button",
381                                    "listeners": {
382                                        "|click": "function()\n"+
383                                            "{\n"+
384                                            "     Pman.genericDelete(_this, '" + this.table + "'); \n"+
385                                            "}\n"+
386                                            "        "
387                                    },
388                                    "|xns": "Roo.Toolbar"
389                                }
390                            ]
391                        }, // end toolbar
392                    ].concat( colmodel)
393                }
394            ]
395            
396            
397        }, null, 4));
398    
399    },
400    xns : Roo,
401    xtype : 'GridPanel',
402    listeners : {
403     activate : function() {
404          _this.panel = this;
405          if (_this.grid) {
406              _this.grid.footer.onClick('first');
407          }
408      }
409    },
410    items : [
411
412    ]
413
414   };  }
415 });