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