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