Pman.Dialog.AdminCoreEnum.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 Pman.Tab.AdminEnums = new Roo.XComponent({
6     part     :  ["Admin","Enums"],
7     order    : '500-Pman.Tab.AdminEnums',
8     region   : 'center',
9     parent   : 'Pman.Tab.Admin',
10     name     : "Pman.Tab.AdminEnums",
11     disabled : false, 
12     permname : 'Admin.Enums', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             background : true,
29             fitContainer : true,
30             fitToframe : true,
31             region : 'center',
32             tableName : 'core_enum',
33             title : "Pulldown Options",
34             grid : {
35                 xtype: 'EditorGrid',
36                 xns: Roo.grid,
37                 listeners : {
38                     render : function() 
39                     {
40                         _this.grid = this; 
41                         //_this.dialog = Pman.Dialog.FILL_IN
42                         if (_this.panel.active) {
43                            this.footer.onClick('first');
44                         }
45                     },
46                     afteredit : function (e)
47                     {
48                        e.record.commit();     
49                     },
50                     cellclick : function (_self, rowIndex, columnIndex, e)
51                     {
52                     
53                             var di = this.colModel.getDataIndex(columnIndex);
54                             if (di != 'active') {
55                                 return;
56                             }
57                              
58                             var rec = _this.grid.ds.getAt(rowIndex);
59                             
60                             rec.set('active', rec.data.active ? 0 : 1);
61                             rec.commit();
62                              
63                             
64                     },
65                     beforeedit : function (e)
66                     {
67                         if(e.field == 'name' && e.record.data.is_system_enum*1 == 1){
68                             return false;
69                         }
70                     }
71                 },
72                 autoExpandColumn : 'display_name',
73                 clicksToEdit : 1,
74                 loadMask : true,
75                 dataSource : {
76                     xtype: 'Store',
77                     xns: Roo.data,
78                     listeners : {
79                         beforeload : function (_self, options)
80                         {
81                             if (!_this.etypeCombo) {
82                                 return false;
83                             }
84                             options.params.etype = _this.etypeCombo.getValue();
85                             if (!options.params.etype.length) {
86                                 return false;
87                             }
88                         },
89                         update : function (_self, record, operation)
90                         {
91                             if (operation != Roo.data.Record.COMMIT) {
92                                 return;
93                             }
94                             // got commit..
95                             new Pman.Request({
96                                 url : baseURL + '/Roo/Core_enum.php',
97                                 method : 'POST',
98                                 params : {
99                                     id : record.data.id,
100                                     etype : _this.etypeCombo.getValue(),
101                                     name : record.data.name,
102                                     active : record.data.active,
103                                     seqid : record.data.seqid,
104                                     display_name : record.data.display_name
105                                 }, 
106                                 success : function(res) {
107                                     //Roo.log(data);
108                                     // update the ID if it's not set..
109                                     if (record.data.id * 1 < 1) {
110                                         record.set('id', res.data.id);
111                                     }
112                                 }
113                             });
114                             
115                         }
116                     },
117                     remoteSort : true,
118                     sortInfo : { field : 'etype', direction: 'ASC' },
119                     proxy : {
120                         xtype: 'HttpProxy',
121                         xns: Roo.data,
122                         method : 'GET',
123                         url : baseURL + '/Roo/core_enum.php'
124                     },
125                     reader : {
126                         xtype: 'JsonReader',
127                         xns: Roo.data,
128                         totalProperty : 'total',
129                         root : 'data',
130                         id : 'id',
131                         fields : [
132                             {
133                                 'name': 'id',
134                                 'type': 'int'
135                             },
136                             {
137                                 'name': 'etype',
138                                 'type': 'string'
139                             },
140                             {
141                                 'name': 'name',
142                                 'type': 'string'
143                             },
144                             {
145                                 'name': 'active',
146                                 'type': 'int'
147                             },
148                             {
149                                 'name': 'seqid',
150                                 'type': 'int'
151                             }
152                         ]
153                     }
154                 },
155                 footer : {
156                     xtype: 'PagingToolbar',
157                     xns: Roo,
158                     pageSize : 25,
159                     displayInfo : true,
160                     displayMsg : "Displaying core_enum{0} - {1} of {2}",
161                     emptyMsg : "No core_enum found",
162                     items : [
163                         {
164                             xtype: 'Button',
165                             xns: Roo.Toolbar,
166                             listeners : {
167                                 click : function (_self, e)
168                                 {
169                                     new Pman.Download({
170                                         grid : _this.grid
171                                     });
172                                     Roo.MessageBox.alert("Downloading", "File is downloading");
173                                 }
174                             },
175                             text : "Download"
176                         },
177                         {
178                             xtype: 'Button',
179                             xns: Roo.Toolbar,
180                             listeners : {
181                                 click : function (_self, e)
182                                 {
183                                     var etype = _this.etypeCombo.getValue();
184                                     
185                                     if(!etype.length){
186                                         Roo.MessageBox.alert('Error', 'Please select a pulldown');
187                                         return;
188                                     }
189                                     
190                                     Pman.Dialog.Image.show(
191                                        {
192                                             _url : baseURL+'/Xtuple/Import/Enum?' + Roo.urlEncode({'etype' : etype})
193                                         
194                                        },
195                                        function () {
196                                             _this.grid.footer.onClick('first');
197                                        }
198                                    );
199                                 }
200                             },
201                             text : "Upload Value"
202                         }
203                     ]
204                 },
205                 toolbar : {
206                     xtype: 'Toolbar',
207                     xns: Roo,
208                     items : [
209                         {
210                             xtype: 'TextItem',
211                             xns: Roo.Toolbar,
212                             text : "Pulldown Name:"
213                         },
214                         {
215                             xtype: 'ComboBox',
216                             xns: Roo.form,
217                             listeners : {
218                                 render : function (_self)
219                                 {
220                                     _this.etypeCombo = _self;
221                                 },
222                                 select : function (combo, record, index)
223                                 {
224                                     _this.grid.footer.onClick('first');
225                                 }
226                             },
227                             alwaysQuery : true,
228                             displayField : 'name',
229                             editable : 'false',
230                             emptyText : "Select pulldown",
231                             fieldLabel : 'core_enum',
232                             forceSelection : true,
233                             listWidth : 400,
234                             loadingText : "Searching...",
235                             minChars : 2,
236                             pageSize : 50,
237                             qtip : "Select type",
238                             queryParam : 'query[name]',
239                             selectOnFocus : true,
240                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{display_name}</b> - {name} </div>',
241                             triggerAction : 'all',
242                             typeAhead : false,
243                             valueField : 'name',
244                             width : 300,
245                             store : {
246                                 xtype: 'Store',
247                                 xns: Roo.data,
248                                 listeners : {
249                                     beforeload : function (_self, o){
250                                         o.params = o.params || {};
251                                         // set more here
252                                         o.params['query[empty_etype]'] = 1; 
253                                     }
254                                 },
255                                 remoteSort : true,
256                                 sortInfo : { direction : 'ASC', field: 'display_name' },
257                                 proxy : {
258                                     xtype: 'HttpProxy',
259                                     xns: Roo.data,
260                                     method : 'GET',
261                                     url : baseURL + '/Roo/core_enum.php'
262                                 },
263                                 reader : {
264                                     xtype: 'JsonReader',
265                                     xns: Roo.data,
266                                     id : 'id',
267                                     root : 'data',
268                                     totalProperty : 'total',
269                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
270                                 }
271                             }
272                         },
273                         {
274                             xtype: 'Button',
275                             xns: Roo.Toolbar,
276                             listeners : {
277                                 click : function()
278                                 {
279                                     
280                                     // if we do not have a selected type... - what should we show..?
281                                     var et = _this.etypeCombo.getValue();
282                                     var ds = _this.grid.getDataSource();
283                                     if (!et) {
284                                         Roo.MessageBox.alert("Error", "Select a pulldown");
285                                         return;
286                                     }
287                                 
288                                     var add = ds.reader.newRow({    
289                                              id: 0, 
290                                              display_name : '', 
291                                              name : '', 
292                                              etype: et, 
293                                              active: 1, 
294                                              seqid: 0
295                                       });
296                                      var r = ds.data.length;
297                                     ds.insert(r  , add);  
298                                     _this.grid.startEditing(r, 1); // name... 
299                                 }
300                             },
301                             cls : 'x-btn-text-icon',
302                             text : "Add Value",
303                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
304                         },
305                         {
306                             xtype: 'Button',
307                             xns: Roo.Toolbar,
308                             listeners : {
309                                 click : function()
310                                 {
311                                     
312                                     // if we do not have a selected type... - what should we show..?
313                                     var et = _this.etypeCombo.getValue();
314                                     
315                                     if (!et) {
316                                         Roo.MessageBox.alert("Error", "Select a pulldown");
317                                         return;
318                                     }
319                                     var sc = _this.grid.getSelectionModel().getSelectedCell();
320                                     Roo.log(sc);
321                                     var ds = _this.grid.ds.getAt(sc[0]);
322                                     if (!ds) {
323                                         Roo.MessageBox.alert("Error", "Select enum");
324                                         return;
325                                     }
326                                     
327                                     Roo.log(ds);
328                                     Pman.Dialog.AdminEnumImages.show({onid:ds.data.id}, function(){
329                                         _this.grid.footer.onClick('first');
330                                     });
331                                     
332                                 }
333                             },
334                             cls : 'x-btn-text-icon',
335                             text : "Add Images",
336                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
337                         },
338                         {
339                             xtype: 'Fill',
340                             xns: Roo.Toolbar
341                         },
342                         {
343                             xtype: 'Button',
344                             xns: Roo.Toolbar,
345                             listeners : {
346                                 click : function()
347                                 {
348                                     
349                                     Roo.MessageBox.prompt ("Create a new Enum type",
350                                         "Enter the name for a new enum type, " + 
351                                         "this is only relivant if you  know how it is going to be used",
352                                         function(btn,txt) {
353                                             if (btn != 'ok') {
354                                                 return; 
355                                             }
356                                             new Pman.Request({
357                                                 url : baseURL + '/Roo/Core_enum.php',
358                                                 method : 'POST',
359                                                 params : {
360                                                     etype : '',
361                                                     name : txt,
362                                                     active : 1
363                                                 }, 
364                                                 success : function() {
365                                                     Roo.MessageBox.alert("Created", "You can now select it from the type list on the left");
366                                                 }
367                                             });
368                                                     
369                                             
370                                              
371                                              
372                                         }
373                                     ); 
374                                          
375                                          
376                                 
377                                 }
378                             },
379                             cls : 'x-btn-text-icon',
380                             text : "Add new pulldown list",
381                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
382                         }
383                     ]
384                 },
385                 colModel : [
386                     {
387                         xtype: 'ColumnModel',
388                         xns: Roo.grid,
389                         dataIndex : 'id',
390                         header : 'Internal #',
391                         width : 75,
392                         renderer : function(v) { return String.format('{0}', v); }
393                     },
394                     {
395                         xtype: 'ColumnModel',
396                         xns: Roo.grid,
397                         dataIndex : 'images_id_id',
398                         header : 'Image',
399                         width : 75,
400                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/25/{1}/{2}" width="25" height="25">', baseURL, v, r.data.images_id_filename); }
401                     },
402                     {
403                         xtype: 'ColumnModel',
404                         xns: Roo.grid,
405                         header : 'Name',
406                         width : 200,
407                         dataIndex : 'name',
408                         renderer : function(v) { return String.format('{0}', v); },
409                         editor : {
410                             xtype: 'GridEditor',
411                             xns: Roo.grid,
412                             field : {
413                                 xtype: 'TextField',
414                                 xns: Roo.form
415                             }
416                         }
417                     },
418                     {
419                         xtype: 'ColumnModel',
420                         xns: Roo.grid,
421                         dataIndex : 'display_name',
422                         header : 'Display Name',
423                         width : 200,
424                         renderer : function(v) { return String.format('{0}', v); },
425                         editor : {
426                             xtype: 'GridEditor',
427                             xns: Roo.grid,
428                             field : {
429                                 xtype: 'TextField',
430                                 xns: Roo.form
431                             }
432                         }
433                     },
434                     {
435                         xtype: 'ColumnModel',
436                         xns: Roo.grid,
437                         dataIndex : 'active',
438                         header : 'Active',
439                         width : 75,
440                         renderer : function(v) {  
441                             var state = v> 0 ?  '-checked' : '';
442                         
443                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
444                                         
445                          }
446                     },
447                     {
448                         xtype: 'ColumnModel',
449                         xns: Roo.grid,
450                         dataIndex : 'seqid',
451                         header : 'Order #',
452                         sortable : true,
453                         width : 75,
454                         renderer : function(v) { return String.format('{0}', v); },
455                         editor : {
456                             xtype: 'GridEditor',
457                             xns: Roo.grid,
458                             field : {
459                                 xtype: 'NumberField',
460                                 xns: Roo.form,
461                                 allowDecimals : false,
462                                 allowNegative : true,
463                                 decimalPrecision : 0
464                             }
465                         }
466                     }
467                 ]
468             }
469         };
470     }
471 });