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                                     Roo.log(record);
130                                 
131                                     if (typeof(_this.data._hide_name) != 'undefined') {
132                                         record.set('name', record.data.display_name);
133                                     }
134                                     if (!record.data.name.length) {
135                                         return;
136                                     }
137                                     
138                                     // got commit..
139                                     new Pman.Request({
140                                         url : baseURL + '/Roo/Core_enum.php',
141                                         method : 'POST',
142                                         params : {
143                                             id : record.data.id,
144                                             etype : _this.data.etype,
145                                             name :  record.data.name,
146                                             active : record.data.active,
147                                             seqid : record.data.seqid,
148                                             display_name : record.data.display_name
149                                         }, 
150                                         success : function(res) {
151                                             //Roo.log(data);
152                                             // update the ID if it's not set..
153                                             if (record.data.id * 1 < 1) {
154                                                 record.set('id', res.data.id);
155                                             }
156                                         }
157                                     });
158                                     
159                                 }
160                             },
161                             remoteSort : true,
162                             sortInfo : { field : 'etype', direction: 'ASC' },
163                             proxy : {
164                                 xtype: 'HttpProxy',
165                                 xns: Roo.data,
166                                 method : 'GET',
167                                 url : baseURL + '/Roo/core_enum.php'
168                             },
169                             reader : {
170                                 xtype: 'JsonReader',
171                                 xns: Roo.data,
172                                 totalProperty : 'total',
173                                 root : 'data',
174                                 id : 'id',
175                                 fields : [
176                                     {
177                                         'name': 'id',
178                                         'type': 'int'
179                                     },
180                                     {
181                                         'name': 'etype',
182                                         'type': 'string'
183                                     },
184                                     {
185                                         'name': 'name',
186                                         'type': 'string'
187                                     },
188                                     {
189                                         'name': 'active',
190                                         'type': 'int'
191                                     },
192                                     {
193                                         'name': 'seqid',
194                                         'type': 'int'
195                                     }
196                                 ]
197                             }
198                         },
199                         footer : {
200                             xtype: 'PagingToolbar',
201                             xns: Roo,
202                             pageSize : 25,
203                             displayInfo : true,
204                             displayMsg : "Displaying core_enum{0} - {1} of {2}",
205                             emptyMsg : "No core_enum found"
206                         },
207                         toolbar : {
208                             xtype: 'Toolbar',
209                             xns: Roo,
210                             items : [
211                                 {
212                                     xtype: 'Button',
213                                     xns: Roo.Toolbar,
214                                     listeners : {
215                                         click : function()
216                                         {
217                                             
218                                             // if we do not have a selected type... - what should we show..?
219                                             var et = _this.data.etype;
220                                             var ds = _this.grid.getDataSource();
221                                             if (!et) {
222                                                 Roo.MessageBox.alert("Error", "Select a pulldown");
223                                                 return;
224                                             }
225                                         
226                                             var add = ds.reader.newRow({    
227                                                      id: 0, 
228                                                      display_name : '', 
229                                                      name : '', 
230                                                      etype: et, 
231                                                      active: 1, 
232                                                      seqid: 0
233                                               });
234                                              var r = ds.data.length;
235                                             ds.insert(r  , add);  
236                                             _this.grid.startEditing(r, 1); // name... 
237                                         }
238                                     },
239                                     cls : 'x-btn-text-icon',
240                                     text : "Add Value",
241                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
242                                 },
243                                 {
244                                     xtype: 'Fill',
245                                     xns: Roo.Toolbar
246                                 }
247                             ]
248                         },
249                         colModel : [
250                             {
251                                 xtype: 'ColumnModel',
252                                 xns: Roo.grid,
253                                 dataIndex : 'id',
254                                 header : 'Internal #',
255                                 width : 75,
256                                 renderer : function(v) { return String.format('{0}', v); }
257                             },
258                             {
259                                 xtype: 'ColumnModel',
260                                 xns: Roo.grid,
261                                 header : 'Name',
262                                 width : 200,
263                                 dataIndex : 'name',
264                                 renderer : function(v) { return String.format('{0}', v); },
265                                 editor : {
266                                     xtype: 'GridEditor',
267                                     xns: Roo.grid,
268                                     field : {
269                                         xtype: 'TextField',
270                                         xns: Roo.form
271                                     }
272                                 }
273                             },
274                             {
275                                 xtype: 'ColumnModel',
276                                 xns: Roo.grid,
277                                 dataIndex : 'display_name',
278                                 header : 'Display Name',
279                                 width : 200,
280                                 renderer : function(v) { return String.format('{0}', v); },
281                                 editor : {
282                                     xtype: 'GridEditor',
283                                     xns: Roo.grid,
284                                     field : {
285                                         xtype: 'TextField',
286                                         xns: Roo.form
287                                     }
288                                 }
289                             },
290                             {
291                                 xtype: 'ColumnModel',
292                                 xns: Roo.grid,
293                                 dataIndex : 'active',
294                                 header : 'Active',
295                                 width : 75,
296                                 renderer : function(v) {  
297                                     var state = v> 0 ?  '-checked' : '';
298                                 
299                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
300                                                 
301                                  }
302                             },
303                             {
304                                 xtype: 'ColumnModel',
305                                 xns: Roo.grid,
306                                 dataIndex : 'seqid',
307                                 header : 'Order #',
308                                 sortable : true,
309                                 width : 75,
310                                 renderer : function(v) { return String.format('{0}', v); },
311                                 editor : {
312                                     xtype: 'GridEditor',
313                                     xns: Roo.grid,
314                                     field : {
315                                         xtype: 'NumberField',
316                                         xns: Roo.form,
317                                         allowDecimals : false,
318                                         allowNegative : true,
319                                         decimalPrecision : 0
320                                     }
321                                 }
322                             }
323                         ]
324                     }
325                 }
326             ],
327             center : {
328                 xtype: 'LayoutRegion',
329                 xns: Roo
330             },
331             buttons : [
332                 {
333                     xtype: 'Button',
334                     xns: Roo,
335                     listeners : {
336                         click : function (_self, e)
337                         {
338                           _this.dialog.hide();
339                         }
340                     },
341                     text : "Cancel"
342                 },
343                 {
344                     xtype: 'Button',
345                     xns: Roo,
346                     listeners : {
347                         click : function (_self, e)
348                         {
349                             var sel = _this.grid.selModel.getSelectedCell();
350                             if (!sel && _this.callback) {
351                                 Roo.MessageBox.alert("Error", "Select an item");
352                                 return;
353                             }
354                             
355                         
356                             if (_this.callback) {
357                                 var rec = _this.grid.ds.getAt(sel[0]);
358                                _this.callback(rec.data);
359                            }
360                            _this.dialog.hide();
361                         }
362                     },
363                     text : "OK"
364                 }
365             ]
366         });
367     }
368 };