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 : 400,
34             title : "Pulldown Options",
35             width : 950,
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 : true,
50                     fitToframe : true,
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                         },
183                         toolbar : {
184                             xtype: 'Toolbar',
185                             xns: Roo,
186                             items : [
187                                 {
188                                     xtype: 'TextItem',
189                                     xns: Roo.Toolbar,
190                                     text : "Pulldown Name:"
191                                 },
192                                 {
193                                     xtype: 'ComboBox',
194                                     xns: Roo.form,
195                                     listeners : {
196                                         render : function (_self)
197                                         {
198                                             _this.etypeCombo = _self;
199                                         },
200                                         select : function (combo, record, index)
201                                         {
202                                             _this.grid.footer.onClick('first');
203                                         }
204                                     },
205                                     alwaysQuery : true,
206                                     displayField : 'name',
207                                     editable : 'false',
208                                     emptyText : "Select pulldown",
209                                     fieldLabel : 'core_enum',
210                                     forceSelection : true,
211                                     listWidth : 400,
212                                     loadingText : "Searching...",
213                                     minChars : 2,
214                                     pageSize : 50,
215                                     qtip : "Select type",
216                                     queryParam : 'query[name]',
217                                     selectOnFocus : true,
218                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{display_name}</b> - {name} </div>',
219                                     triggerAction : 'all',
220                                     typeAhead : false,
221                                     valueField : 'name',
222                                     width : 300,
223                                     store : {
224                                         xtype: 'Store',
225                                         xns: Roo.data,
226                                         listeners : {
227                                             beforeload : function (_self, o){
228                                                 o.params = o.params || {};
229                                                 // set more here
230                                                 o.params['query[empty_etype]'] = 1; 
231                                             }
232                                         },
233                                         remoteSort : true,
234                                         sortInfo : { direction : 'ASC', field: 'display_name' },
235                                         proxy : {
236                                             xtype: 'HttpProxy',
237                                             xns: Roo.data,
238                                             method : 'GET',
239                                             url : baseURL + '/Roo/core_enum.php'
240                                         },
241                                         reader : {
242                                             xtype: 'JsonReader',
243                                             xns: Roo.data,
244                                             id : 'id',
245                                             root : 'data',
246                                             totalProperty : 'total',
247                                             fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
248                                         }
249                                     }
250                                 },
251                                 {
252                                     xtype: 'Button',
253                                     xns: Roo.Toolbar,
254                                     listeners : {
255                                         click : function()
256                                         {
257                                             
258                                             // if we do not have a selected type... - what should we show..?
259                                             var et = _this.etypeCombo.getValue();
260                                             var ds = _this.grid.getDataSource();
261                                             if (!et) {
262                                                 Roo.MessageBox.alert("Error", "Select a pulldown");
263                                                 return;
264                                             }
265                                         
266                                             var add = ds.reader.newRow({    
267                                                      id: 0, 
268                                                      display_name : '', 
269                                                      name : '', 
270                                                      etype: et, 
271                                                      active: 1, 
272                                                      seqid: 0
273                                               });
274                                              var r = ds.data.length;
275                                             ds.insert(r  , add);  
276                                             _this.grid.startEditing(r, 1); // name... 
277                                         }
278                                     },
279                                     cls : 'x-btn-text-icon',
280                                     text : "Add Value",
281                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
282                                 },
283                                 {
284                                     xtype: 'Button',
285                                     xns: Roo.Toolbar,
286                                     listeners : {
287                                         click : function()
288                                         {
289                                             
290                                             // if we do not have a selected type... - what should we show..?
291                                             var et = _this.etypeCombo.getValue();
292                                             
293                                             if (!et) {
294                                                 Roo.MessageBox.alert("Error", "Select a pulldown");
295                                                 return;
296                                             }
297                                             var sc = _this.grid.getSelectionModel().getSelectedCell();
298                                             Roo.log(sc);
299                                             var ds = _this.grid.ds.getAt(sc[0]);
300                                             if (!ds) {
301                                                 Roo.MessageBox.alert("Error", "Select enum");
302                                                 return;
303                                             }
304                                             
305                                             Roo.log(ds);
306                                             Pman.Dialog.AdminEnumImages.show({onid:ds.data.id}, function(){
307                                                 _this.grid.footer.onClick('first');
308                                             });
309                                             
310                                         }
311                                     },
312                                     cls : 'x-btn-text-icon',
313                                     text : "Add Images",
314                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
315                                 },
316                                 {
317                                     xtype: 'Fill',
318                                     xns: Roo.Toolbar
319                                 },
320                                 {
321                                     xtype: 'Button',
322                                     xns: Roo.Toolbar,
323                                     listeners : {
324                                         click : function()
325                                         {
326                                             
327                                             Roo.MessageBox.prompt ("Create a new Enum type",
328                                                 "Enter the name for a new enum type, " + 
329                                                 "this is only relivant if you  know how it is going to be used",
330                                                 function(btn,txt) {
331                                                     if (btn != 'ok') {
332                                                         return; 
333                                                     }
334                                                     new Pman.Request({
335                                                         url : baseURL + '/Roo/Core_enum.php',
336                                                         method : 'POST',
337                                                         params : {
338                                                             etype : '',
339                                                             name : txt,
340                                                             active : 1
341                                                         }, 
342                                                         success : function() {
343                                                             Roo.MessageBox.alert("Created", "You can now select it from the type list on the left");
344                                                         }
345                                                     });
346                                                             
347                                                     
348                                                      
349                                                      
350                                                 }
351                                             ); 
352                                                  
353                                                  
354                                         
355                                         }
356                                     },
357                                     cls : 'x-btn-text-icon',
358                                     text : "Add new pulldown list",
359                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
360                                 }
361                             ]
362                         },
363                         colModel : [
364                             {
365                                 xtype: 'ColumnModel',
366                                 xns: Roo.grid,
367                                 dataIndex : 'id',
368                                 header : 'Internal #',
369                                 width : 75,
370                                 renderer : function(v) { return String.format('{0}', v); }
371                             },
372                             {
373                                 xtype: 'ColumnModel',
374                                 xns: Roo.grid,
375                                 dataIndex : 'images_id_id',
376                                 header : 'Image',
377                                 width : 75,
378                                 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); }
379                             },
380                             {
381                                 xtype: 'ColumnModel',
382                                 xns: Roo.grid,
383                                 header : 'Name',
384                                 width : 200,
385                                 dataIndex : 'name',
386                                 renderer : function(v) { return String.format('{0}', v); },
387                                 editor : {
388                                     xtype: 'GridEditor',
389                                     xns: Roo.grid,
390                                     field : {
391                                         xtype: 'TextField',
392                                         xns: Roo.form
393                                     }
394                                 }
395                             },
396                             {
397                                 xtype: 'ColumnModel',
398                                 xns: Roo.grid,
399                                 dataIndex : 'display_name',
400                                 header : 'Display Name',
401                                 width : 200,
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 : 'active',
416                                 header : 'Active',
417                                 width : 75,
418                                 renderer : function(v) {  
419                                     var state = v> 0 ?  '-checked' : '';
420                                 
421                                     return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
422                                                 
423                                  }
424                             },
425                             {
426                                 xtype: 'ColumnModel',
427                                 xns: Roo.grid,
428                                 dataIndex : 'seqid',
429                                 header : 'Order #',
430                                 sortable : true,
431                                 width : 75,
432                                 renderer : function(v) { return String.format('{0}', v); },
433                                 editor : {
434                                     xtype: 'GridEditor',
435                                     xns: Roo.grid,
436                                     field : {
437                                         xtype: 'NumberField',
438                                         xns: Roo.form,
439                                         allowDecimals : false,
440                                         allowNegative : true,
441                                         decimalPrecision : 0
442                                     }
443                                 }
444                             }
445                         ]
446                     }
447                 }
448             ],
449             center : {
450                 xtype: 'LayoutRegion',
451                 xns: Roo
452             },
453             buttons : [
454                 {
455                     xtype: 'Button',
456                     xns: Roo,
457                     text : "OK"
458                 }
459             ]
460         });
461     }
462 };