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