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