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