4538bb196e81ded9cec99c6595db535f46052edf
[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   '040076bde7f6b3387448e32b66c2eee0' :"To BJS",
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              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('Loading Data...');
244              _this.panel.loadData(data);
245          
246          }
247        }
248       },
249       {
250        '|xns' : 'Roo.Toolbar',
251        text : _this._strings['040076bde7f6b3387448e32b66c2eee0'],
252        xns : Roo.Toolbar,
253        xtype : 'Button',
254        listeners : {
255         click : function (_self, e)
256          {
257              
258              Roo.log('Converting to BJS...');
259              _this.panel.toBJS();
260          
261          }
262        }
263       }
264      ]
265
266     },
267     '|xns' : 'Roo.grid',
268     autoExpandColumn : 'title',
269     clicksToEdit : 1,
270     loadMask : true,
271     xns : Roo.grid,
272     xtype : 'EditorGrid',
273     cm : [
274       {
275        '|xns' : 'Roo.grid',
276        dataIndex : 'active',
277        header : _this._strings['0ccc2bf3fb98387c23b6ca5500244d6e'],
278        renderer : function(v) {  
279            var state = v *1 > 0 ?  '-checked' : '';
280        
281            return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
282                        
283         },
284        width : 75,
285        xns : Roo.grid,
286        xtype : 'ColumnModel'
287       },
288 {
289        '|xns' : 'Roo.grid',
290        dataIndex : 'dataIndex',
291        header : _this._strings['4ce58cbe362a5d7b156992a496d55bf3'],
292        renderer : function(v) { return String.format('{0}', v); },
293        width : 150,
294        xns : Roo.grid,
295        xtype : 'ColumnModel'
296       },
297 {
298        '|xns' : 'Roo.grid',
299        dataIndex : 'type',
300        header : _this._strings['a1fa27779242b4902f7ae3bdd5c6d508'],
301        renderer : function(v) { return String.format('{0}', v); },
302        width : 100,
303        xns : Roo.grid,
304        xtype : 'ColumnModel'
305       },
306 {
307        editor : {
308         field : {
309          '|xns' : 'Roo.form',
310          xns : Roo.form,
311          xtype : 'TextField'
312         },
313         '|xns' : 'Roo.grid',
314         xns : Roo.grid,
315         xtype : 'GridEditor',
316         items : [
317
318         ]
319
320        },
321        '|xns' : 'Roo.grid',
322        dataIndex : 'title',
323        header : _this._strings['b021df6aac4654c454f46c77646e745f'],
324        renderer : function(v) { return String.format('{0}', v); },
325        width : 120,
326        xns : Roo.grid,
327        xtype : 'ColumnModel',
328        items : [
329
330        ]
331
332       },
333 {
334        editor : {
335         field : {
336          store : {
337           '|xns' : 'Roo.data',
338           data : [ 
339               [ 'ComboBox', "ComboBox"],
340               [ 'TextField' , "TextField"],
341               [ 'NumberField', "NumberField"],
342               [ 'TextArea', "TextArea"],
343               [ 'HtmlEditor', "HtmlEditor"],
344               [ 'Hidden', "Hidden"],
345               [ 'DateField', "DateField"],
346               [ 'Checkbox', "Checkbox"]    
347               // checkbox?
348           ],
349           fields : [  'ftype', 'fname'],
350           xns : Roo.data,
351           xtype : 'SimpleStore'
352          },
353          '|xns' : 'Roo.form',
354          allowBlank : false,
355          displayField : 'fname',
356          editable : false,
357          hiddenName : 'status',
358          listWidth : 200,
359          mode : 'local',
360          name : 'ftype',
361          triggerAction : 'all',
362          valueField : 'ftype',
363          width : 150,
364          xns : Roo.form,
365          xtype : 'ComboBox',
366          items : [
367
368          ]
369
370         },
371         '|xns' : 'Roo.grid',
372         xns : Roo.grid,
373         xtype : 'GridEditor',
374         items : [
375
376         ]
377
378        },
379        '|xns' : 'Roo.grid',
380        dataIndex : 'ftype',
381        header : _this._strings['189efd19c4153526994a6d7ea5f6f068'],
382        renderer : function(v) { return String.format('{0}', v); },
383        width : 120,
384        xns : Roo.grid,
385        xtype : 'ColumnModel',
386        items : [
387
388        ]
389
390       },
391 {
392        editor : {
393         field : {
394          store : {
395           '|xns' : 'Roo.data',
396           data : [ 
397               ['id']
398           ],
399           fields : [  'dfield'],
400           xns : Roo.data,
401           xtype : 'SimpleStore'
402          },
403          '|xns' : 'Roo.form',
404          allowBlank : false,
405          displayField : 'dfield',
406          editable : false,
407          hiddenName : 'status',
408          listWidth : 200,
409          mode : 'local',
410          name : 'display_field',
411          triggerAction : 'all',
412          valueField : 'dfield',
413          width : 150,
414          xns : Roo.form,
415          xtype : 'ComboBox',
416          items : [
417
418          ]
419
420         },
421         '|xns' : 'Roo.grid',
422         xns : Roo.grid,
423         xtype : 'GridEditor',
424         items : [
425
426         ]
427
428        },
429        '|xns' : 'Roo.grid',
430        dataIndex : 'display_field',
431        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
432        renderer : function(v) { return String.format('{0}', v); },
433        width : 150,
434        xns : Roo.grid,
435        xtype : 'ColumnModel',
436        items : [
437
438        ]
439
440       },
441 {
442        editor : {
443         field : {
444          '|xns' : 'Roo.form',
445          decimalPrecision : 0,
446          xns : Roo.form,
447          xtype : 'NumberField'
448         },
449         '|xns' : 'Roo.grid',
450         xns : Roo.grid,
451         xtype : 'GridEditor',
452         items : [
453
454         ]
455
456        },
457        '|xns' : 'Roo.grid',
458        dataIndex : 'width',
459        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
460        renderer : function(v) { return String.format('{0}', v); },
461        width : 75,
462        xns : Roo.grid,
463        xtype : 'ColumnModel',
464        items : [
465
466        ]
467
468       }
469     ],
470     listeners : {
471      beforeedit : function (e)
472       {
473           Roo.log('before edit!!!');
474           Roo.log(e);
475           
476           if(e.field != 'display_field'){
477               return;
478           }
479           
480           _this.grid.colModel.getCellEditor(e.column, e.row).field.store.loadData(e.record.data.relates_to_schema);
481       },
482      cellclick : function (_self, rowIndex, columnIndex, e)
483       {
484       
485               var di = this.colModel.getDataIndex(columnIndex);
486               if (di != 'active') {
487                   return;
488               }
489                
490               var rec = _this.grid.ds.getAt(rowIndex);
491               
492               rec.set('active', rec.data.active * 1 ? 0 : 1);
493               rec.commit();
494                
495               
496       },
497      render : function() 
498       {
499           _this.grid = this; 
500           //_this.dialog = Pman.Dialog.FILL_IN
501       
502       },
503      rowdblclick : function (_self, rowIndex, e)
504       {
505           if (!_this.dialog) return;
506         
507       }
508     },
509     items : [
510
511     ]
512
513    },
514    '|xns' : 'Roo',
515    background : false,
516    fitContainer : true,
517    fitToframe : true,
518    loadData : function(data) { 
519    
520        //alert("IPC:TEST:" + JSON.stringify(data,null,4));
521    
522        var fields = _this.grid.dataSource.reader.recordType.prototype.fields;
523        
524        
525        var d = [];
526    
527        for (var k in data) { 
528            var r = data[k];
529            var has_s = typeof(r.relates_to_schema) != 'undefined';
530            
531            var rt = '', rc = '', rs = [];
532            
533            if(has_s){
534                for (var kk in r.relates_to_schema) {         
535                    var rr = r.relates_to_schema[kk];
536                    
537                    rt = r.relates_to_table;
538                    rc = r.relates_to_col;
539                    
540                    rs.push([rr.Field]);
541                    
542                }
543            }
544            
545            var o = {
546                active : !has_s,
547                dataIndex : r.Field,
548                type : r.Type,
549                title : r.Field,
550                width : 100,
551                ftype : 'TextField',
552                display_field : rc, //r.Field + '_display_name',
553                relates_to_table : rt,
554                relates_to_col : rc,
555                relates_to_schema : rs
556            };
557            
558            d.push(o);
559            
560            if (!has_s) {
561                continue;
562            }
563            
564            for (var kk in r.relates_to_schema) {         
565                var rr = r.relates_to_schema[kk];
566                if (rr.Field == r.relates_to_col) {
567                    continue;
568                }
569                
570                var o = {
571                    active : false,
572                    dataIndex : r.Field + '_'+ rr.Field,
573                    type : r.Type,
574                    title : r.Field,
575                    width : 100
576                };
577                
578                d.push(o);
579            }
580        }
581    
582        var ar = [];
583        
584        Roo.each(d, function(dd){
585    
586            var a = [];
587            
588            for(var j = 0; j < fields.length; j++){
589                var f = fields.items[j];
590                
591                if(dd.hasOwnProperty(f.name)){
592                    a.push(dd[f.name]);
593                }
594            }
595            
596            ar.push(a);
597        });
598        
599        
600        Roo.log(ar);
601        this.schema = data;
602        
603        //alert("IPC:TEST:" + JSON.stringify(ar));
604        this.grid.dataSource.loadData(ar);
605    },
606    region : 'center',
607    tableName : 'core_enum',
608    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
609    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
610    toBJS : function() { 
611    
612    // convert the selected cells into a BJS data ready to send back to the UI..
613    
614        this.table = "XXX";
615        this.firstTxtCol = "XXX";
616       
617        var formHeight = 50;
618        
619        var jreader = {};
620        var  formElements = [];
621        this.grid.dataSource.each(function(rec) {
622            if (!rec.data.active) {
623                return;
624            }
625            
626            var el = {
627                fieldLabel : rec.data.title,
628                name : rec.data.dataIndex,
629                width : r.data.width,
630                '|xns' : 'Roo.form',
631                xtype : rec.data.ftype
632            }
633             if (xtype == 'DateField') {
634                el.format = 'Y-m-d';
635                el.useIso = true;
636                el.width = 100;
637            }
638            
639            if (xtype == 'TextArea') {
640                el.height = 100;
641            }
642            
643            if (xtype == 'Hidden') {
644                delete el.fieldLabel;
645                delete el.width;
646            }
647            if (xtype == 'Combobox') {
648            
649    
650                el.queryParam  = 'query[' + rec.data.display_field + ']';// SET WHEN USED
651                
652                el.hiddenName = rec.data.dataIndex // SET WHEN USED eg. project_id
653                el.name  = rec.data.dataIndex + '_' + rec.data.display_field; // SET WHEN USED eg. project_id_name
654                
655                el.displayField = rec.data.display_field // SET WHEN USED eg. project_id
656                el.valueField = rec.data.relates_to_col 
657                
658                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + rec.data.display_field +'}</b> </div>'; // SET WHEN USED
659              
660            
661               el.items = [
662                    {
663                            
664                        '*prop' : 'store',
665                        'xtype' : 'Store',
666                        '|xns' : 'Roo.data',
667                        'remoteSort' : true,
668                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
669                        listeners : {
670                            '|beforeload' : 'function (_self, o)' +
671                            "{\n" +
672                            "    o.params = o.params || {};\n" +
673                            "    // set more here\n" +
674                            "}\n"
675                        },
676                        items : [
677                            {
678                                '*prop' : 'proxy',
679                                'xtype' : 'HttpProxy',
680                                'method' : 'GET',
681                                '|xns' : 'Roo.data',
682                                '|url' : "baseURL + '/Roo/" + rec.data.relates_to_table + ".php'",
683                            },
684                            
685                            {
686                                '*prop' : 'reader',
687                                'xtype' : 'JsonReader',
688                                '|xns' : 'Roo.data',
689                                'id' : 'id',
690                                'root' : 'data',
691                                'totalProperty' : 'total'
692    
693                                
694                            }
695                        ]
696                    }
697                ];
698            
699            }
700            
701            if (xtype == 'HtmlEditor') {
702                el.height = 100,
703                el.resizable = 's',
704                el.toolbar = [
705                    {
706                        '|xns' : 'Roo.form.HtmlEditor',
707                        'xtype' : 'ToolbarContext'
708                    },
709                    {
710                        '|xns' : 'Roo.form.HtmlEditor',
711                        'xtype' : 'ToolbarStandard'
712    
713                   }
714                ]
715            }
716            
717            formElements.push(el);
718            
719            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
720            
721            
722        });
723        
724        
725        
726        
727        
728        
729         var frmCfg = 
730        {
731            '|xns' : 'Roo.form',
732            xtype : "Form",
733            listeners : {
734                "|actioncomplete" : "function(_self,action)\n"+
735                    "{\n"+
736                    "    if (action.type == 'setdata') {\n"+
737                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
738                    "       return;\n"+
739                    "    }\n"+
740                    "    if (action.type == 'load') {\n"+
741                    "        return;\n"+
742                    "    }\n"+
743                    "    if (action.type =='submit') {\n"+
744                    "    \n"+
745                    "        _this.dialog.hide();\n"+
746                    "    \n"+
747                    "         if (_this.callback) {\n"+
748                    "            _this.callback.call(_this, action.result.data);\n"+
749                    "         }\n"+
750                    "         _this.form.reset();\n"+
751                    "         return;\n"+
752                    "    }\n"+
753                    "}\n",
754                
755                "|rendered" : "function (form)\n"+
756                    "{\n"+
757                    "    _this.form= form;\n"+
758                    "}\n"
759            },
760            method : "POST",
761            style : "margin:10px;",
762            "|url" : "baseURL + '/Roo/" + this.table + "'",
763            items : formElements
764        };
765        
766    
767        alert("IPC:OUT:" + JSON.stringify({
768                "closable": false,
769                "collapsible": false,
770                "height": formHeight,
771                "resizable": false,
772                "title": "Edit / Create " + this.table,
773                "width": 400,
774                "modal" : true,
775                "xtype": "LayoutDialog",
776                "|xns": "Roo",
777                "items": [
778                    {
779                        "|xns": "Roo",
780                        "xtype": "LayoutRegion",
781                        "*prop": "center"
782                    },
783                    {
784                        "region": "center",
785                        "xtype": "ContentPanel",
786                        "|xns": "Roo",
787                        "items": [
788                            frmCfg
789                        ]
790                    },
791                    
792                    {
793                        "listeners": {
794                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
795                        },
796                        "*prop": "buttons[]",
797                        "text": "Cancel",
798                        "xtype": "Button",
799                        "|xns": "Roo"
800                    },
801                    {
802                        "listeners": {
803                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
804                        },
805                        "*prop": "buttons[]",
806                        "text": "Save",
807                        "xtype": "Button",
808                        "|xns": "Roo"
809                    }
810                ]
811            
812            
813            
814        }, null, 4));
815    
816    },
817    xns : Roo,
818    xtype : 'GridPanel',
819    listeners : {
820     activate : function() {
821          _this.panel = this;
822          if (_this.grid) {
823              _this.grid.footer.onClick('first');
824          }
825      }
826    },
827    items : [
828
829    ]
830
831   };  }
832 });