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