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