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