Pman.Tab.AdminCompanies.bjs
[Pman.Admin] / Pman.Tab.AdminEnums.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         modKey : '500-Pman.Tab.AdminEnums',
12         module : Pman.Tab.AdminEnums,
13         region : 'center',
14         parent : Pman.Tab.Admin,
15         name : "Pman.Tab.AdminEnums",
16         disabled : false, 
17         permname: '' 
18     });
19 });
20
21 Pman.Tab.AdminEnums = new Roo.util.Observable({
22
23     panel : false,
24     disabled : false,
25     parentLayout:  false,
26
27     add : function(parentLayout, region)
28     {
29
30         var _this = this;
31         this.parentLayout = parentLayout;
32
33         this.panel = parentLayout.addxtype({
34             xtype: 'GridPanel',
35             xns: Roo,
36             listeners : {
37                 activate : function() {
38                     _this.panel = this;
39                     if (_this.grid) {
40                         _this.grid.footer.onClick('first');
41                     }
42                 }
43             },
44             background : true,
45             fitContainer : true,
46             fitToframe : true,
47             region : 'center',
48             tableName : 'core_enum',
49             title : "Enum options",
50             grid : {
51                 xtype: 'EditorGrid',
52                 xns: Roo.grid,
53                 listeners : {
54                     render : function() 
55                     {
56                         _this.grid = this; 
57                         //_this.dialog = Pman.Dialog.FILL_IN
58                         if (_this.panel.active) {
59                            this.footer.onClick('first');
60                         }
61                     },
62                     afteredit : function (e)
63                     {
64                        e.record.commit();     
65                     },
66                     cellclick : function (_self, rowIndex, columnIndex, e)
67                     {
68                     
69                             var di = this.colModel.getDataIndex(columnIndex);
70                             if (di != 'active') {
71                                 return;
72                             }
73                              
74                             var rec = _this.grid.ds.getAt(rowIndex);
75                             
76                             rec.set('active', rec.data.active ? 0 : 1);
77                             rec.commit();
78                              
79                             
80                     }
81                 },
82                 autoExpandColumn : 'name',
83                 clicksToEdit : 1,
84                 loadMask : true,
85                 dataSource : {
86                     xtype: 'Store',
87                     xns: Roo.data,
88                     listeners : {
89                         beforeload : function (_self, options)
90                         {
91                             if (!_this.etypeCombo) {
92                                 return false;
93                             }
94                             options.params.etype = _this.etypeCombo.getValue();
95                             if (!options.params.etype.length) {
96                                 return false;
97                             }
98                         },
99                         update : function (_self, record, operation)
100                         {
101                             if (operation != Roo.data.Record.COMMIT) {
102                                 return;
103                             }
104                             // got commit..
105                             new Pman.Request({
106                                 url : baseURL + '/Roo/Core_enum.php',
107                                 method : 'POST',
108                                 params : {
109                                     id : record.data.id,
110                                     etype : _this.etypeCombo.getValue(),
111                                     name : record.data.name,
112                                     active : record.data.active,
113                                     seqid : record.data.seqid
114                                 }, 
115                                 success : function(res) {
116                                     //Roo.log(data);
117                                     // update the ID if it's not set..
118                                     if (record.data.id * 1 < 1) {
119                                         record.set('id', res.data.id);
120                                     }
121                                 }
122                             });
123                             
124                         }
125                     },
126                     remoteSort : true,
127                     sortInfo : { field : 'etype', direction: 'ASC' },
128                     proxy : {
129                         xtype: 'HttpProxy',
130                         xns: Roo.data,
131                         method : 'GET',
132                         url : baseURL + '/Roo/core_enum.php'
133                     },
134                     reader : {
135                         xtype: 'JsonReader',
136                         xns: Roo.data,
137                         totalProperty : 'total',
138                         root : 'data',
139                         id : 'id',
140                         fields : [
141                             {
142                                 'name': 'id',
143                                 'type': 'int'
144                             },
145                             {
146                                 'name': 'etype',
147                                 'type': 'string'
148                             },
149                             {
150                                 'name': 'name',
151                                 'type': 'string'
152                             },
153                             {
154                                 'name': 'active',
155                                 'type': 'int'
156                             },
157                             {
158                                 'name': 'seqid',
159                                 'type': 'int'
160                             }
161                         ]
162                     }
163                 },
164                 footer : {
165                     xtype: 'PagingToolbar',
166                     xns: Roo,
167                     pageSize : 25,
168                     displayInfo : true,
169                     displayMsg : 'Displaying core_enum{0} - {1} of {2}',
170                     emptyMsg : 'No core_enum found'
171                 },
172                 toolbar : {
173                     xtype: 'Toolbar',
174                     xns: Roo,
175                     items : [
176                         {
177                             xtype: 'TextItem',
178                             xns: Roo.Toolbar,
179                             text : "Show:"
180                         },
181                         {
182                             xtype: 'ComboBox',
183                             xns: Roo.form,
184                             listeners : {
185                                 render : function (_self)
186                                 {
187                                     _this.etypeCombo = _self;
188                                 },
189                                 select : function (combo, record, index)
190                                 {
191                                     _this.grid.footer.onClick('first');
192                                 }
193                             },
194                             alwaysQuery : true,
195                             displayField : 'name',
196                             editable : 'false',
197                             emptyText : "Select type",
198                             fieldLabel : 'core_enum',
199                             forceSelection : true,
200                             listWidth : 400,
201                             loadingText : "Searching...",
202                             minChars : 2,
203                             pageSize : 20,
204                             qtip : "Select type",
205                             queryParam : 'query[name]',
206                             selectOnFocus : true,
207                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
208                             triggerAction : 'all',
209                             typeAhead : false,
210                             valueField : 'name',
211                             width : 300,
212                             store : {
213                                 xtype: 'Store',
214                                 xns: Roo.data,
215                                 listeners : {
216                                     beforeload : function (_self, o){
217                                         o.params = o.params || {};
218                                         // set more here
219                                         o.params['query[empty_etype]'] = 1;
220                                     }
221                                 },
222                                 remoteSort : true,
223                                 sortInfo : { direction : 'ASC', field: 'id' },
224                                 proxy : {
225                                     xtype: 'HttpProxy',
226                                     xns: Roo.data,
227                                     method : 'GET',
228                                     url : baseURL + '/Roo/core_enum.php'
229                                 },
230                                 reader : {
231                                     xtype: 'JsonReader',
232                                     xns: Roo.data,
233                                     id : 'id',
234                                     root : 'data',
235                                     totalProperty : 'total',
236                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
237                                 }
238                             }
239                         },
240                         {
241                             xtype: 'Button',
242                             xns: Roo.Toolbar,
243                             listeners : {
244                                 click : function()
245                                 {
246                                     
247                                     // if we do not have a selected type... - what should we show..?
248                                     var et = _this.etypeCombo.getValue()
249                                     var ds = _this.grid.getDataSource();
250                                 
251                                     var add = ds.reader.newRow({ id: 0, name : '', etype: et, active: 0, seqid: 0 });
252                                      var r = ds.data.length;
253                                     ds.insert(r  , add);  
254                                     _this.grid.startEditing(r, 1); // name... 
255                                 }
256                             },
257                             cls : 'x-btn-text-icon',
258                             text : "Add Value",
259                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
260                         },
261                         {
262                             xtype: 'Fill',
263                             xns: Roo.Toolbar
264                         },
265                         {
266                             xtype: 'Button',
267                             xns: Roo.Toolbar,
268                             listeners : {
269                                 click : function()
270                                 {
271                                     
272                                     Roo.MessageBox.prompt ("Create a new Enum type",
273                                         "Enter the name for a new enum type, " + 
274                                         "this is only relivant if you  know how it is going to be used",
275                                         function(btn,txt) {
276                                             if (btn != 'ok') {
277                                                 return; 
278                                             }
279                                             new Pman.Request({
280                                                 url : baseURL + '/Roo/Core_enum.php',
281                                                 method : 'POST',
282                                                 params : {
283                                                     etype : '',
284                                                     name : txt,
285                                                     active : 1
286                                                 }, 
287                                                 success : function() {
288                                                     Roo.MessageBox.alert("Created", "You can now select it from the type list on the left");
289                                                 }
290                                             });
291                                                     
292                                             
293                                              
294                                              
295                                         }
296                                     ); 
297                                          
298                                          
299                                 
300                                 }
301                             },
302                             cls : 'x-btn-text-icon',
303                             text : "Add new type",
304                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
305                         }
306                     ]
307                 },
308                 colModel : [
309                     {
310                         xtype: 'ColumnModel',
311                         xns: Roo.grid,
312                         header : 'Id',
313                         width : 75,
314                         dataIndex : 'id',
315                         renderer : function(v) { return String.format('{0}', v); }
316                     },
317                     {
318                         xtype: 'ColumnModel',
319                         xns: Roo.grid,
320                         header : 'Name',
321                         width : 200,
322                         dataIndex : 'name',
323                         renderer : function(v) { return String.format('{0}', v); },
324                         editor : {
325                             xtype: 'GridEditor',
326                             xns: Roo.grid,
327                             field : {
328                                 xtype: 'TextField',
329                                 xns: Roo.form
330                             }
331                         }
332                     },
333                     {
334                         xtype: 'ColumnModel',
335                         xns: Roo.grid,
336                         dataIndex : 'active',
337                         header : 'Active',
338                         width : 75,
339                         renderer : function(v) {  
340                             var state = v> 0 ?  '-checked' : '';
341                         
342                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
343                                         
344                          }
345                     },
346                     {
347                         xtype: 'ColumnModel',
348                         xns: Roo.grid,
349                         dataIndex : 'seqid',
350                         header : 'Seqid',
351                         width : 75,
352                         renderer : function(v) { return String.format('{0}', v); },
353                         sortable : true,
354                         editor : {
355                             xtype: 'GridEditor',
356                             xns: Roo.grid,
357                             field : {
358                                 xtype: 'NumberField',
359                                 xns: Roo.form,
360                                 allowDecimals : false,
361                                 allowNegative : true,
362                                 decimalPrecision : 0
363                             }
364                         }
365                     }
366                 ]
367             }
368         });
369         this.layout = this.panel.layout;
370
371     }
372 });