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