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                     
61                             var di = this.colModel.getDataIndex(columnIndex);
62                             var i = di.split('_').shift();
63                             var k = di.split('_').pop();
64                             if (i != 'accessmask') {
65                                 return;
66                             }
67                             var rec = _this.grid.ds.getAt(rowIndex);
68                             if(k == 'AA'){
69                                 var fm = rec.data.FullMask.split('');
70                                 Roo.each(fm, function(e){
71                                     rec.set(i+'_'+e, rec.data[i+'_'+k] ? 0 : 1);
72                                 });
73                             } 
74                             rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
75                             _this.dataUpdate[rec.data.id] = rec.data.accessmask;
76                             //rec.commit();
77                              
78                             
79                     }
80                 },
81                 ddGroup : 'groupDD',
82                 enableDrag : true,
83                 loadMask : true,
84                 dataSource : {
85                     xtype: 'Store',
86                     xns: Roo.data,
87                     listeners : {
88                         beforeload : function (_self, o)
89                         {
90                             if (!o.params) {
91                                 o.params = {}
92                             }
93                             var s = Pman.Tab.Groups.grid.getSelectionModel().getSelections();
94                             if (!s.length) {
95                                 o.params.group_id = -1;
96                             } else {
97                                 o.params.group_id = s[0].data.id;
98                             }
99                             if (o.params.group_id < 0) {
100                                 _this.grid.getView().el.mask("You can not set permissions for that group");
101                                 return false;
102                             }
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                             Roo.each(records, function(e){
139                                 var k = e.data.accessmask.split('');
140                                 Roo.each(k, function(ee){
141                                     e.set('accessmask_'+ee, 1);
142                                 });
143                                 if(e.data.accessmask == e.data.FullMask){
144                                     e.set('accessmask_AA', 1);
145                                 }
146                             });
147                         }
148                     },
149                     remoteSort : true,
150                     sortInfo : { field : 'id', direction: 'ASC' },
151                     proxy : {
152                         xtype: 'HttpProxy',
153                         xns: Roo.data,
154                         method : 'GET',
155                         url : baseURL + '/Admin/GroupRights.php'
156                     },
157                     reader : {
158                         xtype: 'JsonReader',
159                         xns: Roo.data,
160                         id : 'id',
161                         root : 'data',
162                         totalProperty : 'total',
163                         fields : [
164                             {
165                                 'name': 'id',
166                                 'type': 'int'
167                             },
168                             {
169                                 'name': 'rightname',
170                                 'type': 'string'
171                             },
172                             {
173                                 'name': 'descript',
174                                 'type': 'string'
175                             },
176                             {
177                                 'name': 'accessmask',
178                                 'type': 'string'
179                             },
180                             {
181                                 'name': 'FullMask',
182                                 'type': 'string'
183                             },
184                             {
185                                 'name': 'group_id',
186                                 'type': 'int'
187                             }
188                         ]
189                     }
190                 },
191                 footer : {
192                     xtype: 'PagingToolbar',
193                     xns: Roo,
194                     pageSize : 25,
195                     displayInfo : true,
196                     displayMsg : "Displaying Person{0} - {1} of {2}",
197                     emptyMsg : "No Person found",
198                     items : [
199                         {
200                             xtype: 'TextItem',
201                             xns: Roo.Toolbar,
202                             text : "Drag person to add or remove from group"
203                         }
204                     ]
205                 },
206                 toolbar : {
207                     xtype: 'Toolbar',
208                     xns: Roo,
209                     items : [
210                         {
211                             xtype: 'Button',
212                             xns: Roo.Toolbar,
213                             listeners : {
214                                 click : function (_self, e)
215                                 {
216                                     
217                                     new Pman.Request({
218                                         url : baseURL + '/Roo/GroupRights.php',
219                                         method :'POST',
220                                         params : _this.dataUpdate,
221                                         success : function() {
222                                             // do nothing
223                                             
224                                             _this.grid.ds.remove(record);
225                                             
226                                         },
227                                         failure : function() 
228                                         {
229                                             Roo.MessageBox.alert("Error", "saving failed", function() {
230                                                 _this.grid.footer.onClick('first');
231                                             });
232                                         }
233                                     });
234                                 }
235                             },
236                             text : "Save"
237                         }
238                     ]
239                 },
240                 colModel : [
241                     {
242                         xtype: 'ColumnModel',
243                         xns: Roo.grid,
244                         dataIndex : 'accessmask_AA',
245                         header : 'All',
246                         sortable : false,
247                         width : 50,
248                         renderer : function(v,x,r) {
249                              
250                             var state = v> 0 ?  '-checked' : '';
251                         
252                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
253                         }
254                     },
255                     {
256                         xtype: 'ColumnModel',
257                         xns: Roo.grid,
258                         dataIndex : 'rightname',
259                         header : 'Module',
260                         sortable : false,
261                         width : 150,
262                         renderer : function(v,x,r) {
263                             if(!v){
264                                 return;
265                             }
266                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
267                         }
268                     },
269                     {
270                         xtype: 'ColumnModel',
271                         xns: Roo.grid,
272                         dataIndex : 'descript',
273                         header : 'Permission',
274                         sortable : false,
275                         width : 300,
276                         renderer : function(v,x,r)
277                         {
278                             if (r.json.descript && r.json.descript.length) {
279                                 return String.format('{0}',r.json.descript);
280                             }
281                             
282                             return '???' + v;
283                         }
284                     },
285                     {
286                         xtype: 'ColumnModel',
287                         xns: Roo.grid,
288                         dataIndex : 'accessmask_A',
289                         header : 'Add',
290                         width : 75,
291                         renderer : function(v) {  
292                             var state = v> 0 ?  '-checked' : '';
293                         
294                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
295                                         
296                          }
297                     },
298                     {
299                         xtype: 'ColumnModel',
300                         xns: Roo.grid,
301                         dataIndex : 'accessmask_E',
302                         header : 'Edit',
303                         width : 75,
304                         renderer : function(v) {  
305                             var state = v> 0 ?  '-checked' : '';
306                         
307                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
308                                         
309                          }
310                     },
311                     {
312                         xtype: 'ColumnModel',
313                         xns: Roo.grid,
314                         dataIndex : 'accessmask_D',
315                         header : 'Delete',
316                         width : 75,
317                         renderer : function(v) {  
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_S',
328                         header : 'List/View',
329                         width : 75,
330                         renderer : function(v) {  
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_P',
341                         header : 'Print/Export',
342                         width : 75,
343                         renderer : function(v,x,r) {  
344                             
345                             var state = v> 0 ?  '-checked' : '';
346                         
347                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
348                                         
349                          }
350                     }
351                 ]
352             }
353         };
354     }
355 });