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