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                             Roo.each(records, function(e){
144                                 _this.dataUpdate[e.id] = e.accessmask;
145                             
146                                 var k = e.data.accessmask.split('');
147                                 
148                                 Roo.each(k, function(ee){
149                                     e.set('accessmask_'+ee, 1);
150                                 });
151                                 if(e.data.accessmask == e.data.FullMask){
152                                     e.set('accessmask_AA', 1);
153                                 }
154                             });
155                         }
156                     },
157                     remoteSort : true,
158                     sortInfo : { field : 'id', direction: 'ASC' },
159                     proxy : {
160                         xtype: 'HttpProxy',
161                         xns: Roo.data,
162                         method : 'GET',
163                         url : baseURL + '/Admin/GroupRights.php'
164                     },
165                     reader : {
166                         xtype: 'JsonReader',
167                         xns: Roo.data,
168                         id : 'id',
169                         root : 'data',
170                         totalProperty : 'total',
171                         fields : [
172                             {
173                                 'name': 'id',
174                                 'type': 'int'
175                             },
176                             {
177                                 'name': 'rightname',
178                                 'type': 'string'
179                             },
180                             {
181                                 'name': 'descript',
182                                 'type': 'string'
183                             },
184                             {
185                                 'name': 'accessmask',
186                                 'type': 'string'
187                             },
188                             {
189                                 'name': 'FullMask',
190                                 'type': 'string'
191                             },
192                             {
193                                 'name': 'group_id',
194                                 'type': 'int'
195                             }
196                         ]
197                     }
198                 },
199                 footer : {
200                     xtype: 'PagingToolbar',
201                     xns: Roo,
202                     pageSize : 25,
203                     displayInfo : true,
204                     displayMsg : "Displaying Person{0} - {1} of {2}",
205                     emptyMsg : "No Person found",
206                     items : [
207                         {
208                             xtype: 'TextItem',
209                             xns: Roo.Toolbar,
210                             text : "Drag person to add or remove from group"
211                         }
212                     ]
213                 },
214                 toolbar : {
215                     xtype: 'Toolbar',
216                     xns: Roo,
217                     items : [
218                         {
219                             xtype: 'Button',
220                             xns: Roo.Toolbar,
221                             listeners : {
222                                 click : function (_self, e)
223                                 {
224                                     
225                                     new Pman.Request({
226                                         url : baseURL + '/GroupRights.php',
227                                         method :'POST',
228                                         params : {
229                                             dataUpdate : _this.dataUpdate,
230                                             dataAdd : _this.dataAdd
231                                         },
232                                         success : function() {
233                                             // do nothing
234                                             
235                                             //_this.grid.ds.remove(record);
236                                             
237                                         },
238                                         failure : function() 
239                                         {
240                                             Roo.MessageBox.alert("Error", "saving failed", function() {
241                                                 _this.grid.footer.onClick('first');
242                                             });
243                                         }
244                                     });
245                                 }
246                             },
247                             text : "Save"
248                         }
249                     ]
250                 },
251                 colModel : [
252                     {
253                         xtype: 'ColumnModel',
254                         xns: Roo.grid,
255                         dataIndex : 'accessmask_AA',
256                         header : 'All',
257                         sortable : false,
258                         width : 50,
259                         renderer : function(v,x,r) {
260                              
261                             var state = v> 0 ?  '-checked' : '';
262                         
263                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
264                         }
265                     },
266                     {
267                         xtype: 'ColumnModel',
268                         xns: Roo.grid,
269                         dataIndex : 'rightname',
270                         header : 'Module',
271                         sortable : false,
272                         width : 150,
273                         renderer : function(v,x,r) {
274                             if(!v){
275                                 return;
276                             }
277                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
278                         }
279                     },
280                     {
281                         xtype: 'ColumnModel',
282                         xns: Roo.grid,
283                         dataIndex : 'descript',
284                         header : 'Permission',
285                         sortable : false,
286                         width : 300,
287                         renderer : function(v,x,r)
288                         {
289                             if (r.json.descript && r.json.descript.length) {
290                                 return String.format('{0}',r.json.descript);
291                             }
292                             
293                             return '???' + v;
294                         }
295                     },
296                     {
297                         xtype: 'ColumnModel',
298                         xns: Roo.grid,
299                         dataIndex : 'accessmask_A',
300                         header : 'Add',
301                         width : 75,
302                         renderer : function(v) {  
303                             var state = v> 0 ?  '-checked' : '';
304                         
305                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
306                                         
307                          }
308                     },
309                     {
310                         xtype: 'ColumnModel',
311                         xns: Roo.grid,
312                         dataIndex : 'accessmask_E',
313                         header : 'Edit',
314                         width : 75,
315                         renderer : function(v) {  
316                             var state = v> 0 ?  '-checked' : '';
317                         
318                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
319                                         
320                          }
321                     },
322                     {
323                         xtype: 'ColumnModel',
324                         xns: Roo.grid,
325                         dataIndex : 'accessmask_D',
326                         header : 'Delete',
327                         width : 75,
328                         renderer : function(v) {  
329                             var state = v> 0 ?  '-checked' : '';
330                         
331                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
332                                         
333                          }
334                     },
335                     {
336                         xtype: 'ColumnModel',
337                         xns: Roo.grid,
338                         dataIndex : 'accessmask_S',
339                         header : 'List/View',
340                         width : 75,
341                         renderer : function(v) {  
342                             var state = v> 0 ?  '-checked' : '';
343                         
344                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
345                                         
346                          }
347                     },
348                     {
349                         xtype: 'ColumnModel',
350                         xns: Roo.grid,
351                         dataIndex : 'accessmask_P',
352                         header : 'Print/Export',
353                         width : 75,
354                         renderer : function(v,x,r) {  
355                             
356                             var state = v> 0 ?  '-checked' : '';
357                         
358                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
359                                         
360                          }
361                     }
362                 ]
363             }
364         };
365     }
366 });