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