Pman.Dialog.BuilderAddTable.bjs
[Pman.Builder] / Pman.Dialog.BuilderAddTable.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.BuilderAddTable = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 show : function (_self)
35                 {
36                     _this.grid.ds.load({});
37                 }
38             },
39             closable : false,
40             collapsible : false,
41             height : 500,
42             modal : true,
43             resizable : false,
44             title : "Select columns to use",
45             width : 700,
46             items : [
47                 {
48                     xtype: 'GridPanel',
49                     xns: Roo,
50                     listeners : {
51                         activate : function() {
52                             _this.panel = this;
53                             if (_this.grid) {
54                                 _this.grid.ds.load({});
55                             }
56                         }
57                     },
58                     background : false,
59                     fitContainer : true,
60                     fitToframe : true,
61                     region : 'center',
62                     tableName : 'Images',
63                     title : "Images",
64                     grid : {
65                         xtype: 'Grid',
66                         xns: Roo.grid,
67                         listeners : {
68                             render : function() 
69                             {
70                                 _this.grid = this; 
71                                 //_this.dialog = Pman.Dialog.FILL_IN
72                                 if (_this.panel.active) {
73                                    this.ds.load({});
74                                 }
75                             },
76                             cellclick : function (_self, ri, ci , e)
77                             {
78                                if (ci > 1) {return; }
79                                
80                                 var rec = this.ds.getAt(ri);
81                                 var di = this.cm.getDataIndex(ci);
82                                 rec.set(di, (rec.data[di] * 1) ? 0 : 1);
83                                  rec.commit();
84                                  
85                                   
86                                   
87                             }
88                         },
89                         autoExpandColumn : 'desc',
90                         loadMask : true,
91                         dataSource : {
92                             xtype: 'Store',
93                             xns: Roo.data,
94                             listeners : {
95                                 beforeload : function (_self, options)
96                                 {
97                                     if (typeof(_this.data) == 'undefined') {
98                                         return false;
99                                     
100                                     }
101                                     options.params = options.params || {};
102                                     options.params.table = _this.data.table;
103                                 },
104                                 load : function (_self, records, options)
105                                 {
106                                     // after load, if we have configuration already, overlay that 
107                                     if (typeof(_this.data.cols) == 'undefined') {
108                                         return;
109                                     }
110                                     var cmap = {}
111                                     Roo.each(_this.data.cols, function (col) {
112                                         cmap[col.column] = col;
113                                     
114                                     });
115                                     Roo.each(records, function (col) {
116                                         if (typeof(cmap[col.data.column]) == 'undefined') {
117                                             return;
118                                         }
119                                         col.set('use', cmap[col.data.column].use);
120                                         col.set('use_ex', cmap[col.data.column].use_ex);
121                                         // what about descption..
122                                     });
123                                       
124                                         
125                                         
126                                 }
127                             },
128                             remoteSort : true,
129                             sortInfo : { field : 'filename', direction: 'ASC' },
130                             proxy : {
131                                 xtype: 'HttpProxy',
132                                 xns: Roo.data,
133                                 method : 'GET',
134                                 url : baseURL + '/Builder/ERM.php'
135                             },
136                             reader : {
137                                 xtype: 'JsonReader',
138                                 xns: Roo.data,
139                                 id : 'id',
140                                 root : 'data',
141                                 totalProperty : 'total',
142                                 fields : [
143                                     { name: 'use', type: 'int'} , 
144                                     { name: 'use_ex', type: 'int'}, 
145                                     'table', 'column', 'ctype', 'desc', 'columnshort'
146                                 ]
147                             }
148                         },
149                         toolbar : {
150                             xtype: 'Toolbar',
151                             xns: Roo,
152                             items : [
153                                 {
154                                     xtype: 'Button',
155                                     xns: Roo.Toolbar,
156                                     listeners : {
157                                         click : function()
158                                         {
159                                             
160                                         }
161                                     },
162                                     cls : 'x-btn-text-icon',
163                                     text : "Add",
164                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
165                                 },
166                                 {
167                                     xtype: 'Button',
168                                     xns: Roo.Toolbar,
169                                     listeners : {
170                                         click : function()
171                                         {
172                                             // Pman.genericDelete(_this, 'Images'); 
173                                         }
174                                     },
175                                     cls : 'x-btn-text-icon',
176                                     text : "Delete",
177                                     icon : rootURL + '/Pman/templates/images/trash.gif'
178                                 }
179                             ]
180                         },
181                         colModel : [
182                             {
183                                 xtype: 'ColumnModel',
184                                 xns: Roo.grid,
185                                 dataIndex : 'use',
186                                 header : 'Use',
187                                 width : 50,
188                                 renderer : function(v) {  
189                                     var state = v> 0 ?  '-checked' : '';
190                                 
191                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
192                                 }
193                             },
194                             {
195                                 xtype: 'ColumnModel',
196                                 xns: Roo.grid,
197                                 dataIndex : 'use_ex',
198                                 header : 'Display/Expand',
199                                 width : 100,
200                                 renderer : function(v) {  
201                                     var state = v> 0 ?  '-checked' : '';
202                                 
203                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
204                                                 
205                                  }
206                             },
207                             {
208                                 xtype: 'ColumnModel',
209                                 xns: Roo.grid,
210                                 dataIndex : 'table',
211                                 header : 'Table',
212                                 width : 100,
213                                 renderer : function(v) { return String.format('{0}', v); }
214                             },
215                             {
216                                 xtype: 'ColumnModel',
217                                 xns: Roo.grid,
218                                 dataIndex : 'column',
219                                 header : 'Column',
220                                 width : 150,
221                                 renderer : function(v,x,r) { 
222                                     if (r.data.table == _this.data.table) {
223                                     
224                                         return String.format('{0}', v); 
225                                     }
226                                     return String.format('.....{0}', r.data.columnshort); 
227                                 }
228                             },
229                             {
230                                 xtype: 'ColumnModel',
231                                 xns: Roo.grid,
232                                 dataIndex : 'ctype',
233                                 header : 'Type',
234                                 width : 50,
235                                 renderer : function(v) {
236                                 
237                                    return v;
238                                  }
239                             },
240                             {
241                                 xtype: 'ColumnModel',
242                                 xns: Roo.grid,
243                                 dataIndex : 'desc',
244                                 header : 'Description',
245                                 width : 200,
246                                 renderer : function(v) { return String.format('{0}', v); }
247                             }
248                         ]
249                     }
250                 }
251             ],
252             center : {
253                 xtype: 'LayoutRegion',
254                 xns: Roo
255             },
256             buttons : [
257                 {
258                     xtype: 'Button',
259                     xns: Roo,
260                     listeners : {
261                         click : function (_self, e)
262                         {
263                             _this.dialog.hide();
264                         }
265                     },
266                     text : "Cancel"
267                 },
268                 {
269                     xtype: 'Button',
270                     xns: Roo,
271                     listeners : {
272                         click : function (_self, e)
273                         {
274                              var ret = Roo.apply({ cols : [], cols_ex: [] },  _this.data);
275                              
276                              _this.grid.ds.each(function(r) {
277                              
278                                 if (r.data.use*1) {
279                                         ret.cols.push(r.data);
280                                 }
281                                  if (r.data.use_ex*1) {
282                                      ret.cols_ex.push( r.data.column );
283                                  }
284                         
285                              });
286                              
287                              if (!ret.cols_ex.length) {
288                                 Roo.MessageBox.alert("Error", "Select at least one Display/expand col");
289                                 return;
290                             }
291                              Roo.log(ret);
292                              _this.callback(ret);
293                              _this.dialog.hide();
294                         
295                         }
296                     },
297                     text : "Next"
298                 }
299             ]
300         });
301     }
302 };