Pman.Dialog.AdminCoreEnum.bjs
[Pman.Admin] / Pman.Tab.AdminEnums.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.Tab.AdminEnums = new Roo.XComponent({
6     part     :  ["Admin","Enums"],
7     order    : '500-Pman.Tab.AdminEnums',
8     region   : 'center',
9     parent   : 'Pman.Tab.Admin',
10     name     : "Pman.Tab.AdminEnums",
11     disabled : false, 
12     permname : 'Admin.Enums', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             background : true,
29             fitContainer : true,
30             fitToframe : true,
31             region : 'center',
32             tableName : 'core_enum',
33             title : "Pulldown Options",
34             grid : {
35                 xtype: 'EditorGrid',
36                 xns: Roo.grid,
37                 listeners : {
38                     render : function() 
39                     {
40                         _this.grid = this; 
41                         //_this.dialog = Pman.Dialog.FILL_IN
42                         if (_this.panel.active) {
43                            this.footer.onClick('first');
44                         }
45                     },
46                     afteredit : function (e)
47                     {
48                        e.record.commit();     
49                     },
50                     cellclick : function (_self, rowIndex, columnIndex, e)
51                     {
52                     
53                             var di = this.colModel.getDataIndex(columnIndex);
54                             if (di != 'active') {
55                                 return;
56                             }
57                              
58                             var rec = _this.grid.ds.getAt(rowIndex);
59                             
60                             rec.set('active', rec.data.active ? 0 : 1);
61                             rec.commit();
62                              
63                             
64                     },
65                     beforeedit : function (e)
66                     {
67                         if(e.field == 'name' && e.record.data.is_system_enum*1 == 1){
68                             return false;
69                         }
70                     }
71                 },
72                 autoExpandColumn : 'display_name',
73                 clicksToEdit : 1,
74                 loadMask : true,
75                 dataSource : {
76                     xtype: 'Store',
77                     xns: Roo.data,
78                     listeners : {
79                         beforeload : function (_self, options)
80                         {
81                             if (!_this.etypeCombo) {
82                                 return false;
83                             }
84                             options.params.etype = _this.etypeCombo.getValue();
85                             if (!options.params.etype.length) {
86                                 return false;
87                             }
88                         },
89                         update : function (_self, record, operation)
90                         {
91                             if (operation != Roo.data.Record.COMMIT) {
92                                 return;
93                             }
94                             // got commit..
95                             new Pman.Request({
96                                 url : baseURL + '/Roo/Core_enum.php',
97                                 method : 'POST',
98                                 params : {
99                                     id : record.data.id,
100                                     etype : _this.etypeCombo.getValue(),
101                                     name : record.data.name,
102                                     active : record.data.active,
103                                     seqid : record.data.seqid,
104                                     display_name : record.data.display_name
105                                 }, 
106                                 success : function(res) {
107                                     //Roo.log(data);
108                                     // update the ID if it's not set..
109                                     if (record.data.id * 1 < 1) {
110                                         record.set('id', res.data.id);
111                                     }
112                                 }
113                             });
114                             
115                         }
116                     },
117                     remoteSort : true,
118                     sortInfo : { field : 'etype', direction: 'ASC' },
119                     proxy : {
120                         xtype: 'HttpProxy',
121                         xns: Roo.data,
122                         method : 'GET',
123                         url : baseURL + '/Roo/core_enum.php'
124                     },
125                     reader : {
126                         xtype: 'JsonReader',
127                         xns: Roo.data,
128                         totalProperty : 'total',
129                         root : 'data',
130                         id : 'id',
131                         fields : [
132                             {
133                                 'name': 'id',
134                                 'type': 'int'
135                             },
136                             {
137                                 'name': 'etype',
138                                 'type': 'string'
139                             },
140                             {
141                                 'name': 'name',
142                                 'type': 'string'
143                             },
144                             {
145                                 'name': 'active',
146                                 'type': 'int'
147                             },
148                             {
149                                 'name': 'seqid',
150                                 'type': 'int'
151                             }
152                         ]
153                     }
154                 },
155                 footer : {
156                     xtype: 'PagingToolbar',
157                     xns: Roo,
158                     pageSize : 25,
159                     displayInfo : true,
160                     displayMsg : "Displaying core_enum{0} - {1} of {2}",
161                     emptyMsg : "No core_enum found",
162                     items : [
163                         {
164                             xtype: 'Button',
165                             xns: Roo.Toolbar,
166                             listeners : {
167                                 click : function (_self, e)
168                                 {
169                                     new Pman.Download({
170                                         grid : _this.grid
171                                     });
172                                     Roo.MessageBox.alert("Downloading", "File is downloading");
173                                 }
174                             },
175                             text : "Download"
176                         }
177                     ]
178                 },
179                 toolbar : {
180                     xtype: 'Toolbar',
181                     xns: Roo,
182                     items : [
183                         {
184                             xtype: 'TextItem',
185                             xns: Roo.Toolbar,
186                             text : "Pulldown Name:"
187                         },
188                         {
189                             xtype: 'ComboBox',
190                             xns: Roo.form,
191                             listeners : {
192                                 render : function (_self)
193                                 {
194                                     _this.etypeCombo = _self;
195                                 },
196                                 select : function (combo, record, index)
197                                 {
198                                     _this.grid.footer.onClick('first');
199                                 }
200                             },
201                             alwaysQuery : true,
202                             displayField : 'name',
203                             editable : 'false',
204                             emptyText : "Select pulldown",
205                             fieldLabel : 'core_enum',
206                             forceSelection : true,
207                             listWidth : 400,
208                             loadingText : "Searching...",
209                             minChars : 2,
210                             pageSize : 50,
211                             qtip : "Select type",
212                             queryParam : 'query[name]',
213                             selectOnFocus : true,
214                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{display_name}</b> - {name} </div>',
215                             triggerAction : 'all',
216                             typeAhead : false,
217                             valueField : 'name',
218                             width : 300,
219                             store : {
220                                 xtype: 'Store',
221                                 xns: Roo.data,
222                                 listeners : {
223                                     beforeload : function (_self, o){
224                                         o.params = o.params || {};
225                                         // set more here
226                                         o.params['query[empty_etype]'] = 1; 
227                                     }
228                                 },
229                                 remoteSort : true,
230                                 sortInfo : { direction : 'ASC', field: 'display_name' },
231                                 proxy : {
232                                     xtype: 'HttpProxy',
233                                     xns: Roo.data,
234                                     method : 'GET',
235                                     url : baseURL + '/Roo/core_enum.php'
236                                 },
237                                 reader : {
238                                     xtype: 'JsonReader',
239                                     xns: Roo.data,
240                                     id : 'id',
241                                     root : 'data',
242                                     totalProperty : 'total',
243                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
244                                 }
245                             }
246                         },
247                         {
248                             xtype: 'Button',
249                             xns: Roo.Toolbar,
250                             listeners : {
251                                 click : function()
252                                 {
253                                     
254                                     // if we do not have a selected type... - what should we show..?
255                                     var et = _this.etypeCombo.getValue();
256                                     var ds = _this.grid.getDataSource();
257                                     if (!et) {
258                                         Roo.MessageBox.alert("Error", "Select a pulldown");
259                                         return;
260                                     }
261                                 
262                                     var add = ds.reader.newRow({    
263                                              id: 0, 
264                                              display_name : '', 
265                                              name : '', 
266                                              etype: et, 
267                                              active: 1, 
268                                              seqid: 0
269                                       });
270                                      var r = ds.data.length;
271                                     ds.insert(r  , add);  
272                                     _this.grid.startEditing(r, 1); // name... 
273                                 }
274                             },
275                             cls : 'x-btn-text-icon',
276                             text : "Add Value",
277                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
278                         },
279                         {
280                             xtype: 'Button',
281                             xns: Roo.Toolbar,
282                             listeners : {
283                                 click : function()
284                                 {
285                                     
286                                     // if we do not have a selected type... - what should we show..?
287                                     var et = _this.etypeCombo.getValue();
288                                     
289                                     if (!et) {
290                                         Roo.MessageBox.alert("Error", "Select a pulldown");
291                                         return;
292                                     }
293                                     var sc = _this.grid.getSelectionModel().getSelectedCell();
294                                     Roo.log(sc);
295                                     var ds = _this.grid.ds.getAt(sc[0]);
296                                     if (!ds) {
297                                         Roo.MessageBox.alert("Error", "Select enum");
298                                         return;
299                                     }
300                                     
301                                     Roo.log(ds);
302                                     Pman.Dialog.AdminEnumImages.show({onid:ds.data.id}, function(){
303                                         _this.grid.footer.onClick('first');
304                                     });
305                                     
306                                 }
307                             },
308                             cls : 'x-btn-text-icon',
309                             text : "Add Images",
310                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
311                         },
312                         {
313                             xtype: 'Fill',
314                             xns: Roo.Toolbar
315                         },
316                         {
317                             xtype: 'Button',
318                             xns: Roo.Toolbar,
319                             listeners : {
320                                 click : function()
321                                 {
322                                     
323                                     Roo.MessageBox.prompt ("Create a new Enum type",
324                                         "Enter the name for a new enum type, " + 
325                                         "this is only relivant if you  know how it is going to be used",
326                                         function(btn,txt) {
327                                             if (btn != 'ok') {
328                                                 return; 
329                                             }
330                                             new Pman.Request({
331                                                 url : baseURL + '/Roo/Core_enum.php',
332                                                 method : 'POST',
333                                                 params : {
334                                                     etype : '',
335                                                     name : txt,
336                                                     active : 1
337                                                 }, 
338                                                 success : function() {
339                                                     Roo.MessageBox.alert("Created", "You can now select it from the type list on the left");
340                                                 }
341                                             });
342                                                     
343                                             
344                                              
345                                              
346                                         }
347                                     ); 
348                                          
349                                          
350                                 
351                                 }
352                             },
353                             cls : 'x-btn-text-icon',
354                             text : "Add new pulldown list",
355                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
356                         }
357                     ]
358                 },
359                 colModel : [
360                     {
361                         xtype: 'ColumnModel',
362                         xns: Roo.grid,
363                         dataIndex : 'id',
364                         header : 'Internal #',
365                         width : 75,
366                         renderer : function(v) { return String.format('{0}', v); }
367                     },
368                     {
369                         xtype: 'ColumnModel',
370                         xns: Roo.grid,
371                         dataIndex : 'images_id_id',
372                         header : 'Image',
373                         width : 75,
374                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/25/{1}/{2}" width="25" height="25">', baseURL, v, r.data.images_id_filename); }
375                     },
376                     {
377                         xtype: 'ColumnModel',
378                         xns: Roo.grid,
379                         header : 'Name',
380                         width : 200,
381                         dataIndex : 'name',
382                         renderer : function(v) { return String.format('{0}', v); },
383                         editor : {
384                             xtype: 'GridEditor',
385                             xns: Roo.grid,
386                             field : {
387                                 xtype: 'TextField',
388                                 xns: Roo.form
389                             }
390                         }
391                     },
392                     {
393                         xtype: 'ColumnModel',
394                         xns: Roo.grid,
395                         dataIndex : 'display_name',
396                         header : 'Display Name',
397                         width : 200,
398                         renderer : function(v) { return String.format('{0}', v); },
399                         editor : {
400                             xtype: 'GridEditor',
401                             xns: Roo.grid,
402                             field : {
403                                 xtype: 'TextField',
404                                 xns: Roo.form
405                             }
406                         }
407                     },
408                     {
409                         xtype: 'ColumnModel',
410                         xns: Roo.grid,
411                         dataIndex : 'active',
412                         header : 'Active',
413                         width : 75,
414                         renderer : function(v) {  
415                             var state = v> 0 ?  '-checked' : '';
416                         
417                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
418                                         
419                          }
420                     },
421                     {
422                         xtype: 'ColumnModel',
423                         xns: Roo.grid,
424                         dataIndex : 'seqid',
425                         header : 'Order #',
426                         sortable : true,
427                         width : 75,
428                         renderer : function(v) { return String.format('{0}', v); },
429                         editor : {
430                             xtype: 'GridEditor',
431                             xns: Roo.grid,
432                             field : {
433                                 xtype: 'NumberField',
434                                 xns: Roo.form,
435                                 allowDecimals : false,
436                                 allowNegative : true,
437                                 decimalPrecision : 0
438                             }
439                         }
440                     }
441                 ]
442             }
443         };
444     }
445 });