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