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