Pman.Dialog.AdminEnumImages.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                 },
66                 autoExpandColumn : 'display_name',
67                 clicksToEdit : 1,
68                 loadMask : true,
69                 dataSource : {
70                     xtype: 'Store',
71                     xns: Roo.data,
72                     listeners : {
73                         beforeload : function (_self, options)
74                         {
75                             if (!_this.etypeCombo) {
76                                 return false;
77                             }
78                             options.params.etype = _this.etypeCombo.getValue();
79                             if (!options.params.etype.length) {
80                                 return false;
81                             }
82                         },
83                         update : function (_self, record, operation)
84                         {
85                             if (operation != Roo.data.Record.COMMIT) {
86                                 return;
87                             }
88                             // got commit..
89                             new Pman.Request({
90                                 url : baseURL + '/Roo/Core_enum.php',
91                                 method : 'POST',
92                                 params : {
93                                     id : record.data.id,
94                                     etype : _this.etypeCombo.getValue(),
95                                     name : record.data.name,
96                                     active : record.data.active,
97                                     seqid : record.data.seqid,
98                                     display_name : record.data.display_name
99                                 }, 
100                                 success : function(res) {
101                                     //Roo.log(data);
102                                     // update the ID if it's not set..
103                                     if (record.data.id * 1 < 1) {
104                                         record.set('id', res.data.id);
105                                     }
106                                 }
107                             });
108                             
109                         }
110                     },
111                     remoteSort : true,
112                     sortInfo : { field : 'etype', direction: 'ASC' },
113                     proxy : {
114                         xtype: 'HttpProxy',
115                         xns: Roo.data,
116                         method : 'GET',
117                         url : baseURL + '/Roo/core_enum.php'
118                     },
119                     reader : {
120                         xtype: 'JsonReader',
121                         xns: Roo.data,
122                         totalProperty : 'total',
123                         root : 'data',
124                         id : 'id',
125                         fields : [
126                             {
127                                 'name': 'id',
128                                 'type': 'int'
129                             },
130                             {
131                                 'name': 'etype',
132                                 'type': 'string'
133                             },
134                             {
135                                 'name': 'name',
136                                 'type': 'string'
137                             },
138                             {
139                                 'name': 'active',
140                                 'type': 'int'
141                             },
142                             {
143                                 'name': 'seqid',
144                                 'type': 'int'
145                             }
146                         ]
147                     }
148                 },
149                 footer : {
150                     xtype: 'PagingToolbar',
151                     xns: Roo,
152                     pageSize : 25,
153                     displayInfo : true,
154                     displayMsg : "Displaying core_enum{0} - {1} of {2}",
155                     emptyMsg : "No core_enum found"
156                 },
157                 toolbar : {
158                     xtype: 'Toolbar',
159                     xns: Roo,
160                     items : [
161                         {
162                             xtype: 'TextItem',
163                             xns: Roo.Toolbar,
164                             text : "Pulldown Name:"
165                         },
166                         {
167                             xtype: 'ComboBox',
168                             xns: Roo.form,
169                             listeners : {
170                                 render : function (_self)
171                                 {
172                                     _this.etypeCombo = _self;
173                                 },
174                                 select : function (combo, record, index)
175                                 {
176                                     _this.grid.footer.onClick('first');
177                                 }
178                             },
179                             alwaysQuery : true,
180                             displayField : 'name',
181                             editable : 'false',
182                             emptyText : "Select pulldown",
183                             fieldLabel : 'core_enum',
184                             forceSelection : true,
185                             listWidth : 400,
186                             loadingText : "Searching...",
187                             minChars : 2,
188                             pageSize : 20,
189                             qtip : "Select type",
190                             queryParam : 'query[name]',
191                             selectOnFocus : true,
192                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
193                             triggerAction : 'all',
194                             typeAhead : false,
195                             valueField : 'name',
196                             width : 300,
197                             store : {
198                                 xtype: 'Store',
199                                 xns: Roo.data,
200                                 listeners : {
201                                     beforeload : function (_self, o){
202                                         o.params = o.params || {};
203                                         // set more here
204                                         o.params['query[empty_etype]'] = 1; 
205                                     }
206                                 },
207                                 remoteSort : true,
208                                 sortInfo : { direction : 'ASC', field: 'id' },
209                                 proxy : {
210                                     xtype: 'HttpProxy',
211                                     xns: Roo.data,
212                                     method : 'GET',
213                                     url : baseURL + '/Roo/core_enum.php'
214                                 },
215                                 reader : {
216                                     xtype: 'JsonReader',
217                                     xns: Roo.data,
218                                     id : 'id',
219                                     root : 'data',
220                                     totalProperty : 'total',
221                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
222                                 }
223                             }
224                         },
225                         {
226                             xtype: 'Button',
227                             xns: Roo.Toolbar,
228                             listeners : {
229                                 click : function()
230                                 {
231                                     
232                                     // if we do not have a selected type... - what should we show..?
233                                     var et = _this.etypeCombo.getValue();
234                                     var ds = _this.grid.getDataSource();
235                                     if (!et) {
236                                         Roo.MessageBox.alert("Error", "Select a pulldown");
237                                         return;
238                                     }
239                                 
240                                     var add = ds.reader.newRow({    
241                                              id: 0, 
242                                              display_name : '', 
243                                              name : '', 
244                                              etype: et, 
245                                              active: 1, 
246                                              seqid: 0
247                                       });
248                                      var r = ds.data.length;
249                                     ds.insert(r  , add);  
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: 'Button',
259                             xns: Roo.Toolbar,
260                             listeners : {
261                                 click : function()
262                                 {
263                                     
264                                     // if we do not have a selected type... - what should we show..?
265                                     var et = _this.etypeCombo.getValue();
266                                     
267                                     if (!et) {
268                                         Roo.MessageBox.alert("Error", "Select a pulldown");
269                                         return;
270                                     }
271                                     var sc = _this.grid.getSelectionModel().getSelectedCell();
272                                     Roo.log(sc);
273                                     var ds = _this.grid.ds.getAt(sc[0]);
274                                     if (!ds) {
275                                         Roo.MessageBox.alert("Error", "Select enum");
276                                         return;
277                                     }
278                                     
279                                     Roo.log(ds);
280                                     Pman.Dialog.AdminEnumImages.show({onid:ds.data.id});
281                                     
282                                 }
283                             },
284                             cls : 'x-btn-text-icon',
285                             text : "Add Images",
286                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
287                         },
288                         {
289                             xtype: 'Fill',
290                             xns: Roo.Toolbar
291                         },
292                         {
293                             xtype: 'Button',
294                             xns: Roo.Toolbar,
295                             listeners : {
296                                 click : function()
297                                 {
298                                     
299                                     Roo.MessageBox.prompt ("Create a new Enum type",
300                                         "Enter the name for a new enum type, " + 
301                                         "this is only relivant if you  know how it is going to be used",
302                                         function(btn,txt) {
303                                             if (btn != 'ok') {
304                                                 return; 
305                                             }
306                                             new Pman.Request({
307                                                 url : baseURL + '/Roo/Core_enum.php',
308                                                 method : 'POST',
309                                                 params : {
310                                                     etype : '',
311                                                     name : txt,
312                                                     active : 1
313                                                 }, 
314                                                 success : function() {
315                                                     Roo.MessageBox.alert("Created", "You can now select it from the type list on the left");
316                                                 }
317                                             });
318                                                     
319                                             
320                                              
321                                              
322                                         }
323                                     ); 
324                                          
325                                          
326                                 
327                                 }
328                             },
329                             cls : 'x-btn-text-icon',
330                             text : "Add new pulldown list",
331                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
332                         }
333                     ]
334                 },
335                 colModel : [
336                     {
337                         xtype: 'ColumnModel',
338                         xns: Roo.grid,
339                         dataIndex : 'id',
340                         header : 'Internal #',
341                         width : 75,
342                         renderer : function(v) { return String.format('{0}', v); }
343                     },
344                     {
345                         xtype: 'ColumnModel',
346                         xns: Roo.grid,
347                         dataIndex : 'images_id_id',
348                         header : 'Image',
349                         width : 75,
350                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" width="100">', baseURL, v, r.data.images_id_filename); }
351                     },
352                     {
353                         xtype: 'ColumnModel',
354                         xns: Roo.grid,
355                         header : 'Name',
356                         width : 200,
357                         dataIndex : 'name',
358                         renderer : function(v) { return String.format('{0}', v); },
359                         editor : {
360                             xtype: 'GridEditor',
361                             xns: Roo.grid,
362                             field : {
363                                 xtype: 'TextField',
364                                 xns: Roo.form
365                             }
366                         }
367                     },
368                     {
369                         xtype: 'ColumnModel',
370                         xns: Roo.grid,
371                         dataIndex : 'display_name',
372                         header : 'Display Name',
373                         width : 200,
374                         renderer : function(v) { return String.format('{0}', v); },
375                         editor : {
376                             xtype: 'GridEditor',
377                             xns: Roo.grid,
378                             field : {
379                                 xtype: 'TextField',
380                                 xns: Roo.form
381                             }
382                         }
383                     },
384                     {
385                         xtype: 'ColumnModel',
386                         xns: Roo.grid,
387                         dataIndex : 'active',
388                         header : 'Active',
389                         width : 75,
390                         renderer : function(v) {  
391                             var state = v> 0 ?  '-checked' : '';
392                         
393                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
394                                         
395                          }
396                     },
397                     {
398                         xtype: 'ColumnModel',
399                         xns: Roo.grid,
400                         dataIndex : 'seqid',
401                         header : 'Order #',
402                         sortable : true,
403                         width : 75,
404                         renderer : function(v) { return String.format('{0}', v); },
405                         editor : {
406                             xtype: 'GridEditor',
407                             xns: Roo.grid,
408                             field : {
409                                 xtype: 'NumberField',
410                                 xns: Roo.form,
411                                 allowDecimals : false,
412                                 allowNegative : true,
413                                 decimalPrecision : 0
414                             }
415                         }
416                     }
417                 ]
418             }
419         };
420     }
421 });