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                                     new Pman.Request({
235                                         url : baseURL + '/GroupRights.php',
236                                         method :'POST',
237                                         params : {
238                                             dataUpdate : _this.dataUpdate
239                                              
240                                         },
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 });