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 state = v> 0 ?  '-checked' : '';
300                         
301                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
302                         }
303                     },
304                     {
305                         xtype: 'ColumnModel',
306                         xns: Roo.grid,
307                         dataIndex : 'rightname',
308                         header : 'Module',
309                         sortable : false,
310                         width : 150,
311                         renderer : function(v,x,r) {
312                             if(!v){
313                                 return;
314                             }
315                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
316                         }
317                     },
318                     {
319                         xtype: 'ColumnModel',
320                         xns: Roo.grid,
321                         dataIndex : 'descript',
322                         header : 'Permission',
323                         sortable : false,
324                         width : 300,
325                         renderer : function(v,x,r)
326                         {
327                             if (r.json.descript && r.json.descript.length) {
328                                 return String.format('{0}',r.json.descript);
329                             }
330                             
331                             return '???' + v;
332                         }
333                     },
334                     {
335                         xtype: 'ColumnModel',
336                         xns: Roo.grid,
337                         dataIndex : 'accessmask_A',
338                         header : 'Add',
339                         width : 75,
340                         renderer : function(v) {  
341                             var state = v> 0 ?  '-checked' : '';
342                         
343                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
344                                         
345                          }
346                     },
347                     {
348                         xtype: 'ColumnModel',
349                         xns: Roo.grid,
350                         dataIndex : 'accessmask_E',
351                         header : 'Edit',
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_D',
364                         header : 'Delete',
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_S',
377                         header : 'List/View',
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_P',
390                         header : 'Print/Export',
391                         width : 75,
392                         renderer : function(v,x,r) {  
393                             Roo.log(x);
394                             Roo.log(r);
395                             var state = v> 0 ?  '-checked' : '';
396                         
397                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
398                                         
399                          }
400                     }
401                 ]
402             }
403         };
404     }
405 });