php7 fixes
[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 : 900,
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: 'EditorGrid',
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                         clicksToEdit : 1,
91                         loadMask : true,
92                         dataSource : {
93                             xtype: 'Store',
94                             xns: Roo.data,
95                             listeners : {
96                                 beforeload : function (_self, options)
97                                 {
98                                     if (typeof(_this.data) == 'undefined') {
99                                         return false;
100                                     
101                                     }
102                                     options.params = options.params || {};
103                                     options.params.table = _this.data.table;
104                                 },
105                                 load : function (_self, records, options)
106                                 {
107                                     // after load, if we have configuration already, overlay that 
108                                     if (typeof(_this.data.cols) == 'undefined') {
109                                         return;
110                                     }
111                                     _this.data.cols_ex = _this.data.cols_ex || [];
112                                     var cmap = {}
113                                     Roo.each(_this.data.cols, function (col) {
114                                         cmap[col.column] = col;
115                                     
116                                     });
117                                     Roo.each(records, function (col) {
118                                         col.set('use_ex', _this.data.cols_ex.indexOf(col.data.column) > -1 ? 1 : 0);
119                                 
120                                         if (typeof(cmap[col.data.column]) != 'undefined') {
121                                 
122                                             col.set('title',  typeof(cmap[col.data.column].title) == 'undefined' ? '' : cmap[col.data.column].title);
123                                             col.set('use', 1);
124                                         }
125                                         if (!col.data.title.length) {
126                                         
127                                             if (col.data.columnshort.substring(0, col.data.table.length) == col.data.table) {
128                                                 // it's prefixed with table name..
129                                                 col.set('title', col.data.columnshort.substring(col.data.table.length+1));
130                                             } else {
131                                                 col.set('title', col.data.columnshort);
132                                             }
133                                         } 
134                                        
135                                 
136                                         // what about descption..
137                                     });
138                                       
139                                         
140                                         
141                                 }
142                             },
143                             remoteSort : true,
144                             sortInfo : { field : 'filename', direction: 'ASC' },
145                             proxy : {
146                                 xtype: 'HttpProxy',
147                                 xns: Roo.data,
148                                 method : 'GET',
149                                 url : baseURL + '/Builder/ERM.php'
150                             },
151                             reader : {
152                                 xtype: 'JsonReader',
153                                 xns: Roo.data,
154                                 id : 'id',
155                                 root : 'data',
156                                 totalProperty : 'total',
157                                 fields : [
158                                     { name: 'use', type: 'int'} , 
159                                     { name: 'use_ex', type: 'int'}, 
160                                     'table', 'column', 'ctype', 'desc', 'columnshort', 'title'
161                                 ]
162                             }
163                         },
164                         toolbar : {
165                             xtype: 'Toolbar',
166                             xns: Roo,
167                             items : [
168                                 {
169                                     xtype: 'Button',
170                                     xns: Roo.Toolbar,
171                                     listeners : {
172                                         click : function()
173                                         {
174                                             
175                                         }
176                                     },
177                                     cls : 'x-btn-text-icon',
178                                     text : "Add",
179                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
180                                 },
181                                 {
182                                     xtype: 'Button',
183                                     xns: Roo.Toolbar,
184                                     listeners : {
185                                         click : function()
186                                         {
187                                             // Pman.genericDelete(_this, 'Images'); 
188                                         }
189                                     },
190                                     cls : 'x-btn-text-icon',
191                                     text : "Delete",
192                                     icon : rootURL + '/Pman/templates/images/trash.gif'
193                                 }
194                             ]
195                         },
196                         colModel : [
197                             {
198                                 xtype: 'ColumnModel',
199                                 xns: Roo.grid,
200                                 dataIndex : 'use',
201                                 header : 'Use',
202                                 width : 50,
203                                 renderer : function(v) {  
204                                     var state = v> 0 ?  '-checked' : '';
205                                 
206                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
207                                 }
208                             },
209                             {
210                                 xtype: 'ColumnModel',
211                                 xns: Roo.grid,
212                                 dataIndex : 'use_ex',
213                                 header : 'Display/Expand',
214                                 width : 100,
215                                 renderer : function(v) {  
216                                     var state = v> 0 ?  '-checked' : '';
217                                 
218                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
219                                                 
220                                  }
221                             },
222                             {
223                                 xtype: 'ColumnModel',
224                                 xns: Roo.grid,
225                                 dataIndex : 'column',
226                                 header : 'Column',
227                                 width : 150,
228                                 renderer : function(v,x,r) { 
229                                     if (r.data.table == _this.data.table) {
230                                     
231                                         return String.format('<B>{0}</B>', v); 
232                                     }
233                                     return String.format('{0}...{1}', r.data.table, r.data.columnshort); 
234                                 }
235                             },
236                             {
237                                 xtype: 'ColumnModel',
238                                 xns: Roo.grid,
239                                 dataIndex : 'title',
240                                 header : 'Title',
241                                 width : 150,
242                                 renderer : function(v,x,r) { 
243                                      
244                                     var u = r.data.use * 1;
245                                      u += (r.data.use_ex*1);
246                                     
247                                     return String.format('{0}', u ? v : ''); 
248                                 },
249                                 editor : {
250                                     xtype: 'GridEditor',
251                                     xns: Roo.grid,
252                                     field : {
253                                         xtype: 'TextField',
254                                         xns: Roo.form
255                                     }
256                                 }
257                             },
258                             {
259                                 xtype: 'ColumnModel',
260                                 xns: Roo.grid,
261                                 dataIndex : 'ctype',
262                                 header : 'Type',
263                                 width : 50,
264                                 renderer : function(v) {
265                                 
266                                    return v;
267                                  }
268                             },
269                             {
270                                 xtype: 'ColumnModel',
271                                 xns: Roo.grid,
272                                 dataIndex : 'desc',
273                                 header : 'Description',
274                                 width : 200,
275                                 renderer : function(v) { return String.format('{0}', v); }
276                             }
277                         ]
278                     }
279                 }
280             ],
281             center : {
282                 xtype: 'LayoutRegion',
283                 xns: Roo
284             },
285             buttons : [
286                 {
287                     xtype: 'Button',
288                     xns: Roo,
289                     listeners : {
290                         click : function (_self, e)
291                         {
292                             _this.dialog.hide();
293                         }
294                     },
295                     text : "Cancel"
296                 },
297                 {
298                     xtype: 'Button',
299                     xns: Roo,
300                     listeners : {
301                         click : function (_self, e)
302                         {
303                              var ret = Roo.applyIf({ cols : [], cols_ex: [] },  _this.data);
304                               
305                              _this.grid.ds.each(function(r) {
306                              
307                                 if (r.data.use*1) {
308                                 
309                                     var d = Roo.apply({}, r.json);
310                                     Roo.apply(d, r.data);
311                                     ret.cols.push(d);
312                                         
313                                 }
314                                  if (r.data.use_ex*1) {
315                                      ret.cols_ex.push( r.data.column );
316                                  }
317                         
318                              });
319                              
320                              if (!ret.cols_ex.length) {
321                                 Roo.MessageBox.alert("Error", "Select at least one Display/expand col");
322                                 return;
323                             }
324                              Roo.log(ret);
325                         
326                             _this.dialog.hide();
327                              _this.callback(ret);
328                              
329                         
330                         }
331                     },
332                     text : "Next"
333                 }
334             ]
335         });
336     }
337 };