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