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               ['id']
383           ],
384           fields : [  'ftype'],
385           xns : Roo.data,
386           xtype : 'SimpleStore'
387          },
388          '|xns' : 'Roo.form',
389          allowBlank : false,
390          displayField : 'fname',
391          editable : false,
392          hiddenName : 'status',
393          listWidth : 200,
394          mode : 'local',
395          name : 'display_field',
396          triggerAction : 'all',
397          valueField : 'ftype',
398          width : 150,
399          xns : Roo.form,
400          xtype : 'ComboBox',
401          items : [
402
403          ]
404
405         },
406         '|xns' : 'Roo.grid',
407         xns : Roo.grid,
408         xtype : 'GridEditor',
409         items : [
410
411         ]
412
413        },
414        '|xns' : 'Roo.grid',
415        dataIndex : 'display_field',
416        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
417        renderer : function(v) { return String.format('{0}', v); },
418        width : 150,
419        xns : Roo.grid,
420        xtype : 'ColumnModel',
421        items : [
422
423        ]
424
425       },
426 {
427        editor : {
428         field : {
429          '|xns' : 'Roo.form',
430          decimalPrecision : 0,
431          xns : Roo.form,
432          xtype : 'NumberField'
433         },
434         '|xns' : 'Roo.grid',
435         xns : Roo.grid,
436         xtype : 'GridEditor',
437         items : [
438
439         ]
440
441        },
442        '|xns' : 'Roo.grid',
443        dataIndex : 'width',
444        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
445        renderer : function(v) { return String.format('{0}', v); },
446        width : 75,
447        xns : Roo.grid,
448        xtype : 'ColumnModel',
449        items : [
450
451        ]
452
453       }
454     ],
455     listeners : {
456      beforeedit : function (e)
457       {
458           Roo.log('before edit!!!');
459           Roo.log(e);
460           
461           _this.grid.colModel.getCellEditor(e.column, e.row).field.store.loadData(e.record.data.relates_to_schema);
462       },
463      cellclick : function (_self, rowIndex, columnIndex, e)
464       {
465       
466               var di = this.colModel.getDataIndex(columnIndex);
467               if (di != 'active') {
468                   return;
469               }
470                
471               var rec = _this.grid.ds.getAt(rowIndex);
472               
473               rec.set('active', rec.data.active * 1 ? 0 : 1);
474               rec.commit();
475                
476               
477       },
478      render : function() 
479       {
480           _this.grid = this; 
481           //_this.dialog = Pman.Dialog.FILL_IN
482       
483       },
484      rowdblclick : function (_self, rowIndex, e)
485       {
486           if (!_this.dialog) return;
487         
488       }
489     },
490     items : [
491
492     ]
493
494    },
495    '|xns' : 'Roo',
496    background : false,
497    fitContainer : true,
498    fitToframe : true,
499    loadData : function(data) { 
500    
501        //alert("IPC:TEST:" + JSON.stringify(data,null,4));
502    
503        var fields = _this.grid.dataSource.reader.recordType.prototype.fields;
504        
505        
506        var d = [];
507    
508        for (var k in data) { 
509            var r = data[k];
510            var has_s = typeof(r.relates_to_schema) != 'undefined';
511            
512            var rt = '', rc = '', rs = [];
513            
514            if(has_s){
515                for (var kk in r.relates_to_schema) {         
516                    var rr = r.relates_to_schema[kk];
517                    
518                    rt = r.relates_to_table;
519                    rc = r.relates_to_col;
520                    
521                    rs.push([rr.Field]);
522                    
523                }
524            }
525            
526            var o = {
527                active : !has_s,
528                dataIndex : r.Field,
529                type : r.Type,
530                title : r.Field,
531                width : 100,
532                ftype : 'TextField',
533                display_field : r.Field + '_display_name',
534                relates_to_table : rt,
535                relates_to_col : rc,
536                relates_to_schema : rs
537            };
538            
539            d.push(o);
540            
541            if (!has_s) {
542                continue;
543            }
544            
545            for (var kk in r.relates_to_schema) {         
546                var rr = r.relates_to_schema[kk];
547                if (rr.Field == r.relates_to_col) {
548                    continue;
549                }
550                
551                var o = {
552                    active : false,
553                    dataIndex : r.Field + '_'+ rr.Field,
554                    type : r.Type,
555                    title : r.Field,
556                    width : 100
557                };
558                
559                d.push(o);
560            }
561        }
562    
563        var ar = [];
564        
565        Roo.each(d, function(dd){
566    
567            var a = [];
568            
569            for(var j = 0; j < fields.length; j++){
570                var f = fields.items[j];
571                
572                if(dd.hasOwnProperty(f.name)){
573                    a.push(dd[f.name]);
574                }
575            }
576            
577            ar.push(a);
578        });
579        
580        
581        Roo.log(ar);
582        this.schema = data;
583        
584        //alert("IPC:TEST:" + JSON.stringify(ar));
585        this.grid.dataSource.loadData(ar);
586    },
587    region : 'center',
588    tableName : 'core_enum',
589    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
590    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
591    toBJS : function() { 
592    
593    // convert the selected cells into a BJS data ready to send back to the UI..
594    
595        this.table = "XXX";
596        this.firstTxtCol = "XXX";
597       
598        var formHeight = 50;
599        
600        var jreader = {};
601        var  formElements = [];
602        this.grid.dataSource.each(function(rec) {
603            if (!rec.data.active) {
604                return;
605            }
606            
607            var el = {
608                fieldLabel : rec.data.title,
609                name : rec.data.dataIndex,
610                width : 200, //row.type == 'string' ? 200 : 75,
611                '|xns' : 'Roo.form',
612                xtype : rec.data.ftype
613            }
614             if (xtype == 'DateField') {
615                el.format = 'Y-m-d';
616                el.useIso = true;
617                el.width = 100;
618            }
619            
620            if (xtype == 'TextArea') {
621                el.height = 100;
622            }
623            
624            if (xtype == 'Hidden') {
625                delete el.fieldLabel;
626                delete el.width;
627            }
628            if (xtype == 'Combobox') {
629            
630    
631                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
632                
633                el.hiddenName = rec.data.dataIndex // SET WHEN USED eg. project_id
634                el.displayField = combofields_name; // SET WHEN USED eg. project_id
635                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
636                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
637              
638            
639               el.items = [
640                    {
641                            
642                        '*prop' : 'store',
643                        'xtype' : 'Store',
644                        '|xns' : 'Roo.data',
645                        'remoteSort' : true,
646                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
647                        listeners : {
648                            '|beforeload' : 'function (_self, o)' +
649                            "{\n" +
650                            "    o.params = o.params || {};\n" +
651                            "    // set more here\n" +
652                            "}\n"
653                        },
654                        items : [
655                            {
656                                '*prop' : 'proxy',
657                                'xtype' : 'HttpProxy',
658                                'method' : 'GET',
659                                '|xns' : 'Roo.data',
660                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
661                            },
662                            
663                            {
664                                '*prop' : 'reader',
665                                'xtype' : 'JsonReader',
666                                '|xns' : 'Roo.data',
667                                'id' : 'id',
668                                'root' : 'data',
669                                'totalProperty' : 'total'
670    
671                                
672                            }
673                        ]
674                    }
675                ];
676            
677            }
678            
679            
680            formElements.push(el);
681            
682            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
683            
684            
685        });
686        
687        
688        
689        
690        
691        
692         var frmCfg = 
693        {
694            '|xns' : 'Roo.form',
695            xtype : "Form",
696            listeners : {
697                "|actioncomplete" : "function(_self,action)\n"+
698                    "{\n"+
699                    "    if (action.type == 'setdata') {\n"+
700                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
701                    "       return;\n"+
702                    "    }\n"+
703                    "    if (action.type == 'load') {\n"+
704                    "        return;\n"+
705                    "    }\n"+
706                    "    if (action.type =='submit') {\n"+
707                    "    \n"+
708                    "        _this.dialog.hide();\n"+
709                    "    \n"+
710                    "         if (_this.callback) {\n"+
711                    "            _this.callback.call(_this, action.result.data);\n"+
712                    "         }\n"+
713                    "         _this.form.reset();\n"+
714                    "         return;\n"+
715                    "    }\n"+
716                    "}\n",
717                
718                "|rendered" : "function (form)\n"+
719                    "{\n"+
720                    "    _this.form= form;\n"+
721                    "}\n"
722            },
723            method : "POST",
724            style : "margin:10px;",
725            "|url" : "baseURL + '/Roo/" + this.table + "'",
726            items : formElements
727        };
728        
729    
730        alert("IPC:OUT:" + JSON.stringify({
731                "closable": false,
732                "collapsible": false,
733                "height": formHeight,
734                "resizable": false,
735                "title": "Edit / Create " + this.table,
736                "width": 400,
737                "modal" : true,
738                "xtype": "LayoutDialog",
739                "|xns": "Roo",
740                "items": [
741                    {
742                        "|xns": "Roo",
743                        "xtype": "LayoutRegion",
744                        "*prop": "center"
745                    },
746                    {
747                        "region": "center",
748                        "xtype": "ContentPanel",
749                        "|xns": "Roo",
750                        "items": [
751                            frmCfg
752                        ]
753                    },
754                    
755                    {
756                        "listeners": {
757                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
758                        },
759                        "*prop": "buttons[]",
760                        "text": "Cancel",
761                        "xtype": "Button",
762                        "|xns": "Roo"
763                    },
764                    {
765                        "listeners": {
766                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
767                        },
768                        "*prop": "buttons[]",
769                        "text": "Save",
770                        "xtype": "Button",
771                        "|xns": "Roo"
772                    }
773                ]
774            
775            
776            
777        }, null, 4));
778    
779    },
780    xns : Roo,
781    xtype : 'GridPanel',
782    listeners : {
783     activate : function() {
784          _this.panel = this;
785          if (_this.grid) {
786              _this.grid.footer.onClick('first');
787          }
788      }
789    },
790    items : [
791
792    ]
793
794   };  }
795 });