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