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