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' ],
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 : 75,
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               
139           ],
140           fields : [  'ftype', 'fname'],
141           xns : Roo.data,
142           xtype : 'SimpleStore'
143          },
144          '|xns' : 'Roo.form',
145          allowBlank : false,
146          displayField : 'fname',
147          editable : false,
148          hiddenName : 'status',
149          listWidth : 200,
150          mode : 'local',
151          name : 'status',
152          triggerAction : 'all',
153          valueField : 'ftype',
154          width : 150,
155          xns : Roo.form,
156          xtype : 'ComboBox',
157          items : [
158
159          ]
160
161         },
162         '|xns' : 'Roo.grid',
163         xns : Roo.grid,
164         xtype : 'GridEditor',
165         items : [
166
167         ]
168
169        },
170        '|xns' : 'Roo.grid',
171        dataIndex : 'ftype',
172        header : _this._strings['189efd19c4153526994a6d7ea5f6f068'],
173        renderer : function(v) { return String.format('{0}', v); },
174        width : 75,
175        xns : Roo.grid,
176        xtype : 'ColumnModel',
177        items : [
178
179        ]
180
181       },
182 {
183        editor : {
184         field : {
185          store : {
186           '|xns' : 'Roo.data',
187           data : [ 
188               [ 'ComboBox', "ComboBox"],
189               [ 'Text' , "TextField"],
190               [ 'Number', "NumberField"],
191               [ 'TextArea', "TextArea"],
192               [ 'Html', "HtmlEntry"]
193               
194           ],
195           fields : [  'ftype', 'fname'],
196           xns : Roo.data,
197           xtype : 'SimpleStore'
198          },
199          '|xns' : 'Roo.form',
200          allowBlank : false,
201          displayField : 'fname',
202          editable : false,
203          hiddenName : 'status',
204          listWidth : 200,
205          mode : 'local',
206          name : 'status',
207          triggerAction : 'all',
208          valueField : 'ftype',
209          width : 150,
210          xns : Roo.form,
211          xtype : 'ComboBox',
212          items : [
213
214          ]
215
216         },
217         '|xns' : 'Roo.grid',
218         xns : Roo.grid,
219         xtype : 'GridEditor',
220         items : [
221
222         ]
223
224        },
225        '|xns' : 'Roo.grid',
226        dataIndex : 'ftype',
227        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
228        renderer : function(v) { return String.format('{0}', v); },
229        width : 75,
230        xns : Roo.grid,
231        xtype : 'ColumnModel',
232        items : [
233
234        ]
235
236       },
237 {
238        editor : {
239         field : {
240          '|xns' : 'Roo.form',
241          decimalPrecision : 0,
242          xns : Roo.form,
243          xtype : 'NumberField'
244         },
245         '|xns' : 'Roo.grid',
246         xns : Roo.grid,
247         xtype : 'GridEditor',
248         items : [
249
250         ]
251
252        },
253        '|xns' : 'Roo.grid',
254        dataIndex : 'width',
255        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
256        renderer : function(v) { return String.format('{0}', v); },
257        width : 75,
258        xns : Roo.grid,
259        xtype : 'ColumnModel',
260        items : [
261
262        ]
263
264       }
265     ],
266     listeners : {
267      cellclick : function (_self, rowIndex, columnIndex, e)
268       {
269       
270               var di = this.colModel.getDataIndex(columnIndex);
271               if (di != 'active') {
272                   return;
273               }
274                
275               var rec = _this.grid.ds.getAt(rowIndex);
276               
277               rec.set('active', rec.data.active * 1 ? 0 : 1);
278               rec.commit();
279                
280               
281       },
282      render : function() 
283       {
284           _this.grid = this; 
285           //_this.dialog = Pman.Dialog.FILL_IN
286       
287       },
288      rowdblclick : function (_self, rowIndex, e)
289       {
290           if (!_this.dialog) return;
291         
292       }
293     },
294     items : [
295
296     ]
297
298    },
299    '|xns' : 'Roo',
300    background : false,
301    fitContainer : true,
302    fitToframe : true,
303    loadData : function(data) { 
304    
305         alert("IPC:TEST:" + JSON.stringify(data,null,4));
306        var ar = [];
307        for (var k in data) { 
308            var r = data[k];
309            var has_s = typeof(r.relates_to_schema) != 'undefined'
310            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100] );
311            if (!has_s) {
312                continue;
313            }
314            /*
315            for (var kk in r.relates_to_schema) {         
316                var rr = r.relates_to_schema[kk];
317                if (rr.Field == r.relates_to_col) {
318                    continue;
319                }
320                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
321            }
322            */
323        }
324        this.schema = data;
325        alert("IPC:TEST:" + JSON.stringify(ar));
326        this.grid.dataSource.loadData(ar);
327    },
328    region : 'center',
329    tableName : 'core_enum',
330    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
331    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
332    toBJS : function() { 
333    
334    // convert the selected cells into a BJS data ready to send back to the UI..
335       
336        this.table = "XXX";
337        this.firstTxtCol = "XXX";
338       
339        var formHeight = 50;
340        
341        var jreader = {};
342        var  formElements = [];
343        this.grid.dataSource.each(function(rec) {
344            if (!rec.data.active) {
345                return;
346            }
347            
348            var el = {
349                fieldLabel : rec.data.title,
350                name : rec.data.dataIndex,
351                width : 200, //row.type == 'string' ? 200 : 75,
352                '|xns' : 'Roo.form',
353                xtype : rec.data.ftype
354            }
355             if (xtype == 'DateField') {
356                el.format = 'Y-m-d';
357                el.useIso = true;
358                el.width = 100;
359            }
360            
361            if (xtype == 'TextArea') {
362                el.height = 100;
363            }
364            
365            if (xtype == 'Hidden') {
366                delete el.fieldLabel;
367                delete el.width;
368            }
369            if (xtype == 'Combobox') {
370            
371    
372                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
373                
374                el.hiddenName = old.name; // SET WHEN USED eg. project_id
375                el.displayField = combofields_name; // SET WHEN USED eg. project_id
376                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
377                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
378              
379            
380               el.items = [
381                    {
382                            
383                        '*prop' : 'store',
384                        'xtype' : 'Store',
385                        '|xns' : 'Roo.data',
386                        'remoteSort' : true,
387                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
388                        listeners : {
389                            '|beforeload' : 'function (_self, o)' +
390                            "{\n" +
391                            "    o.params = o.params || {};\n" +
392                            "    // set more here\n" +
393                            "}\n"
394                        },
395                        items : [
396                            {
397                                '*prop' : 'proxy',
398                                'xtype' : 'HttpProxy',
399                                'method' : 'GET',
400                                '|xns' : 'Roo.data',
401                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
402                            },
403                            
404                            {
405                                '*prop' : 'reader',
406                                'xtype' : 'JsonReader',
407                                '|xns' : 'Roo.data',
408                                'id' : 'id',
409                                'root' : 'data',
410                                'totalProperty' : 'total'
411    
412                                
413                            }
414                        ]
415                    }
416                ];
417            
418            }
419            
420            
421            formElements.push(el);
422            
423            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
424            
425            
426        });
427        
428        
429        
430        
431        
432        
433         var frmCfg = 
434        {
435            '|xns' : 'Roo.form',
436            xtype : "Form",
437            listeners : {
438                "|actioncomplete" : "function(_self,action)\n"+
439                    "{\n"+
440                    "    if (action.type == 'setdata') {\n"+
441                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
442                    "       return;\n"+
443                    "    }\n"+
444                    "    if (action.type == 'load') {\n"+
445                    "        return;\n"+
446                    "    }\n"+
447                    "    if (action.type =='submit') {\n"+
448                    "    \n"+
449                    "        _this.dialog.hide();\n"+
450                    "    \n"+
451                    "         if (_this.callback) {\n"+
452                    "            _this.callback.call(_this, action.result.data);\n"+
453                    "         }\n"+
454                    "         _this.form.reset();\n"+
455                    "         return;\n"+
456                    "    }\n"+
457                    "}\n",
458                
459                "|rendered" : "function (form)\n"+
460                    "{\n"+
461                    "    _this.form= form;\n"+
462                    "}\n"
463            },
464            method : "POST",
465            style : "margin:10px;",
466            "|url" : "baseURL + '/Roo/" + this.table + "'",
467            items : formElements
468        };
469        
470    
471        alert("IPC:OUT:" + JSON.stringify({
472                "closable": false,
473                "collapsible": false,
474                "height": formHeight,
475                "resizable": false,
476                "title": "Edit / Create " + this.table,
477                "width": 400,
478                "modal" : true,
479                "xtype": "LayoutDialog",
480                "|xns": "Roo",
481                "items": [
482                    {
483                        "|xns": "Roo",
484                        "xtype": "LayoutRegion",
485                        "*prop": "center"
486                    },
487                    {
488                        "region": "center",
489                        "xtype": "ContentPanel",
490                        "|xns": "Roo",
491                        "items": [
492                            frmCfg
493                        ]
494                    },
495                    
496                    {
497                        "listeners": {
498                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
499                        },
500                        "*prop": "buttons[]",
501                        "text": "Cancel",
502                        "xtype": "Button",
503                        "|xns": "Roo"
504                    },
505                    {
506                        "listeners": {
507                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
508                        },
509                        "*prop": "buttons[]",
510                        "text": "Save",
511                        "xtype": "Button",
512                        "|xns": "Roo"
513                    }
514                ]
515            
516            
517            
518        }, null, 4));
519    
520    },
521    xns : Roo,
522    xtype : 'GridPanel',
523    listeners : {
524     activate : function() {
525          _this.panel = this;
526          if (_this.grid) {
527              _this.grid.footer.onClick('first');
528          }
529      }
530    },
531    items : [
532
533    ]
534
535   };  }
536 });