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