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