Pman.Tab.AdminContactsGroupRight.bjs
[Pman.Admin] / Pman.Tab.AdminContactsGroupRight.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.AdminContactsGroupRight = new Roo.XComponent({
6     part     :  ["Admin","ContactsGroupRight"],
7     order    : '001-Pman.Tab.AdminContactsGroupRight',
8     region   : 'center',
9     parent   : 'Pman.Tab.AdminContactsManager',
10     name     : "unnamed module",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'GridPanel',
19             xns: Roo,
20             listeners : {
21                 activate : function() {
22                     _this.panel = this;
23                     if (_this.grid) {
24                         _this.grid.footer.onClick('first');
25                     }
26                 }
27             },
28             autoScroll : true,
29             background : true,
30             fitContainer : true,
31             fitToframe : true,
32             region : 'center',
33             tableName : 'Person',
34             title : "Rights",
35             grid : {
36                 xtype: 'Grid',
37                 xns: Roo.grid,
38                 listeners : {
39                     render : function() 
40                     {
41                         _this.grid = this; 
42                         if (!_this.dialog) {
43                             _this.dialog = Pman.Dialog.PersonEdit;
44                             
45                         }
46                         //_this.dialog = Pman.Dialog.FILL_IN
47                         if (_this.panel.active) {
48                            this.footer.onClick('first');
49                         }
50                     },
51                     rowdblclick : function (_self, rowIndex, e)
52                     {
53                         if (!_this.dialog) return;
54                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
55                             _this.grid.footer.onClick('first');
56                         }); 
57                     },
58                     cellclick : function (_self, rowIndex, columnIndex, e)
59                     {
60                             _this.dataUpdate = typeof(_this.dataUpdate) =='undefined' ?  {} : _this.dataUpdate;
61                             
62                             var di = this.colModel.getDataIndex(columnIndex);
63                             var i = di.split('_').shift();
64                             var k = di.split('_').pop();
65                             if (i != 'accessmask') {
66                                 return;
67                             }
68                             var rec = _this.grid.ds.getAt(rowIndex);
69                             if(k == 'AA'){
70                                 var fm = rec.data.FullMask.split('');
71                                 Roo.each(fm, function(e){
72                                     rec.set(i+'_'+e, rec.data[i+'_'+k] ? 0 : 1);
73                                 });
74                             } 
75                             rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
76                             //rec.data.accessmask = rec.data.accessmask + rec
77                             //Roo.log(rec);
78                             _this.dataUpdate[rec.data.id] = rec.data.accessmask;
79                     
80                             //rec.commit();
81                              
82                             
83                     }
84                 },
85                 ddGroup : 'groupDD',
86                 enableDrag : true,
87                 loadMask : true,
88                 dataSource : {
89                     xtype: 'Store',
90                     xns: Roo.data,
91                     listeners : {
92                         beforeload : function (_self, o)
93                         {
94                             if (!o.params) {
95                                 o.params = {}
96                             }
97                             var s = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelections();
98                             if (!s.length) {
99                                 o.params.group_id = -1;
100                             } else {
101                                 o.params.group_id = s[0].data.id;
102                             }
103                             if (o.params.group_id < 0) {
104                                 _this.grid.getView().el.mask("You can not set permissions for that group");
105                                 return false;
106                             }
107                             _this.grid.getView().el.unmask();
108                             return true;
109                           
110                         },
111                         update : function (_self, record, operation)
112                         {
113                             if (operation != 'commit') {
114                                 return;
115                             }
116                             // only used to change active status.
117                             
118                             new Pman.Request({
119                                 url : baseURL + '/Roo/GroupRights.php',
120                                 method :'POST',
121                                 params : {
122                                     id : record.data.id,
123                                     active: record.data.active
124                                     
125                                 },
126                                 success : function() {
127                                     // do nothing
128                                     
129                                     _this.grid.ds.remove(record);
130                                     
131                                 },
132                                 failure : function() 
133                                 {
134                                     Roo.MessageBox.alert("Error", "saving failed", function() {
135                                         _this.grid.footer.onClick('first');
136                                     });
137                                 }
138                             });
139                         },
140                         load : function (_self, records, options)
141                         {
142                             _this.dataUpdate = {};
143                             var full = 'ADEPS'.split('');
144                             
145                             Roo.each(records, function(e){
146                                 _this.dataUpdate[e.id] = e.data.accessmask;
147                             
148                                 var k = e.data.accessmask.split('');
149                                 var rm = e.data.FullMask.split('');
150                                 
151                                 Roo.each(full, function(ee){
152                                     if (rm.indexOf(ee) < 0) {
153                                         e.set('accessmask_'+ee, -1);          
154                                         return;
155                                     }
156                                     
157                                     e.set('accessmask_'+ee, (k.indexOf(ee) < 0) ? 0 : 1);
158                                 });
159                                 
160                                 if(e.data.accessmask == e.data.FullMask){
161                                     e.set('accessmask_AA', 1);
162                                 }
163                             });
164                         }
165                     },
166                     remoteSort : true,
167                     sortInfo : { field : 'id', direction: 'ASC' },
168                     proxy : {
169                         xtype: 'HttpProxy',
170                         xns: Roo.data,
171                         method : 'GET',
172                         url : baseURL + '/Admin/GroupRights.php'
173                     },
174                     reader : {
175                         xtype: 'JsonReader',
176                         xns: Roo.data,
177                         id : 'id',
178                         root : 'data',
179                         totalProperty : 'total',
180                         fields : [
181                             {
182                                 'name': 'id',
183                                 'type': 'int'
184                             },
185                             {
186                                 'name': 'rightname',
187                                 'type': 'string'
188                             },
189                             {
190                                 'name': 'descript',
191                                 'type': 'string'
192                             },
193                             {
194                                 'name': 'accessmask',
195                                 'type': 'string'
196                             },
197                             {
198                                 'name': 'FullMask',
199                                 'type': 'string'
200                             },
201                             {
202                                 'name': 'group_id',
203                                 'type': 'int'
204                             }
205                         ]
206                     }
207                 },
208                 footer : {
209                     xtype: 'PagingToolbar',
210                     xns: Roo,
211                     pageSize : 25,
212                     displayInfo : true,
213                     displayMsg : "Displaying Person{0} - {1} of {2}",
214                     emptyMsg : "No Person found",
215                     items : [
216                         {
217                             xtype: 'TextItem',
218                             xns: Roo.Toolbar,
219                             text : "Drag person to add or remove from group"
220                         }
221                     ]
222                 },
223                 toolbar : {
224                     xtype: 'Toolbar',
225                     xns: Roo,
226                     items : [
227                         {
228                             xtype: 'Button',
229                             xns: Roo.Toolbar,
230                             listeners : {
231                                 click : function (_self, e)
232                                 {
233                                     
234                                     var params = {};
235                                     for(var i in _this.dataUpdate) {
236                                         params['dataUpdate[' + i + ']'] = _this.dataUpdate[i];
237                                     }
238                                     
239                                     
240                                     new Pman.Request({
241                                         url : baseURL + '/GroupRights.php',
242                                         method :'POST',
243                                         params : params,
244                                         success : function() {
245                                             // do nothing
246                                             
247                                             //_this.grid.ds.remove(record);
248                                             
249                                         },
250                                         failure : function() 
251                                         {
252                                             Roo.MessageBox.alert("Error", "saving failed", function() {
253                                                 _this.grid.footer.onClick('first');
254                                             });
255                                         }
256                                     });
257                                 }
258                             },
259                             text : "Save"
260                         }
261                     ]
262                 },
263                 colModel : [
264                     {
265                         xtype: 'ColumnModel',
266                         xns: Roo.grid,
267                         dataIndex : 'accessmask_AA',
268                         header : 'All',
269                         sortable : false,
270                         width : 50,
271                         renderer : function(v,x,r) {
272                              
273                             var state = v> 0 ?  '-checked' : '';
274                         
275                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
276                         }
277                     },
278                     {
279                         xtype: 'ColumnModel',
280                         xns: Roo.grid,
281                         dataIndex : 'rightname',
282                         header : 'Module',
283                         sortable : false,
284                         width : 150,
285                         renderer : function(v,x,r) {
286                             if(!v){
287                                 return;
288                             }
289                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
290                         }
291                     },
292                     {
293                         xtype: 'ColumnModel',
294                         xns: Roo.grid,
295                         dataIndex : 'descript',
296                         header : 'Permission',
297                         sortable : false,
298                         width : 300,
299                         renderer : function(v,x,r)
300                         {
301                             if (r.json.descript && r.json.descript.length) {
302                                 return String.format('{0}',r.json.descript);
303                             }
304                             
305                             return '???' + v;
306                         }
307                     },
308                     {
309                         xtype: 'ColumnModel',
310                         xns: Roo.grid,
311                         dataIndex : 'accessmask_A',
312                         header : 'Add',
313                         width : 75,
314                         renderer : function(v) {  
315                             if (v < 0) {
316                                 return '';
317                             }
318                             var state = v> 0 ?  '-checked' : '';
319                         
320                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
321                                         
322                          }
323                     },
324                     {
325                         xtype: 'ColumnModel',
326                         xns: Roo.grid,
327                         dataIndex : 'accessmask_E',
328                         header : 'Edit',
329                         width : 75,
330                         renderer : function(v) {  
331                            if (v < 0) {
332                                 return '';
333                             }
334                             var state = v> 0 ?  '-checked' : '';
335                         
336                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
337                                         
338                          }
339                     },
340                     {
341                         xtype: 'ColumnModel',
342                         xns: Roo.grid,
343                         dataIndex : 'accessmask_D',
344                         header : 'Delete',
345                         width : 75,
346                         renderer : function(v) {  
347                             if (v < 0) {
348                                 return '';
349                             }
350                             var state = v> 0 ?  '-checked' : '';
351                         
352                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
353                                         
354                          }
355                     },
356                     {
357                         xtype: 'ColumnModel',
358                         xns: Roo.grid,
359                         dataIndex : 'accessmask_S',
360                         header : 'List/View',
361                         width : 75,
362                         renderer : function(v) {  
363                             
364                             if (v < 0) {
365                                 return '';
366                             }
367                             var state = v> 0 ?  '-checked' : '';
368                         
369                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
370                                         
371                          }
372                     },
373                     {
374                         xtype: 'ColumnModel',
375                         xns: Roo.grid,
376                         dataIndex : 'accessmask_P',
377                         header : 'Print/Export',
378                         width : 75,
379                         renderer : function(v,x,r) {  
380                             
381                             
382                             if (v < 0) {
383                                 return '';
384                             }
385                             var state = v> 0 ?  '-checked' : '';
386                         
387                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
388                                         
389                          }
390                     }
391                 ]
392             }
393         };
394     }
395 });