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