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