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