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