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