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          
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          listeners : {
341           render : function (_self)
342            {
343                Roo.log('ftype combo render');
344                _this.ftype_combo = _self;
345            }
346          },
347          items : [
348
349          ]
350
351         },
352         '|xns' : 'Roo.grid',
353         xns : Roo.grid,
354         xtype : 'GridEditor',
355         items : [
356
357         ]
358
359        },
360        '|xns' : 'Roo.grid',
361        dataIndex : 'ftype',
362        header : _this._strings['189efd19c4153526994a6d7ea5f6f068'],
363        renderer : function(v) { return String.format('{0}', v); },
364        width : 120,
365        xns : Roo.grid,
366        xtype : 'ColumnModel',
367        items : [
368
369        ]
370
371       },
372 {
373        editor : {
374         field : {
375          store : {
376           '|xns' : 'Roo.data',
377           data : [ 
378               [ 'ComboBox', "ComboBox"],
379               [ 'Text' , "TextField"],
380               [ 'Number', "NumberField"],
381               [ 'TextArea', "TextArea"],
382               [ 'Html', "HtmlEntry"]
383               
384           ],
385           fields : [  'ftype', 'fname'],
386           xns : Roo.data,
387           xtype : 'SimpleStore'
388          },
389          '|xns' : 'Roo.form',
390          allowBlank : false,
391          displayField : 'fname',
392          editable : false,
393          hiddenName : 'status',
394          listWidth : 200,
395          mode : 'local',
396          name : 'display_field',
397          triggerAction : 'all',
398          valueField : 'ftype',
399          width : 150,
400          xns : Roo.form,
401          xtype : 'ComboBox',
402          listeners : {
403           render : function (_self)
404            {
405                _this.display_field_combo = _self;
406            }
407          },
408          items : [
409
410          ]
411
412         },
413         '|xns' : 'Roo.grid',
414         xns : Roo.grid,
415         xtype : 'GridEditor',
416         items : [
417
418         ]
419
420        },
421        '|xns' : 'Roo.grid',
422        dataIndex : 'display_field',
423        header : _this._strings['793548e77e782c209a78ed67f255b5e2'],
424        renderer : function(v) { return String.format('{0}', v); },
425        width : 150,
426        xns : Roo.grid,
427        xtype : 'ColumnModel',
428        items : [
429
430        ]
431
432       },
433 {
434        editor : {
435         field : {
436          '|xns' : 'Roo.form',
437          decimalPrecision : 0,
438          xns : Roo.form,
439          xtype : 'NumberField'
440         },
441         '|xns' : 'Roo.grid',
442         xns : Roo.grid,
443         xtype : 'GridEditor',
444         items : [
445
446         ]
447
448        },
449        '|xns' : 'Roo.grid',
450        dataIndex : 'width',
451        header : _this._strings['32954654ac8fe66a1d09be19001de2d4'],
452        renderer : function(v) { return String.format('{0}', v); },
453        width : 75,
454        xns : Roo.grid,
455        xtype : 'ColumnModel',
456        items : [
457
458        ]
459
460       }
461     ],
462     listeners : {
463      cellclick : function (_self, rowIndex, columnIndex, e)
464       {
465       
466               var di = this.colModel.getDataIndex(columnIndex);
467               if (di != 'active') {
468                   return;
469               }
470                
471               var rec = _this.grid.ds.getAt(rowIndex);
472               
473               rec.set('active', rec.data.active * 1 ? 0 : 1);
474               rec.commit();
475                
476               
477       },
478      render : function() 
479       {
480           _this.grid = this; 
481           //_this.dialog = Pman.Dialog.FILL_IN
482       
483       },
484      rowdblclick : function (_self, rowIndex, e)
485       {
486           if (!_this.dialog) return;
487         
488       }
489     },
490     items : [
491
492     ]
493
494    },
495    '|xns' : 'Roo',
496    background : false,
497    fitContainer : true,
498    fitToframe : true,
499    loadData : function(data) { 
500    
501        //alert("IPC:TEST:" + JSON.stringify(data,null,4));
502    
503        var ar = [];
504        for (var k in data) { 
505            var r = data[k];
506            var has_s = typeof(r.relates_to_schema) != 'undefined'
507            ar.push([ !has_s , r.Field, r.Type,  r.Field, 100 , 'TextField', r.Field + '_display_name'] );
508            if (!has_s) {
509                continue;
510            }
511            
512            for (var kk in r.relates_to_schema) {         
513                var rr = r.relates_to_schema[kk];
514                if (rr.Field == r.relates_to_col) {
515                    continue;
516                }
517                ar.push([ false, r.Field + '_'+ rr.Field, rr.Type,  rr.Field, 100] );
518            }
519            
520        }
521        this.schema = data;
522        
523        //alert("IPC:TEST:" + JSON.stringify(ar));
524        this.grid.dataSource.loadData(ar);
525    },
526    region : 'center',
527    tableName : 'core_enum',
528    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
529    title : _this._strings['c671c787b49f50a3ace9fdc5bd597825'],
530    toBJS : function() { 
531    
532    // convert the selected cells into a BJS data ready to send back to the UI..
533    
534        this.table = "XXX";
535        this.firstTxtCol = "XXX";
536       
537        var formHeight = 50;
538        
539        var jreader = {};
540        var  formElements = [];
541        this.grid.dataSource.each(function(rec) {
542            if (!rec.data.active) {
543                return;
544            }
545            
546            var el = {
547                fieldLabel : rec.data.title,
548                name : rec.data.dataIndex,
549                width : 200, //row.type == 'string' ? 200 : 75,
550                '|xns' : 'Roo.form',
551                xtype : rec.data.ftype
552            }
553             if (xtype == 'DateField') {
554                el.format = 'Y-m-d';
555                el.useIso = true;
556                el.width = 100;
557            }
558            
559            if (xtype == 'TextArea') {
560                el.height = 100;
561            }
562            
563            if (xtype == 'Hidden') {
564                delete el.fieldLabel;
565                delete el.width;
566            }
567            if (xtype == 'Combobox') {
568            
569    
570                el.queryParam  = 'query[' + combofields_name + ']';// SET WHEN USED
571                
572                el.hiddenName = rec.data.dataIndex // SET WHEN USED eg. project_id
573                el.displayField = combofields_name; // SET WHEN USED eg. project_id
574                el.name  = old.name + '_' + combofields_name; // SET WHEN USED eg. project_id_name
575                el.tpl = '<div class="x-grid-cell-text x-btn button"><b>{' + combofields_name +'}</b> </div>'; // SET WHEN USED
576              
577            
578               el.items = [
579                    {
580                            
581                        '*prop' : 'store',
582                        'xtype' : 'Store',
583                        '|xns' : 'Roo.data',
584                        'remoteSort' : true,
585                        '|sortInfo' : '{ direction : \'ASC\', field: \'id\' }',
586                        listeners : {
587                            '|beforeload' : 'function (_self, o)' +
588                            "{\n" +
589                            "    o.params = o.params || {};\n" +
590                            "    // set more here\n" +
591                            "}\n"
592                        },
593                        items : [
594                            {
595                                '*prop' : 'proxy',
596                                'xtype' : 'HttpProxy',
597                                'method' : 'GET',
598                                '|xns' : 'Roo.data',
599                                '|url' : "baseURL + '/Roo/" + reftable + ".php'",
600                            },
601                            
602                            {
603                                '*prop' : 'reader',
604                                'xtype' : 'JsonReader',
605                                '|xns' : 'Roo.data',
606                                'id' : 'id',
607                                'root' : 'data',
608                                'totalProperty' : 'total'
609    
610                                
611                            }
612                        ]
613                    }
614                ];
615            
616            }
617            
618            
619            formElements.push(el);
620            
621            formHeight += rec.data.ftype == 'TextArea' ? 100 : 30;
622            
623            
624        });
625        
626        
627        
628        
629        
630        
631         var frmCfg = 
632        {
633            '|xns' : 'Roo.form',
634            xtype : "Form",
635            listeners : {
636                "|actioncomplete" : "function(_self,action)\n"+
637                    "{\n"+
638                    "    if (action.type == 'setdata') {\n"+
639                    "       //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+
640                    "       return;\n"+
641                    "    }\n"+
642                    "    if (action.type == 'load') {\n"+
643                    "        return;\n"+
644                    "    }\n"+
645                    "    if (action.type =='submit') {\n"+
646                    "    \n"+
647                    "        _this.dialog.hide();\n"+
648                    "    \n"+
649                    "         if (_this.callback) {\n"+
650                    "            _this.callback.call(_this, action.result.data);\n"+
651                    "         }\n"+
652                    "         _this.form.reset();\n"+
653                    "         return;\n"+
654                    "    }\n"+
655                    "}\n",
656                
657                "|rendered" : "function (form)\n"+
658                    "{\n"+
659                    "    _this.form= form;\n"+
660                    "}\n"
661            },
662            method : "POST",
663            style : "margin:10px;",
664            "|url" : "baseURL + '/Roo/" + this.table + "'",
665            items : formElements
666        };
667        
668    
669        alert("IPC:OUT:" + JSON.stringify({
670                "closable": false,
671                "collapsible": false,
672                "height": formHeight,
673                "resizable": false,
674                "title": "Edit / Create " + this.table,
675                "width": 400,
676                "modal" : true,
677                "xtype": "LayoutDialog",
678                "|xns": "Roo",
679                "items": [
680                    {
681                        "|xns": "Roo",
682                        "xtype": "LayoutRegion",
683                        "*prop": "center"
684                    },
685                    {
686                        "region": "center",
687                        "xtype": "ContentPanel",
688                        "|xns": "Roo",
689                        "items": [
690                            frmCfg
691                        ]
692                    },
693                    
694                    {
695                        "listeners": {
696                            "click": "function (_self, e)\n{\n    _this.dialog.hide();\n}"
697                        },
698                        "*prop": "buttons[]",
699                        "text": "Cancel",
700                        "xtype": "Button",
701                        "|xns": "Roo"
702                    },
703                    {
704                        "listeners": {
705                            "click": "function (_self, e)\n{\n    // do some checks?\n     \n    \n    _this.dialog.el.mask(\"Saving\");\n    _this.form.doAction(\"submit\");\n\n}"
706                        },
707                        "*prop": "buttons[]",
708                        "text": "Save",
709                        "xtype": "Button",
710                        "|xns": "Roo"
711                    }
712                ]
713            
714            
715            
716        }, null, 4));
717    
718    },
719    xns : Roo,
720    xtype : 'GridPanel',
721    listeners : {
722     activate : function() {
723          _this.panel = this;
724          if (_this.grid) {
725              _this.grid.footer.onClick('first');
726          }
727      }
728    },
729    items : [
730
731    ]
732
733   };  }
734 });