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