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                                 _this.group_id = -1;
98                             var s = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelections();
99                         
100                             if (!s.length) {
101                                 o.params.group_id = -1;
102                             } else {
103                                 o.params.group_id = s[0].data.id;
104                             }
105                             if (o.params.group_id < 0) {
106                                 _this.grid.getView().el.mask("You can not set permissions for that group");
107                                 return false;
108                             }
109                             _this.group_id = id;    
110                             _this.grid.getView().el.unmask();
111                             return true;
112                           
113                         },
114                         update : function (_self, record, operation)
115                         {
116                             if (operation != 'commit') {
117                                 return;
118                             }
119                             // only used to change active status.
120                             
121                             new Pman.Request({
122                                 url : baseURL + '/Roo/GroupRights.php',
123                                 method :'POST',
124                                 params : {
125                                     id : record.data.id,
126                                     active: record.data.active
127                                     
128                                 },
129                                 success : function() {
130                                     // do nothing
131                                     
132                                     _this.grid.ds.remove(record);
133                                     
134                                 },
135                                 failure : function() 
136                                 {
137                                     Roo.MessageBox.alert("Error", "saving failed", function() {
138                                         _this.grid.footer.onClick('first');
139                                     });
140                                 }
141                             });
142                         },
143                         load : function (_self, records, options)
144                         {
145                             _this.dataUpdate = {};
146                             var full = 'ADEPS'.split('');
147                             
148                             Roo.each(records, function(e){
149                                 _this.dataUpdate[e.id] = e.data.accessmask;
150                             
151                                 var k = e.data.accessmask.split('');
152                                 var rm = e.data.FullMask.split('');
153                                 
154                                 Roo.each(full, function(ee){
155                                     if (rm.indexOf(ee) < 0) {
156                                         e.set('accessmask_'+ee, -1);          
157                                         return;
158                                     }
159                                     
160                                     e.set('accessmask_'+ee, (k.indexOf(ee) < 0) ? 0 : 1);
161                                 });
162                                 
163                                 if(e.data.accessmask == e.data.FullMask){
164                                     e.set('accessmask_AA', 1);
165                                 }
166                             });
167                         }
168                     },
169                     remoteSort : true,
170                     sortInfo : { field : 'id', direction: 'ASC' },
171                     proxy : {
172                         xtype: 'HttpProxy',
173                         xns: Roo.data,
174                         method : 'GET',
175                         url : baseURL + '/Admin/GroupRights.php'
176                     },
177                     reader : {
178                         xtype: 'JsonReader',
179                         xns: Roo.data,
180                         id : 'id',
181                         root : 'data',
182                         totalProperty : 'total',
183                         fields : [
184                             {
185                                 'name': 'id',
186                                 'type': 'int'
187                             },
188                             {
189                                 'name': 'rightname',
190                                 'type': 'string'
191                             },
192                             {
193                                 'name': 'descript',
194                                 'type': 'string'
195                             },
196                             {
197                                 'name': 'accessmask',
198                                 'type': 'string'
199                             },
200                             {
201                                 'name': 'FullMask',
202                                 'type': 'string'
203                             },
204                             {
205                                 'name': 'group_id',
206                                 'type': 'int'
207                             }
208                         ]
209                     }
210                 },
211                 footer : {
212                     xtype: 'PagingToolbar',
213                     xns: Roo,
214                     pageSize : 25,
215                     displayInfo : true,
216                     displayMsg : "Displaying Person{0} - {1} of {2}",
217                     emptyMsg : "No Person found",
218                     items : [
219                         {
220                             xtype: 'TextItem',
221                             xns: Roo.Toolbar,
222                             text : "Drag person to add or remove from group"
223                         }
224                     ]
225                 },
226                 toolbar : {
227                     xtype: 'Toolbar',
228                     xns: Roo,
229                     items : [
230                         {
231                             xtype: 'Button',
232                             xns: Roo.Toolbar,
233                             listeners : {
234                                 click : function (_self, e)
235                                 {
236                                     
237                                     var params = { group_id : _this.group_id };
238                                     for(var i in _this.dataUpdate) {
239                                         params['dataUpdate[' + i + ']'] = _this.dataUpdate[i];
240                                     }
241                                     //Roo.log(params);return;
242                                     
243                                     new Pman.Request({
244                                         url : baseURL + '/Admin/GroupRights.php',
245                                         method :'POST',
246                                         mask: "Saving",
247                                         params : params,
248                                         success : function() {
249                                             // do nothing
250                                             
251                                             //_this.grid.ds.remove(record);
252                                             
253                                         },
254                                         failure : function() 
255                                         {
256                                             Roo.MessageBox.alert("Error", "saving failed", function() {
257                                                 _this.grid.footer.onClick('first');
258                                             });
259                                         }
260                                     });
261                                 }
262                             },
263                             text : "Save"
264                         }
265                     ]
266                 },
267                 colModel : [
268                     {
269                         xtype: 'ColumnModel',
270                         xns: Roo.grid,
271                         dataIndex : 'accessmask_AA',
272                         header : 'All',
273                         sortable : false,
274                         width : 50,
275                         renderer : function(v,x,r) {
276                              
277                             var state = v> 0 ?  '-checked' : '';
278                         
279                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
280                         }
281                     },
282                     {
283                         xtype: 'ColumnModel',
284                         xns: Roo.grid,
285                         dataIndex : 'rightname',
286                         header : 'Module',
287                         sortable : false,
288                         width : 150,
289                         renderer : function(v,x,r) {
290                             if(!v){
291                                 return;
292                             }
293                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
294                         }
295                     },
296                     {
297                         xtype: 'ColumnModel',
298                         xns: Roo.grid,
299                         dataIndex : 'descript',
300                         header : 'Permission',
301                         sortable : false,
302                         width : 300,
303                         renderer : function(v,x,r)
304                         {
305                             if (r.json.descript && r.json.descript.length) {
306                                 return String.format('{0}',r.json.descript);
307                             }
308                             
309                             return '???' + v;
310                         }
311                     },
312                     {
313                         xtype: 'ColumnModel',
314                         xns: Roo.grid,
315                         dataIndex : 'accessmask_A',
316                         header : 'Add',
317                         width : 75,
318                         renderer : function(v) {  
319                             if (v < 0) {
320                                 return '';
321                             }
322                             var state = v> 0 ?  '-checked' : '';
323                         
324                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
325                                         
326                          }
327                     },
328                     {
329                         xtype: 'ColumnModel',
330                         xns: Roo.grid,
331                         dataIndex : 'accessmask_E',
332                         header : 'Edit',
333                         width : 75,
334                         renderer : function(v) {  
335                            if (v < 0) {
336                                 return '';
337                             }
338                             var state = v> 0 ?  '-checked' : '';
339                         
340                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
341                                         
342                          }
343                     },
344                     {
345                         xtype: 'ColumnModel',
346                         xns: Roo.grid,
347                         dataIndex : 'accessmask_D',
348                         header : 'Delete',
349                         width : 75,
350                         renderer : function(v) {  
351                             if (v < 0) {
352                                 return '';
353                             }
354                             var state = v> 0 ?  '-checked' : '';
355                         
356                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
357                                         
358                          }
359                     },
360                     {
361                         xtype: 'ColumnModel',
362                         xns: Roo.grid,
363                         dataIndex : 'accessmask_S',
364                         header : 'List/View',
365                         width : 75,
366                         renderer : function(v) {  
367                             
368                             if (v < 0) {
369                                 return '';
370                             }
371                             var state = v> 0 ?  '-checked' : '';
372                         
373                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
374                                         
375                          }
376                     },
377                     {
378                         xtype: 'ColumnModel',
379                         xns: Roo.grid,
380                         dataIndex : 'accessmask_P',
381                         header : 'Print/Export',
382                         width : 75,
383                         renderer : function(v,x,r) {  
384                             
385                             
386                             if (v < 0) {
387                                 return '';
388                             }
389                             var state = v> 0 ?  '-checked' : '';
390                         
391                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
392                                         
393                          }
394                     }
395                 ]
396             }
397         };
398     }
399 });