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