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