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