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   'dc30ec20708ef7b0f641ef78b7880a15' :"DEBUG",
18   '32954654ac8fe66a1d09be19001de2d4' :"Width",
19   'a1fa27779242b4902f7ae3bdd5c6d508' :"Type",
20   '6e7376dca68a2386a8737944196ab491' :"Create / Edit Grid"
21  },
22
23   part     :  ["Editors", "LayoutDialog" ],
24   order    : '001-Editor.Roo.LayoutDialog',
25   region   : 'center',
26   parent   : false,
27   name     : "unnamed module",
28   disabled : false, 
29   permname : '', 
30   _tree : function()
31   {
32    var _this = this;
33    var MODULE = this;
34    return {
35    grid : {
36     ds : {
37      '|xns' : 'Roo.data',
38      data : [
39        [ 1, 'test', 'test', 110 ]
40        
41      
42      ],
43      fields : [ 'active', 'dataIndex', 'type','title', 'width', 'ftype', 'display_field' ],
44      id : 'dataindex',
45      xns : Roo.data,
46      xtype : 'SimpleStore'
47     },
48     toolbar : {
49      '|xns' : 'Roo',
50      xns : Roo,
51      xtype : 'Toolbar',
52      items : [
53       {
54        '|xns' : 'Roo.Toolbar',
55        text : _this._strings['2f616612593df62aeed112de4f03110e'],
56        xns : Roo.Toolbar,
57        xtype : 'TextItem'
58       },
59       {
60        '|xns' : 'Roo.Toolbar',
61        xns : Roo.Toolbar,
62        xtype : 'Fill'
63       },
64       {
65        '|xns' : 'Roo.Toolbar',
66        text : _this._strings['dc30ec20708ef7b0f641ef78b7880a15'],
67        xns : Roo.Toolbar,
68        xtype : 'Button',
69        listeners : {
70         click : function (_self, e)
71          {
72              Roo.log("Test");
73          
74              var data = {    
75                  "manage_scale_id": {
76                      "Field": "manage_scale_id",
77                      "Type": "int(11)",
78                      "Null": "NO",
79                      "Key": null,
80                      "Default": "0",
81                      "Extra": null,
82                      "relates_to_table": "core_enum",
83                      "relates_to_col": "id",
84                      "relates_to_schema": {
85                          "id": {
86                              "Field": "id",
87                              "Type": "int(11)",
88                              "Null": "NO",
89                              "Key": "PRI",
90                              "Default": null,
91                              "Extra": "auto_increment"
92                          },
93                          "etype": {
94                              "Field": "etype",
95                              "Type": "varchar(32)",
96                              "Null": "NO",
97                              "Key": null,
98                              "Default": null,
99                              "Extra": null
100                          },
101                          "name": {
102                              "Field": "name",
103                              "Type": "varchar(255)",
104                              "Null": "NO",
105                              "Key": null,
106                              "Default": null,
107                              "Extra": null
108                          },
109                          "active": {
110                              "Field": "active",
111                              "Type": "int(2)",
112                              "Null": "NO",
113                              "Key": null,
114                              "Default": "1",
115                              "Extra": null
116                          },
117                          "seqid": {
118                              "Field": "seqid",
119                              "Type": "int(11)",
120                              "Null": "NO",
121                              "Key": "MUL",
122                              "Default": "0",
123                              "Extra": null
124                          },
125                          "seqmax": {
126                              "Field": "seqmax",
127                              "Type": "int(11)",
128                              "Null": "NO",
129                              "Key": null,
130                              "Default": "0",
131                              "Extra": null
132                          },
133                          "display_name": {
134                              "Field": "display_name",
135                              "Type": "text",
136                              "Null": "NO",
137                              "Key": null,
138                              "Default": null,
139                              "Extra": null
140                          },
141                          "is_system_enum": {
142                              "Field": "is_system_enum",
143                              "Type": "int(2)",
144                              "Null": "NO",
145                              "Key": null,
146                              "Default": "0",
147                              "Extra": null
148                          }
149                      }
150                  },
151                  "person_type": {
152                      "Field": "person_type",
153                      "Type": "text",
154                      "Null": "NO",
155                      "Key": null,
156                      "Default": null,
157                      "Extra": null
158                  },
159                  "employer_name": {
160                      "Field": "employer_name",
161                      "Type": "text",
162                      "Null": "NO",
163                      "Key": null,
164                      "Default": null,
165                      "Extra": null
166                  },
167                  "birth_date": {
168                      "Field": "birth_date",
169                      "Type": "date",
170                      "Null": "NO",
171                      "Key": null,
172                      "Default": "0000-00-00",
173                      "Extra": null
174                  },
175                  "employ_start_date": {
176                      "Field": "employ_start_date",
177                      "Type": "date",
178                      "Null": "NO",
179                      "Key": null,
180                      "Default": "0000-00-00",
181                      "Extra": null
182                  },
183                  "employ_end_date": {
184                      "Field": "employ_end_date",
185                      "Type": "date",
186                      "Null": "NO",
187                      "Key": null,
188                      "Default": "0000-00-00",
189                      "Extra": null
190                  },
191                  "hide_same_employer": {
192                      "Field": "hide_same_employer",
193                      "Type": "int(4)",
194                      "Null": "NO",
195                      "Key": null,
196                      "Default": "0",
197                      "Extra": null
198                  },
199                  "salary_currency": {
200                      "Field": "salary_currency",
201                      "Type": "varchar(256)",
202                      "Null": "NO",
203                      "Key": null,
204                      "Default": null,
205                      "Extra": null
206                  },
207                  "quota_currency": {
208                      "Field": "quota_currency",
209                      "Type": "varchar(256)",
210                      "Null": "NO",
211                      "Key": null,
212                      "Default": null,
213                      "Extra": null
214                  },
215                  "created_dt": {
216                      "Field": "created_dt",
217                      "Type": "datetime",
218                      "Null": "NO",
219                      "Key": null,
220                      "Default": "0000-00-00 00:00:00",
221                      "Extra": null
222                  },
223                  "updated_dt": {
224                      "Field": "updated_dt",
225                      "Type": "datetime",
226                      "Null": "NO",
227                      "Key": null,
228                      "Default": "0000-00-00 00:00:00",
229                      "Extra": null
230                  }
231              };
232              
233              Roo.log('debuging...');
234              _this.panel.loadData(data);
235          
236          }
237        }
238       }
239      ]
240
241     },
242     '|xns' : 'Roo.grid',
243     autoExpandColumn : 'title',
244     clicksToEdit : 1,
245     loadMask : true,
246     xns : Roo.grid,
247     xtype : 'EditorGrid',
248     cm : [
249       {
250        '|xns' : 'Roo.grid',
251        dataIndex : 'active',
252        header : _this._strings['0ccc2bf3fb98387c23b6ca5500244d6e'],
253        renderer : function(v) {  
254            var state = v *1 > 0 ?  '-checked' : '';
255        
256            return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
257                        
258         },
259        width : 75,
260        xns : Roo.grid,
261        xtype : 'ColumnModel'
262       },
263 {
264        '|xns' : 'Roo.grid',
265        dataIndex : 'dataIndex',
266        header : _this._strings['4ce58cbe362a5d7b156992a496d55bf3'],
267        renderer : function(v) { return String.format('{0}', v); },
268        width : 150,
269        xns : Roo.grid,
270        xtype : 'ColumnModel'
271       },
272 {
273        '|xns' : 'Roo.grid',
274        dataIndex : 'type',
275        header : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'],
276        renderer : function(v) { return String.format('{0}', v); },
277        width : 100,
278        xns : Roo.grid,
279        xtype : 'ColumnModel'
280       },
281 {
282        editor : {
283         field : {
284          '|xns' : 'Roo.form',
285          xns : Roo.form,
286          xtype : 'TextField'
287         },
288         '|xns' : 'Roo.grid',
289         xns : Roo.grid,
290         xtype : 'GridEditor',
291         items : [
292
293         ]
294
295        },
296        '|xns' : 'Roo.grid',
297        dataIndex : 'title',
298        header : _this._strings['b021df6aac4654c454f46c77646e745f'],
299        renderer : function(v) { return String.format('{0}', v); },
300        width : 120,
301        xns : Roo.grid,
302        xtype : 'ColumnModel',
303        items : [
304
305        ]
306
307       },
308 {
309        editor : {
310         field : {
311          store : {
312           '|xns' : 'Roo.data',
313           data : [ 
314               [ 'ComboBox', "ComboBox"],
315               [ 'TextField' , "TextField"],
316               [ 'NumberField', "NumberField"],
317               [ 'TextArea', "TextArea"],
318               [ 'HtmlEditor', "HtmlEditor"],
319               [ 'Hidden', "Hidden"],
320               [ 'DateField', "DateField"]    ,
321                [ 'Checkbox', "Checkbox"]    
322               // checkbox?
323           ],
324           fields : [  'ftype', 'fname'],
325           xns : Roo.data,
326           xtype : 'SimpleStore'
327          },
328          '|xns' : 'Roo.form',
329          allowBlank : false,
330          displayField : 'fname',
331          editable : false,
332          hiddenName : 'status',
333          listWidth : 200,
334          mode : 'local',
335          name : 'field_type',
336          triggerAction : 'all',
337          valueField : 'ftype',
338          width : 150,
339          xns : Roo.form,
340          xtype : 'ComboBox',
341          items : [
342
343          ]
344
345         },
346         '|xns' : 'Roo.grid',
347         xns : Roo.grid,
348         xtype : 'GridEditor',
349         items : [
350
351         ]
352
353        },
354        '|xns' : 'Roo.grid',
355        dataIndex : 'ftype',
356        header : _this._strings['189efd19c4153526994a6d7ea5f6f068'],
357        renderer : function(v) { return String.format('{0}', v); },
358        width : 120,
359        xns : Roo.grid,
360        xtype : 'ColumnModel',
361        items : [
362
363        ]
364
365       },
366 {
367        editor : {
368         field : {
369          store : {
370           '|xns' : 'Roo.data',
371           data : [ 
372               [ 'ComboBox', "ComboBox"],
373               [ 'Text' , "TextField"],
374               [ 'Number', "NumberField"],
375               [ 'TextArea', "TextArea"],
376               [ 'Html', "HtmlEntry"]
377               
378           ],
379           fields : [  'ftype', 'fname'],
380           xns : Roo.data,
381           xtype : 'SimpleStore'
382          },
383          '|xns' : 'Roo.form',
384          allowBlank : false,
385          displayField : 'fname',
386          editable : false,
387          hiddenName : 'status',
388          listWidth : 200,
389          mode : 'local',
390          name : 'combo_display',
391          triggerAction : 'all',
392          valueField : 'ftype',
393          width : 150,
394          xns : Roo.form,
395          xtype : 'ComboBox',
396          items : [
397
398          ]
399
400         },
401         '|xns' : 'Roo.grid',
402         xns : Roo.grid,
403         xtype : 'GridEditor',
404         items : [
405
406         ]
407
408        },
409        '|xns' : 'Roo.grid',
410        dataIndex : 'display_field',
411        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
412        renderer : function(v) { return String.format('{0}', v); },
413        width : 150,
414        xns : Roo.grid,
415        xtype : 'ColumnModel',
416        items : [
417
418        ]
419
420       },
421 {
422        editor : {
423         field : {
424          '|xns' : 'Roo.form',
425          decimalPrecision : 0,
426          xns : Roo.form,
427          xtype : 'NumberField'
428         },
429         '|xns' : 'Roo.grid',
430         xns : Roo.grid,
431         xtype : 'GridEditor',
432         items : [
433
434         ]
435
436        },
437        '|xns' : 'Roo.grid',
438        dataIndex : 'width',
439        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
440        renderer : function(v) { return String.format('{0}', v); },
441        width : 75,
442        xns : Roo.grid,
443        xtype : 'ColumnModel',
444        items : [
445
446        ]
447
448       }
449     ],
450     listeners : {
451      cellclick : function (_self, rowIndex, columnIndex, e)
452       {
453       
454               var di = this.colModel.getDataIndex(columnIndex);
455               if (di != 'active') {
456                   return;
457               }
458                
459               var rec = _this.grid.ds.getAt(rowIndex);
460               
461               rec.set('active', rec.data.active * 1 ? 0 : 1);
462               rec.commit();
463                
464               
465       },
466      render : function() 
467       {
468           _this.grid = this; 
469           //_this.dialog = Pman.Dialog.FILL_IN
470       
471       },
472      rowdblclick : function (_self, rowIndex, e)
473       {
474           if (!_this.dialog) return;
475         
476       }
477     },
478     items : [
479
480     ]
481
482    },
483    '|xns' : 'Roo',
484    background : false,
485    fitContainer : true,
486    fitToframe : true,
487    loadData : function(data) { 
488    
489        alert("IPC:TEST:" + JSON.stringify(data,null,4));
490    
491        var ar = [];
492        for (var k in data) { 
493            var r = data[k];
494            var has_s = typeof(r.relates_to_schema) != 'undefined'
495            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100 , 'TextField', r.Field + '_display_name'] );
496            if (!has_s) {
497                continue;
498            }
499            /*
500            for (var kk in r.relates_to_schema) {         
501                var rr = r.relates_to_schema[kk];
502                if (rr.Field == r.relates_to_col) {
503                    continue;
504                }
505                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
506            }
507            */
508        }
509        this.schema = data;
510        //alert("IPC:TEST:" + JSON.stringify(ar));
511        this.grid.dataSource.loadData(ar);
512    },
513    region : 'center',
514    tableName : 'core_enum',
515    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
516    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
517    toBJS : function() { 
518    
519    // convert the selected cells into a BJS data ready to send back to the UI..
520    
521        this.table = "XXX";
522        this.firstTxtCol = "XXX";
523       
524        var formHeight = 50;
525        
526        var jreader = {};
527        var  formElements = [];
528        this.grid.dataSource.each(function(rec) {
529            if (!rec.data.active) {
530                return;
531            }
532            
533            var el = {
534                fieldLabel : rec.data.title,
535                name : rec.data.dataIndex,
536                width : 200, //row.type == 'string' ? 200 : 75,
537                '|xns' : 'Roo.form',
538                xtype : rec.data.ftype
539            }
540             if (xtype == 'DateField') {
541                el.format = 'Y-m-d';
542                el.useIso = true;
543                el.width = 100;
544            }
545            
546            if (xtype == 'TextArea') {
547                el.height = 100;
548            }
549            
550            if (xtype == 'Hidden') {
551                delete el.fieldLabel;
552                delete el.width;
553            }
554            if (xtype == 'Combobox') {
555            
556    
557                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
558                
559                el.hiddenName = rec.data.dataIndex // SET WHEN USED eg. project_id
560                el.displayField = combofields_name; // SET WHEN USED eg. project_id
561                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
562                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
563              
564            
565               el.items = [
566                    {
567                            
568                        '*prop' : 'store',
569                        'xtype' : 'Store',
570                        '|xns' : 'Roo.data',
571                        'remoteSort' : true,
572                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
573                        listeners : {
574                            '|beforeload' : 'function (_self, o)' +
575                            "{\n" +
576                            "    o.params = o.params || {};\n" +
577                            "    // set more here\n" +
578                            "}\n"
579                        },
580                        items : [
581                            {
582                                '*prop' : 'proxy',
583                                'xtype' : 'HttpProxy',
584                                'method' : 'GET',
585                                '|xns' : 'Roo.data',
586                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
587                            },
588                            
589                            {
590                                '*prop' : 'reader',
591                                'xtype' : 'JsonReader',
592                                '|xns' : 'Roo.data',
593                                'id' : 'id',
594                                'root' : 'data',
595                                'totalProperty' : 'total'
596    
597                                
598                            }
599                        ]
600                    }
601                ];
602            
603            }
604            
605            
606            formElements.push(el);
607            
608            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
609            
610            
611        });
612        
613        
614        
615        
616        
617        
618         var frmCfg = 
619        {
620            '|xns' : 'Roo.form',
621            xtype : "Form",
622            listeners : {
623                "|actioncomplete" : "function(_self,action)\n"+
624                    "{\n"+
625                    "    if (action.type == 'setdata') {\n"+
626                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
627                    "       return;\n"+
628                    "    }\n"+
629                    "    if (action.type == 'load') {\n"+
630                    "        return;\n"+
631                    "    }\n"+
632                    "    if (action.type =='submit') {\n"+
633                    "    \n"+
634                    "        _this.dialog.hide();\n"+
635                    "    \n"+
636                    "         if (_this.callback) {\n"+
637                    "            _this.callback.call(_this, action.result.data);\n"+
638                    "         }\n"+
639                    "         _this.form.reset();\n"+
640                    "         return;\n"+
641                    "    }\n"+
642                    "}\n",
643                
644                "|rendered" : "function (form)\n"+
645                    "{\n"+
646                    "    _this.form= form;\n"+
647                    "}\n"
648            },
649            method : "POST",
650            style : "margin:10px;",
651            "|url" : "baseURL + '/Roo/" + this.table + "'",
652            items : formElements
653        };
654        
655    
656        alert("IPC:OUT:" + JSON.stringify({
657                "closable": false,
658                "collapsible": false,
659                "height": formHeight,
660                "resizable": false,
661                "title": "Edit / Create " + this.table,
662                "width": 400,
663                "modal" : true,
664                "xtype": "LayoutDialog",
665                "|xns": "Roo",
666                "items": [
667                    {
668                        "|xns": "Roo",
669                        "xtype": "LayoutRegion",
670                        "*prop": "center"
671                    },
672                    {
673                        "region": "center",
674                        "xtype": "ContentPanel",
675                        "|xns": "Roo",
676                        "items": [
677                            frmCfg
678                        ]
679                    },
680                    
681                    {
682                        "listeners": {
683                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
684                        },
685                        "*prop": "buttons[]",
686                        "text": "Cancel",
687                        "xtype": "Button",
688                        "|xns": "Roo"
689                    },
690                    {
691                        "listeners": {
692                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
693                        },
694                        "*prop": "buttons[]",
695                        "text": "Save",
696                        "xtype": "Button",
697                        "|xns": "Roo"
698                    }
699                ]
700            
701            
702            
703        }, null, 4));
704    
705    },
706    xns : Roo,
707    xtype : 'GridPanel',
708    listeners : {
709     activate : function() {
710          _this.panel = this;
711          if (_this.grid) {
712              _this.grid.footer.onClick('first');
713          }
714      }
715    },
716    items : [
717
718    ]
719
720   };  }
721 });