resources/Editors/Editor.Roo.LayoutDialog.bjs
[app.Builder.js] / resources / Editors / Editor.Roo.LayoutDialog.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');
6
7 Editor.Roo.LayoutDialog = new Roo.XComponent({
8
9  _strings : {
10   'b021df6aac4654c454f46c77646e745f' :"Label",
11   '793548e77e782c209a78ed67f255b5e2' :"Display Field",
12   '4ce58cbe362a5d7b156992a496d55bf3' :"Database Column",
13   '189efd19c4153526994a6d7ea5f6f068' :"Field Type",
14   '2f616612593df62aeed112de4f03110e' :"Edit a Grid",
15   '0ccc2bf3fb98387c23b6ca5500244d6e' :"Use ",
16   'c671c787b49f50a3ace9fdc5bd597825' :"core_enum",
17   '32954654ac8fe66a1d09be19001de2d4' :"Width",
18   'a1fa27779242b4902f7ae3bdd5c6d508' :"Type",
19   '6e7376dca68a2386a8737944196ab491' :"Create / Edit Grid"
20  },
21
22   part     :  ["Editors", "LayoutDialog" ],
23   order    : '001-Editor.Roo.LayoutDialog',
24   region   : 'center',
25   parent   : false,
26   name     : "unnamed module",
27   disabled : false, 
28   permname : '', 
29   _tree : function()
30   {
31    var _this = this;
32    var MODULE = this;
33    return {
34    grid : {
35     ds : {
36      '|xns' : 'Roo.data',
37      data : [
38        [ 1, 'test', 'test', 110 ]
39        
40      
41      ],
42      fields : [ 'active', 'dataIndex', 'type','title', 'width', 'ftype', 'display_field' ],
43      id : 'dataindex',
44      xns : Roo.data,
45      xtype : 'SimpleStore'
46     },
47     toolbar : {
48      '|xns' : 'Roo',
49      xns : Roo,
50      xtype : 'Toolbar',
51      items : [
52       {
53        '|xns' : 'Roo.Toolbar',
54        text : _this._strings['2f616612593df62aeed112de4f03110e'],
55        xns : Roo.Toolbar,
56        xtype : 'TextItem'
57       }
58      ]
59
60     },
61     '|xns' : 'Roo.grid',
62     autoExpandColumn : 'title',
63     clicksToEdit : 1,
64     loadMask : true,
65     xns : Roo.grid,
66     xtype : 'EditorGrid',
67     cm : [
68       {
69        '|xns' : 'Roo.grid',
70        dataIndex : 'active',
71        header : _this._strings['0ccc2bf3fb98387c23b6ca5500244d6e'],
72        renderer : function(v) {  
73            var state = v *1 > 0 ?  '-checked' : '';
74        
75            return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
76                        
77         },
78        width : 75,
79        xns : Roo.grid,
80        xtype : 'ColumnModel'
81       },
82 {
83        '|xns' : 'Roo.grid',
84        dataIndex : 'dataIndex',
85        header : _this._strings['4ce58cbe362a5d7b156992a496d55bf3'],
86        renderer : function(v) { return String.format('{0}', v); },
87        width : 150,
88        xns : Roo.grid,
89        xtype : 'ColumnModel'
90       },
91 {
92        '|xns' : 'Roo.grid',
93        dataIndex : 'type',
94        header : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'],
95        renderer : function(v) { return String.format('{0}', v); },
96        width : 100,
97        xns : Roo.grid,
98        xtype : 'ColumnModel'
99       },
100 {
101        editor : {
102         field : {
103          '|xns' : 'Roo.form',
104          xns : Roo.form,
105          xtype : 'TextField'
106         },
107         '|xns' : 'Roo.grid',
108         xns : Roo.grid,
109         xtype : 'GridEditor',
110         items : [
111
112         ]
113
114        },
115        '|xns' : 'Roo.grid',
116        dataIndex : 'title',
117        header : _this._strings['b021df6aac4654c454f46c77646e745f'],
118        renderer : function(v) { return String.format('{0}', v); },
119        width : 120,
120        xns : Roo.grid,
121        xtype : 'ColumnModel',
122        items : [
123
124        ]
125
126       },
127 {
128        editor : {
129         field : {
130          store : {
131           '|xns' : 'Roo.data',
132           data : [ 
133               [ 'ComboBox', "ComboBox"],
134               [ 'TextField' , "TextField"],
135               [ 'NumberField', "NumberField"],
136               [ 'TextArea', "TextArea"],
137               [ 'HtmlEditor', "HtmlEditor"],
138               [ 'Hidden', "Hidden"],
139               [ 'DateField', "DateField"]    ,
140                [ 'Checkbox', "Checkbox"]    
141               // checkbox?
142           ],
143           fields : [  'ftype', 'fname'],
144           xns : Roo.data,
145           xtype : 'SimpleStore'
146          },
147          '|xns' : 'Roo.form',
148          allowBlank : false,
149          displayField : 'fname',
150          editable : false,
151          hiddenName : 'status',
152          listWidth : 200,
153          mode : 'local',
154          name : 'status',
155          triggerAction : 'all',
156          valueField : 'ftype',
157          width : 150,
158          xns : Roo.form,
159          xtype : 'ComboBox',
160          items : [
161
162          ]
163
164         },
165         '|xns' : 'Roo.grid',
166         xns : Roo.grid,
167         xtype : 'GridEditor',
168         items : [
169
170         ]
171
172        },
173        '|xns' : 'Roo.grid',
174        dataIndex : 'ftype',
175        header : _this._strings['189efd19c4153526994a6d7ea5f6f068'],
176        renderer : function(v) { return String.format('{0}', v); },
177        width : 120,
178        xns : Roo.grid,
179        xtype : 'ColumnModel',
180        items : [
181
182        ]
183
184       },
185 {
186        editor : {
187         field : {
188          store : {
189           '|xns' : 'Roo.data',
190           data : [ 
191               [ 'ComboBox', "ComboBox"],
192               [ 'Text' , "TextField"],
193               [ 'Number', "NumberField"],
194               [ 'TextArea', "TextArea"],
195               [ 'Html', "HtmlEntry"]
196               
197           ],
198           fields : [  'ftype', 'fname'],
199           xns : Roo.data,
200           xtype : 'SimpleStore'
201          },
202          '|xns' : 'Roo.form',
203          allowBlank : false,
204          displayField : 'fname',
205          editable : false,
206          hiddenName : 'status',
207          listWidth : 200,
208          mode : 'local',
209          name : 'status',
210          triggerAction : 'all',
211          valueField : 'ftype',
212          width : 150,
213          xns : Roo.form,
214          xtype : 'ComboBox',
215          items : [
216
217          ]
218
219         },
220         '|xns' : 'Roo.grid',
221         xns : Roo.grid,
222         xtype : 'GridEditor',
223         items : [
224
225         ]
226
227        },
228        '|xns' : 'Roo.grid',
229        dataIndex : 'display_field',
230        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
231        renderer : function(v) { return String.format('{0}', v); },
232        width : 150,
233        xns : Roo.grid,
234        xtype : 'ColumnModel',
235        items : [
236
237        ]
238
239       },
240 {
241        editor : {
242         field : {
243          '|xns' : 'Roo.form',
244          decimalPrecision : 0,
245          xns : Roo.form,
246          xtype : 'NumberField'
247         },
248         '|xns' : 'Roo.grid',
249         xns : Roo.grid,
250         xtype : 'GridEditor',
251         items : [
252
253         ]
254
255        },
256        '|xns' : 'Roo.grid',
257        dataIndex : 'width',
258        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
259        renderer : function(v) { return String.format('{0}', v); },
260        width : 75,
261        xns : Roo.grid,
262        xtype : 'ColumnModel',
263        items : [
264
265        ]
266
267       }
268     ],
269     listeners : {
270      cellclick : function (_self, rowIndex, columnIndex, e)
271       {
272       
273               var di = this.colModel.getDataIndex(columnIndex);
274               if (di != 'active') {
275                   return;
276               }
277                
278               var rec = _this.grid.ds.getAt(rowIndex);
279               
280               rec.set('active', rec.data.active * 1 ? 0 : 1);
281               rec.commit();
282                
283               
284       },
285      render : function() 
286       {
287           _this.grid = this; 
288           //_this.dialog = Pman.Dialog.FILL_IN
289       
290       },
291      rowdblclick : function (_self, rowIndex, e)
292       {
293           if (!_this.dialog) return;
294         
295       }
296     },
297     items : [
298
299     ]
300
301    },
302    '|xns' : 'Roo',
303    background : false,
304    fitContainer : true,
305    fitToframe : true,
306    loadData : function(data) { 
307    
308        //alert("IPC:TEST:" + JSON.stringify(data,null,4));
309        alert("IPC:TEST: OUTPUT DATA : " + data);
310        var ar = [];
311        for (var k in data) { 
312            var r = data[k];
313            var has_s = typeof(r.relates_to_schema) != 'undefined'
314            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100 , 'TextField', r.Field + '_display_name'] );
315            if (!has_s) {
316                continue;
317            }
318            /*
319            for (var kk in r.relates_to_schema) {         
320                var rr = r.relates_to_schema[kk];
321                if (rr.Field == r.relates_to_col) {
322                    continue;
323                }
324                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
325            }
326            */
327        }
328        this.schema = data;
329        //alert("IPC:TEST:" + JSON.stringify(ar));
330        this.grid.dataSource.loadData(ar);
331    },
332    region : 'center',
333    tableName : 'core_enum',
334    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
335    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
336    toBJS : function() { 
337    
338    // convert the selected cells into a BJS data ready to send back to the UI..
339       
340        this.table = "XXX";
341        this.firstTxtCol = "XXX";
342       
343        var formHeight = 50;
344        
345        var jreader = {};
346        var  formElements = [];
347        this.grid.dataSource.each(function(rec) {
348            if (!rec.data.active) {
349                return;
350            }
351            
352            var el = {
353                fieldLabel : rec.data.title,
354                name : rec.data.dataIndex,
355                width : 200, //row.type == 'string' ? 200 : 75,
356                '|xns' : 'Roo.form',
357                xtype : rec.data.ftype
358            }
359             if (xtype == 'DateField') {
360                el.format = 'Y-m-d';
361                el.useIso = true;
362                el.width = 100;
363            }
364            
365            if (xtype == 'TextArea') {
366                el.height = 100;
367            }
368            
369            if (xtype == 'Hidden') {
370                delete el.fieldLabel;
371                delete el.width;
372            }
373            if (xtype == 'Combobox') {
374            
375    
376                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
377                
378                el.hiddenName = old.name; // SET WHEN USED eg. project_id
379                el.displayField = combofields_name; // SET WHEN USED eg. project_id
380                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
381                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
382              
383            
384               el.items = [
385                    {
386                            
387                        '*prop' : 'store',
388                        'xtype' : 'Store',
389                        '|xns' : 'Roo.data',
390                        'remoteSort' : true,
391                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
392                        listeners : {
393                            '|beforeload' : 'function (_self, o)' +
394                            "{\n" +
395                            "    o.params = o.params || {};\n" +
396                            "    // set more here\n" +
397                            "}\n"
398                        },
399                        items : [
400                            {
401                                '*prop' : 'proxy',
402                                'xtype' : 'HttpProxy',
403                                'method' : 'GET',
404                                '|xns' : 'Roo.data',
405                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
406                            },
407                            
408                            {
409                                '*prop' : 'reader',
410                                'xtype' : 'JsonReader',
411                                '|xns' : 'Roo.data',
412                                'id' : 'id',
413                                'root' : 'data',
414                                'totalProperty' : 'total'
415    
416                                
417                            }
418                        ]
419                    }
420                ];
421            
422            }
423            
424            
425            formElements.push(el);
426            
427            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
428            
429            
430        });
431        
432        
433        
434        
435        
436        
437         var frmCfg = 
438        {
439            '|xns' : 'Roo.form',
440            xtype : "Form",
441            listeners : {
442                "|actioncomplete" : "function(_self,action)\n"+
443                    "{\n"+
444                    "    if (action.type == 'setdata') {\n"+
445                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
446                    "       return;\n"+
447                    "    }\n"+
448                    "    if (action.type == 'load') {\n"+
449                    "        return;\n"+
450                    "    }\n"+
451                    "    if (action.type =='submit') {\n"+
452                    "    \n"+
453                    "        _this.dialog.hide();\n"+
454                    "    \n"+
455                    "         if (_this.callback) {\n"+
456                    "            _this.callback.call(_this, action.result.data);\n"+
457                    "         }\n"+
458                    "         _this.form.reset();\n"+
459                    "         return;\n"+
460                    "    }\n"+
461                    "}\n",
462                
463                "|rendered" : "function (form)\n"+
464                    "{\n"+
465                    "    _this.form= form;\n"+
466                    "}\n"
467            },
468            method : "POST",
469            style : "margin:10px;",
470            "|url" : "baseURL + '/Roo/" + this.table + "'",
471            items : formElements
472        };
473        
474    
475        alert("IPC:OUT:" + JSON.stringify({
476                "closable": false,
477                "collapsible": false,
478                "height": formHeight,
479                "resizable": false,
480                "title": "Edit / Create " + this.table,
481                "width": 400,
482                "modal" : true,
483                "xtype": "LayoutDialog",
484                "|xns": "Roo",
485                "items": [
486                    {
487                        "|xns": "Roo",
488                        "xtype": "LayoutRegion",
489                        "*prop": "center"
490                    },
491                    {
492                        "region": "center",
493                        "xtype": "ContentPanel",
494                        "|xns": "Roo",
495                        "items": [
496                            frmCfg
497                        ]
498                    },
499                    
500                    {
501                        "listeners": {
502                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
503                        },
504                        "*prop": "buttons[]",
505                        "text": "Cancel",
506                        "xtype": "Button",
507                        "|xns": "Roo"
508                    },
509                    {
510                        "listeners": {
511                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
512                        },
513                        "*prop": "buttons[]",
514                        "text": "Save",
515                        "xtype": "Button",
516                        "|xns": "Roo"
517                    }
518                ]
519            
520            
521            
522        }, null, 4));
523    
524    },
525    xns : Roo,
526    xtype : 'GridPanel',
527    listeners : {
528     activate : function() {
529          _this.panel = this;
530          if (_this.grid) {
531              _this.grid.footer.onClick('first');
532          }
533      }
534    },
535    items : [
536
537    ]
538
539   };  }
540 });