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