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