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                             var fm = rec.data.FullMask.split('');
73                             Roo.each(rec.data.FullMask, function(){
74                                 rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
75                             });
76                             rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
77                             //rec.commit();
78                              
79                             
80                     }
81                 },
82                 ddGroup : 'groupDD',
83                 enableDrag : true,
84                 loadMask : true,
85                 dataSource : {
86                     xtype: 'Store',
87                     xns: Roo.data,
88                     listeners : {
89                         beforeload : function (_self, o)
90                         {
91                             if (!o.params) {
92                                 o.params = {}
93                             }
94                             var s = Pman.Tab.Groups.grid.getSelectionModel().getSelections();
95                             if (!s.length) {
96                                 o.params.group_id = -1;
97                             } else {
98                                 o.params.group_id = s[0].data.id;
99                             }
100                             if (o.params.group_id < 0) {
101                                 _this.grid.getView().el.mask("You can not set permissions for that group");
102                                 return false;
103                             }
104                             _this.grid.getView().el.unmask();
105                             return true;
106                           
107                         },
108                         update : function (_self, record, operation)
109                         {
110                             if (operation != 'commit') {
111                                 return;
112                             }
113                             // only used to change active status.
114                             
115                             new Pman.Request({
116                                 url : baseURL + '/Roo/GroupRights.php',
117                                 method :'POST',
118                                 params : {
119                                     id : record.data.id,
120                                     active: record.data.active
121                                     
122                                 },
123                                 success : function() {
124                                     // do nothing
125                                     
126                                     _this.grid.ds.remove(record);
127                                     
128                                 },
129                                 failure : function() 
130                                 {
131                                     Roo.MessageBox.alert("Error", "saving failed", function() {
132                                         _this.grid.footer.onClick('first');
133                                     });
134                                 }
135                             });
136                         }
137                     },
138                     remoteSort : true,
139                     sortInfo : { field : 'id', direction: 'ASC' },
140                     proxy : {
141                         xtype: 'HttpProxy',
142                         xns: Roo.data,
143                         method : 'GET',
144                         url : baseURL + '/Admin/GroupRights.php'
145                     },
146                     reader : {
147                         xtype: 'JsonReader',
148                         xns: Roo.data,
149                         id : 'id',
150                         root : 'data',
151                         totalProperty : 'total',
152                         fields : [
153                             {
154                                 'name': 'id',
155                                 'type': 'int'
156                             },
157                             {
158                                 'name': 'rightname',
159                                 'type': 'string'
160                             },
161                             {
162                                 'name': 'descript',
163                                 'type': 'string'
164                             },
165                             {
166                                 'name': 'accessmask',
167                                 'type': 'string'
168                             },
169                             {
170                                 'name': 'FullMask',
171                                 'type': 'string'
172                             },
173                             {
174                                 'name': 'group_id',
175                                 'type': 'int'
176                             }
177                         ]
178                     }
179                 },
180                 footer : {
181                     xtype: 'PagingToolbar',
182                     xns: Roo,
183                     pageSize : 25,
184                     displayInfo : true,
185                     displayMsg : "Displaying Person{0} - {1} of {2}",
186                     emptyMsg : "No Person found",
187                     items : [
188                         {
189                             xtype: 'TextItem',
190                             xns: Roo.Toolbar,
191                             text : "Drag person to add or remove from group"
192                         }
193                     ]
194                 },
195                 toolbar : {
196                     xtype: 'Toolbar',
197                     xns: Roo,
198                     items : [
199                         {
200                             xtype: 'TextItem',
201                             xns: Roo.Toolbar,
202                             text : "Search"
203                         },
204                         {
205                             xtype: 'TextField',
206                             xns: Roo.form,
207                             listeners : {
208                                 render : function (_self)
209                                 {
210                                     _this.searchBox = _self;
211                                 },
212                                 show : function (_self,e)
213                                 {
214                                     if (e.getCharCode() != 13) {
215                                         return;
216                                     }
217                                     _this.grid.footer.onClick('first');
218                                 },
219                                 specialkey : function (_self, e)
220                                 {
221                                   if (e.getKey() == 13) {
222                                     _this.grid.footer.onClick('first');
223                                   }
224                                 }
225                             }
226                         },
227                         {
228                             xtype: 'ComboBox',
229                             xns: Roo.form,
230                             listeners : {
231                                 render : function (_self)
232                                 {
233                                   _this.companyCombo = _self;
234                                 },
235                                 select : function (combo, record, index)
236                                 {
237                                    _this.grid.footer.onClick.defer(300,_this.grid.footer,[ 'first'] );
238                                 }
239                             },
240                             displayField : 'name',
241                             editable : true,
242                             emptyText : "Select Company",
243                             forceSelection : true,
244                             hiddenName : 'company_id',
245                             listWidth : 400,
246                             loadingText : "Searching...",
247                             minChars : 2,
248                             name : 'company_name',
249                             pageSize : 20,
250                             qtip : "Select Companies",
251                             queryParam : 'query[name]',
252                             selectOnFocus : true,
253                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
254                             triggerAction : 'all',
255                             typeAhead : true,
256                             valueField : 'id',
257                             width : 150,
258                             store : {
259                                 xtype: 'Store',
260                                 xns: Roo.data,
261                                 listeners : {
262                                     beforeload : function (_self, o){
263                                         o.params = o.params || {};
264                                         // set more here
265                                     }
266                                 },
267                                 remoteSort : true,
268                                 sortInfo : { direction : 'ASC', field: 'name' },
269                                 proxy : {
270                                     xtype: 'HttpProxy',
271                                     xns: Roo.data,
272                                     method : 'GET',
273                                     url : baseURL + '/Roo/Companies.php'
274                                 },
275                                 reader : {
276                                     xtype: 'JsonReader',
277                                     xns: Roo.data,
278                                     id : 'id',
279                                     root : 'data',
280                                     totalProperty : 'total',
281                                     fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
282                                 }
283                             }
284                         },
285                         {
286                             xtype: 'Fill',
287                             xns: Roo.Toolbar
288                         }
289                     ]
290                 },
291                 colModel : [
292                     {
293                         xtype: 'ColumnModel',
294                         xns: Roo.grid,
295                         dataIndex : 'accessmask_AA',
296                         header : 'All',
297                         sortable : false,
298                         width : 50,
299                         renderer : function(v,x,r) {
300                             var state = v> 0 ?  '-checked' : '';
301                         
302                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
303                         }
304                     },
305                     {
306                         xtype: 'ColumnModel',
307                         xns: Roo.grid,
308                         dataIndex : 'rightname',
309                         header : 'Module',
310                         sortable : false,
311                         width : 150,
312                         renderer : function(v,x,r) {
313                             if(!v){
314                                 return;
315                             }
316                             return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
317                         }
318                     },
319                     {
320                         xtype: 'ColumnModel',
321                         xns: Roo.grid,
322                         dataIndex : 'descript',
323                         header : 'Permission',
324                         sortable : false,
325                         width : 300,
326                         renderer : function(v,x,r)
327                         {
328                             if (r.json.descript && r.json.descript.length) {
329                                 return String.format('{0}',r.json.descript);
330                             }
331                             
332                             return '???' + v;
333                         }
334                     },
335                     {
336                         xtype: 'ColumnModel',
337                         xns: Roo.grid,
338                         dataIndex : 'accessmask_A',
339                         header : 'Add',
340                         width : 75,
341                         renderer : function(v) {  
342                             var state = v> 0 ?  '-checked' : '';
343                         
344                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
345                                         
346                          }
347                     },
348                     {
349                         xtype: 'ColumnModel',
350                         xns: Roo.grid,
351                         dataIndex : 'accessmask_E',
352                         header : 'Edit',
353                         width : 75,
354                         renderer : function(v) {  
355                             var state = v> 0 ?  '-checked' : '';
356                         
357                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
358                                         
359                          }
360                     },
361                     {
362                         xtype: 'ColumnModel',
363                         xns: Roo.grid,
364                         dataIndex : 'accessmask_D',
365                         header : 'Delete',
366                         width : 75,
367                         renderer : function(v) {  
368                             var state = v> 0 ?  '-checked' : '';
369                         
370                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
371                                         
372                          }
373                     },
374                     {
375                         xtype: 'ColumnModel',
376                         xns: Roo.grid,
377                         dataIndex : 'accessmask_S',
378                         header : 'List/View',
379                         width : 75,
380                         renderer : function(v) {  
381                             var state = v> 0 ?  '-checked' : '';
382                         
383                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
384                                         
385                          }
386                     },
387                     {
388                         xtype: 'ColumnModel',
389                         xns: Roo.grid,
390                         dataIndex : 'accessmask_P',
391                         header : 'Print/Export',
392                         width : 75,
393                         renderer : function(v) {  
394                             var state = v> 0 ?  '-checked' : '';
395                         
396                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
397                                         
398                          }
399                     }
400                 ]
401             }
402         };
403     }
404 });