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                             
65                             if (i != 'accessmask') {
66                                 return;
67                             }
68                     
69                             var rec = _this.grid.ds.getAt(rowIndex);
70                             Roo.log(di);
71                             Roo.log(rec.data.FullMask);
72                             if(k == 'AA'){
73                                 var fm = rec.data.FullMask.split('');
74                                 Roo.each(fm, function(e){
75                                     rec.set(i+'_'+e, rec.data[i+'_'+k] ? 0 : 1);
76                                 });
77                             } 
78                             rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
79                             
80                             //rec.commit();
81                              
82                             
83                     }
84                 },
85                 ddGroup : 'groupDD',
86                 enableDrag : true,
87                 loadMask : true,
88                 dataSource : {
89                     xtype: 'Store',
90                     xns: Roo.data,
91                     listeners : {
92                         beforeload : function (_self, o)
93                         {
94                             if (!o.params) {
95                                 o.params = {}
96                             }
97                             var s = Pman.Tab.Groups.grid.getSelectionModel().getSelections();
98                             if (!s.length) {
99                                 o.params.group_id = -1;
100                             } else {
101                                 o.params.group_id = s[0].data.id;
102                             }
103                             if (o.params.group_id < 0) {
104                                 _this.grid.getView().el.mask("You can not set permissions for that group");
105                                 return false;
106                             }
107                             _this.grid.getView().el.unmask();
108                             return true;
109                           
110                         },
111                         update : function (_self, record, operation)
112                         {
113                             if (operation != 'commit') {
114                                 return;
115                             }
116                             // only used to change active status.
117                             
118                             new Pman.Request({
119                                 url : baseURL + '/Roo/GroupRights.php',
120                                 method :'POST',
121                                 params : {
122                                     id : record.data.id,
123                                     active: record.data.active
124                                     
125                                 },
126                                 success : function() {
127                                     // do nothing
128                                     
129                                     _this.grid.ds.remove(record);
130                                     
131                                 },
132                                 failure : function() 
133                                 {
134                                     Roo.MessageBox.alert("Error", "saving failed", function() {
135                                         _this.grid.footer.onClick('first');
136                                     });
137                                 }
138                             });
139                         }
140                     },
141                     remoteSort : true,
142                     sortInfo : { field : 'id', direction: 'ASC' },
143                     proxy : {
144                         xtype: 'HttpProxy',
145                         xns: Roo.data,
146                         method : 'GET',
147                         url : baseURL + '/Admin/GroupRights.php'
148                     },
149                     reader : {
150                         xtype: 'JsonReader',
151                         xns: Roo.data,
152                         id : 'id',
153                         root : 'data',
154                         totalProperty : 'total',
155                         fields : [
156                             {
157                                 'name': 'id',
158                                 'type': 'int'
159                             },
160                             {
161                                 'name': 'rightname',
162                                 'type': 'string'
163                             },
164                             {
165                                 'name': 'descript',
166                                 'type': 'string'
167                             },
168                             {
169                                 'name': 'accessmask',
170                                 'type': 'string'
171                             },
172                             {
173                                 'name': 'FullMask',
174                                 'type': 'string'
175                             },
176                             {
177                                 'name': 'group_id',
178                                 'type': 'int'
179                             }
180                         ]
181                     }
182                 },
183                 footer : {
184                     xtype: 'PagingToolbar',
185                     xns: Roo,
186                     pageSize : 25,
187                     displayInfo : true,
188                     displayMsg : "Displaying Person{0} - {1} of {2}",
189                     emptyMsg : "No Person found",
190                     items : [
191                         {
192                             xtype: 'TextItem',
193                             xns: Roo.Toolbar,
194                             text : "Drag person to add or remove from group"
195                         }
196                     ]
197                 },
198                 toolbar : {
199                     xtype: 'Toolbar',
200                     xns: Roo,
201                     items : [
202                         {
203                             xtype: 'TextItem',
204                             xns: Roo.Toolbar,
205                             text : "Search"
206                         },
207                         {
208                             xtype: 'TextField',
209                             xns: Roo.form,
210                             listeners : {
211                                 render : function (_self)
212                                 {
213                                     _this.searchBox = _self;
214                                 },
215                                 show : function (_self,e)
216                                 {
217                                     if (e.getCharCode() != 13) {
218                                         return;
219                                     }
220                                     _this.grid.footer.onClick('first');
221                                 },
222                                 specialkey : function (_self, e)
223                                 {
224                                   if (e.getKey() == 13) {
225                                     _this.grid.footer.onClick('first');
226                                   }
227                                 }
228                             }
229                         },
230                         {
231                             xtype: 'ComboBox',
232                             xns: Roo.form,
233                             listeners : {
234                                 render : function (_self)
235                                 {
236                                   _this.companyCombo = _self;
237                                 },
238                                 select : function (combo, record, index)
239                                 {
240                                    _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
241                                 }
242                             },
243                             displayField : 'name',
244                             editable : true,
245                             emptyText : "Select Company",
246                             forceSelection : true,
247                             hiddenName : 'company_id',
248                             listWidth : 400,
249                             loadingText : "Searching...",
250                             minChars : 2,
251                             name : 'company_name',
252                             pageSize : 20,
253                             qtip : "Select Companies",
254                             queryParam : 'query[name]',
255                             selectOnFocus : true,
256                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
257                             triggerAction : 'all',
258                             typeAhead : true,
259                             valueField : 'id',
260                             width : 150,
261                             store : {
262                                 xtype: 'Store',
263                                 xns: Roo.data,
264                                 listeners : {
265                                     beforeload : function (_self, o){
266                                         o.params = o.params || {};
267                                         // set more here
268                                     }
269                                 },
270                                 remoteSort : true,
271                                 sortInfo : { direction : 'ASC', field: 'name' },
272                                 proxy : {
273                                     xtype: 'HttpProxy',
274                                     xns: Roo.data,
275                                     method : 'GET',
276                                     url : baseURL + '/Roo/Companies.php'
277                                 },
278                                 reader : {
279                                     xtype: 'JsonReader',
280                                     xns: Roo.data,
281                                     id : 'id',
282                                     root : 'data',
283                                     totalProperty : 'total',
284                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
285                                 }
286                             }
287                         },
288                         {
289                             xtype: 'Fill',
290                             xns: Roo.Toolbar
291                         }
292                     ]
293                 },
294                 colModel : [
295                     {
296                         xtype: 'ColumnModel',
297                         xns: Roo.grid,
298                         dataIndex : 'accessmask_AA',
299                         header : 'All',
300                         sortable : false,
301                         width : 50,
302                         renderer : function(v,x,r) {
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) {  
397                             var state = v> 0 ?  '-checked' : '';
398                         
399                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
400                                         
401                          }
402                     }
403                 ]
404             }
405         };
406     }
407 });