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                             
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                                     
142                                     e.data['accessmask_'+ee] = 1;
143                                 });
144                             });
145                         }
146                     },
147                     remoteSort : true,
148                     sortInfo : { field : 'id', direction: 'ASC' },
149                     proxy : {
150                         xtype: 'HttpProxy',
151                         xns: Roo.data,
152                         method : 'GET',
153                         url : baseURL + '/Admin/GroupRights.php'
154                     },
155                     reader : {
156                         xtype: 'JsonReader',
157                         xns: Roo.data,
158                         id : 'id',
159                         root : 'data',
160                         totalProperty : 'total',
161                         fields : [
162                             {
163                                 'name': 'id',
164                                 'type': 'int'
165                             },
166                             {
167                                 'name': 'rightname',
168                                 'type': 'string'
169                             },
170                             {
171                                 'name': 'descript',
172                                 'type': 'string'
173                             },
174                             {
175                                 'name': 'accessmask',
176                                 'type': 'string'
177                             },
178                             {
179                                 'name': 'FullMask',
180                                 'type': 'string'
181                             },
182                             {
183                                 'name': 'group_id',
184                                 'type': 'int'
185                             }
186                         ]
187                     }
188                 },
189                 footer : {
190                     xtype: 'PagingToolbar',
191                     xns: Roo,
192                     pageSize : 25,
193                     displayInfo : true,
194                     displayMsg : "Displaying Person{0} - {1} of {2}",
195                     emptyMsg : "No Person found",
196                     items : [
197                         {
198                             xtype: 'TextItem',
199                             xns: Roo.Toolbar,
200                             text : "Drag person to add or remove from group"
201                         }
202                     ]
203                 },
204                 toolbar : {
205                     xtype: 'Toolbar',
206                     xns: Roo,
207                     items : [
208                         {
209                             xtype: 'TextItem',
210                             xns: Roo.Toolbar,
211                             text : "Search"
212                         },
213                         {
214                             xtype: 'TextField',
215                             xns: Roo.form,
216                             listeners : {
217                                 render : function (_self)
218                                 {
219                                     _this.searchBox = _self;
220                                 },
221                                 show : function (_self,e)
222                                 {
223                                     if (e.getCharCode() != 13) {
224                                         return;
225                                     }
226                                     _this.grid.footer.onClick('first');
227                                 },
228                                 specialkey : function (_self, e)
229                                 {
230                                   if (e.getKey() == 13) {
231                                     _this.grid.footer.onClick('first');
232                                   }
233                                 }
234                             }
235                         },
236                         {
237                             xtype: 'ComboBox',
238                             xns: Roo.form,
239                             listeners : {
240                                 render : function (_self)
241                                 {
242                                   _this.companyCombo = _self;
243                                 },
244                                 select : function (combo, record, index)
245                                 {
246                                    _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
247                                 }
248                             },
249                             displayField : 'name',
250                             editable : true,
251                             emptyText : "Select Company",
252                             forceSelection : true,
253                             hiddenName : 'company_id',
254                             listWidth : 400,
255                             loadingText : "Searching...",
256                             minChars : 2,
257                             name : 'company_name',
258                             pageSize : 20,
259                             qtip : "Select Companies",
260                             queryParam : 'query[name]',
261                             selectOnFocus : true,
262                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
263                             triggerAction : 'all',
264                             typeAhead : true,
265                             valueField : 'id',
266                             width : 150,
267                             store : {
268                                 xtype: 'Store',
269                                 xns: Roo.data,
270                                 listeners : {
271                                     beforeload : function (_self, o){
272                                         o.params = o.params || {};
273                                         // set more here
274                                     }
275                                 },
276                                 remoteSort : true,
277                                 sortInfo : { direction : 'ASC', field: 'name' },
278                                 proxy : {
279                                     xtype: 'HttpProxy',
280                                     xns: Roo.data,
281                                     method : 'GET',
282                                     url : baseURL + '/Roo/Companies.php'
283                                 },
284                                 reader : {
285                                     xtype: 'JsonReader',
286                                     xns: Roo.data,
287                                     id : 'id',
288                                     root : 'data',
289                                     totalProperty : 'total',
290                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
291                                 }
292                             }
293                         },
294                         {
295                             xtype: 'Fill',
296                             xns: Roo.Toolbar
297                         }
298                     ]
299                 },
300                 colModel : [
301                     {
302                         xtype: 'ColumnModel',
303                         xns: Roo.grid,
304                         dataIndex : 'accessmask_AA',
305                         header : 'All',
306                         sortable : false,
307                         width : 50,
308                         renderer : function(v,x,r) {
309                              
310                             var state = v> 0 ?  '-checked' : '';
311                         
312                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
313                         }
314                     },
315                     {
316                         xtype: 'ColumnModel',
317                         xns: Roo.grid,
318                         dataIndex : 'rightname',
319                         header : 'Module',
320                         sortable : false,
321                         width : 150,
322                         renderer : function(v,x,r) {
323                             if(!v){
324                                 return;
325                             }
326                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
327                         }
328                     },
329                     {
330                         xtype: 'ColumnModel',
331                         xns: Roo.grid,
332                         dataIndex : 'descript',
333                         header : 'Permission',
334                         sortable : false,
335                         width : 300,
336                         renderer : function(v,x,r)
337                         {
338                             if (r.json.descript && r.json.descript.length) {
339                                 return String.format('{0}',r.json.descript);
340                             }
341                             
342                             return '???' + v;
343                         }
344                     },
345                     {
346                         xtype: 'ColumnModel',
347                         xns: Roo.grid,
348                         dataIndex : 'accessmask_A',
349                         header : 'Add',
350                         width : 75,
351                         renderer : function(v) {  
352                             var state = v> 0 ?  '-checked' : '';
353                         
354                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
355                                         
356                          }
357                     },
358                     {
359                         xtype: 'ColumnModel',
360                         xns: Roo.grid,
361                         dataIndex : 'accessmask_E',
362                         header : 'Edit',
363                         width : 75,
364                         renderer : function(v) {  
365                             var state = v> 0 ?  '-checked' : '';
366                         
367                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
368                                         
369                          }
370                     },
371                     {
372                         xtype: 'ColumnModel',
373                         xns: Roo.grid,
374                         dataIndex : 'accessmask_D',
375                         header : 'Delete',
376                         width : 75,
377                         renderer : function(v) {  
378                             var state = v> 0 ?  '-checked' : '';
379                         
380                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
381                                         
382                          }
383                     },
384                     {
385                         xtype: 'ColumnModel',
386                         xns: Roo.grid,
387                         dataIndex : 'accessmask_S',
388                         header : 'List/View',
389                         width : 75,
390                         renderer : function(v) {  
391                             var state = v> 0 ?  '-checked' : '';
392                         
393                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
394                                         
395                          }
396                     },
397                     {
398                         xtype: 'ColumnModel',
399                         xns: Roo.grid,
400                         dataIndex : 'accessmask_P',
401                         header : 'Print/Export',
402                         width : 75,
403                         renderer : function(v,x,r) {  
404                             
405                             var state = v> 0 ?  '-checked' : '';
406                         
407                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
408                                         
409                          }
410                     }
411                 ]
412             }
413         };
414     }
415 });