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        return;
311        var ar = [];
312        for (var k in data) { 
313            var r = data[k];
314            var has_s = typeof(r.relates_to_schema) != 'undefined'
315            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100 , 'TextField', r.Field + '_display_name'] );
316            if (!has_s) {
317                continue;
318            }
319            /*
320            for (var kk in r.relates_to_schema) {         
321                var rr = r.relates_to_schema[kk];
322                if (rr.Field == r.relates_to_col) {
323                    continue;
324                }
325                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
326            }
327            */
328        }
329        this.schema = data;
330        //alert("IPC:TEST:" + JSON.stringify(ar));
331        this.grid.dataSource.loadData(ar);
332    },
333    region : 'center',
334    tableName : 'core_enum',
335    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
336    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
337    toBJS : function() { 
338    
339    // convert the selected cells into a BJS data ready to send back to the UI..
340       
341        this.table = "XXX";
342        this.firstTxtCol = "XXX";
343       
344        var formHeight = 50;
345        
346        var jreader = {};
347        var  formElements = [];
348        this.grid.dataSource.each(function(rec) {
349            if (!rec.data.active) {
350                return;
351            }
352            
353            var el = {
354                fieldLabel : rec.data.title,
355                name : rec.data.dataIndex,
356                width : 200, //row.type == 'string' ? 200 : 75,
357                '|xns' : 'Roo.form',
358                xtype : rec.data.ftype
359            }
360             if (xtype == 'DateField') {
361                el.format = 'Y-m-d';
362                el.useIso = true;
363                el.width = 100;
364            }
365            
366            if (xtype == 'TextArea') {
367                el.height = 100;
368            }
369            
370            if (xtype == 'Hidden') {
371                delete el.fieldLabel;
372                delete el.width;
373            }
374            if (xtype == 'Combobox') {
375            
376    
377                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
378                
379                el.hiddenName = old.name; // SET WHEN USED eg. project_id
380                el.displayField = combofields_name; // SET WHEN USED eg. project_id
381                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
382                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
383              
384            
385               el.items = [
386                    {
387                            
388                        '*prop' : 'store',
389                        'xtype' : 'Store',
390                        '|xns' : 'Roo.data',
391                        'remoteSort' : true,
392                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
393                        listeners : {
394                            '|beforeload' : 'function (_self, o)' +
395                            "{\n" +
396                            "    o.params = o.params || {};\n" +
397                            "    // set more here\n" +
398                            "}\n"
399                        },
400                        items : [
401                            {
402                                '*prop' : 'proxy',
403                                'xtype' : 'HttpProxy',
404                                'method' : 'GET',
405                                '|xns' : 'Roo.data',
406                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
407                            },
408                            
409                            {
410                                '*prop' : 'reader',
411                                'xtype' : 'JsonReader',
412                                '|xns' : 'Roo.data',
413                                'id' : 'id',
414                                'root' : 'data',
415                                'totalProperty' : 'total'
416    
417                                
418                            }
419                        ]
420                    }
421                ];
422            
423            }
424            
425            
426            formElements.push(el);
427            
428            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
429            
430            
431        });
432        
433        
434        
435        
436        
437        
438         var frmCfg = 
439        {
440            '|xns' : 'Roo.form',
441            xtype : "Form",
442            listeners : {
443                "|actioncomplete" : "function(_self,action)\n"+
444                    "{\n"+
445                    "    if (action.type == 'setdata') {\n"+
446                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
447                    "       return;\n"+
448                    "    }\n"+
449                    "    if (action.type == 'load') {\n"+
450                    "        return;\n"+
451                    "    }\n"+
452                    "    if (action.type =='submit') {\n"+
453                    "    \n"+
454                    "        _this.dialog.hide();\n"+
455                    "    \n"+
456                    "         if (_this.callback) {\n"+
457                    "            _this.callback.call(_this, action.result.data);\n"+
458                    "         }\n"+
459                    "         _this.form.reset();\n"+
460                    "         return;\n"+
461                    "    }\n"+
462                    "}\n",
463                
464                "|rendered" : "function (form)\n"+
465                    "{\n"+
466                    "    _this.form= form;\n"+
467                    "}\n"
468            },
469            method : "POST",
470            style : "margin:10px;",
471            "|url" : "baseURL + '/Roo/" + this.table + "'",
472            items : formElements
473        };
474        
475    
476        alert("IPC:OUT:" + JSON.stringify({
477                "closable": false,
478                "collapsible": false,
479                "height": formHeight,
480                "resizable": false,
481                "title": "Edit / Create " + this.table,
482                "width": 400,
483                "modal" : true,
484                "xtype": "LayoutDialog",
485                "|xns": "Roo",
486                "items": [
487                    {
488                        "|xns": "Roo",
489                        "xtype": "LayoutRegion",
490                        "*prop": "center"
491                    },
492                    {
493                        "region": "center",
494                        "xtype": "ContentPanel",
495                        "|xns": "Roo",
496                        "items": [
497                            frmCfg
498                        ]
499                    },
500                    
501                    {
502                        "listeners": {
503                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
504                        },
505                        "*prop": "buttons[]",
506                        "text": "Cancel",
507                        "xtype": "Button",
508                        "|xns": "Roo"
509                    },
510                    {
511                        "listeners": {
512                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
513                        },
514                        "*prop": "buttons[]",
515                        "text": "Save",
516                        "xtype": "Button",
517                        "|xns": "Roo"
518                    }
519                ]
520            
521            
522            
523        }, null, 4));
524    
525    },
526    xns : Roo,
527    xtype : 'GridPanel',
528    listeners : {
529     activate : function() {
530          _this.panel = this;
531          if (_this.grid) {
532              _this.grid.footer.onClick('first');
533          }
534      }
535    },
536    items : [
537
538    ]
539
540   };  }
541 });