sync
[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 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.AdminContactsGroupRight = new Roo.XComponent({
8
9  _strings : {
10   '8444e81d652b084d70c71cd7d19ac0cf' :"Displaying Person{0} - {1} of {2}",
11   '72670177480da92f72dc55e4aaff219b' :"Rights",
12   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
13   '7dce122004969d56ae2e0245cb754d35' :"Edit",
14   '4110db87ce3ac86d603d03d691616b1e' :"Drag person to add or remove from group",
15   '4d2d6b41cd520fa711073fffbfe81076' :"List/View",
16   '6a0483c116671f74ffb653d4c85c4f55' :"Print/Export",
17   'f1174ecbbc232f948717979daf04cf08' :"No Person found",
18   'c9cc8cce247e49bae79f15173ce97354' :"Save",
19   'b1c94ca2fbc3e78fc30069c8d0f01680' :"All",
20   'e55f75a29310d7b60f7ac1d390c8ae42' :"Module",
21   'ed5dea09095f671b801bee34ea28a319' :"Permission",
22   'f2a6c498fb90ee345d997f888fce3b18' :"Delete"
23  },
24
25   part     :  ["Admin", "ContactsGroupRight" ],
26   order    : '001-Pman.Tab.AdminContactsGroupRight',
27   region   : 'center',
28   parent   : 'Pman.Tab.AdminContactsManager',
29   name     : "unnamed module",
30   disabled : false, 
31   permname : '', 
32   _tree : function(_data)
33   {
34    var _this = this;
35    var MODULE = this;
36    return {
37    xtype : 'GridPanel',
38    autoScroll : true,
39    background : true,
40    fitContainer : true,
41    fitToframe : true,
42    region : 'center',
43    tableName : 'Person',
44    title : _this._strings['72670177480da92f72dc55e4aaff219b'] /* Rights */,
45    listeners : {
46     activate : function() {
47          _this.panel = this;
48          if (_this.grid) {
49              _this.grid.footer.onClick('first');
50          }
51      }
52    },
53    xns : Roo,
54    '|xns' : 'Roo',
55    grid : {
56     xtype : 'Grid',
57     ddGroup : 'groupDD',
58     enableDrag : true,
59     loadMask : true,
60     listeners : {
61      cellclick : function (_self, rowIndex, columnIndex, e)
62       {
63               _this.dataUpdate = typeof(_this.dataUpdate) =='undefined' ?  {} : _this.dataUpdate;
64               
65               var di = this.colModel.getDataIndex(columnIndex);
66               var i = di.split('_').shift();
67               var k = di.split('_').pop();
68               if (i != 'accessmask') {
69                   return;
70               }
71               var rec = _this.grid.ds.getAt(rowIndex);
72               var fm = rec.data.FullMask.split('');        
73               if(k == 'AA'){
74       
75                   Roo.each(fm, function(e){
76                       rec.set(i+'_'+e, rec.data[i+'_'+k] ? 0 : 1);
77                   });
78               } 
79               rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
80               
81               var newmask = '';
82               Roo.each(fm, function(e) {
83                   if (rec.data[i+'_'+e] === 1) {
84               
85                       newmask += e;
86                   }
87               
88               });        
89               
90               //rec.data.accessmask = rec.data.accessmask + rec
91               //Roo.log(rec);
92               _this.dataUpdate[rec.data.id] = newmask;
93       
94               //rec.commit();
95                
96               
97       },
98      render : function() 
99       {
100           _this.grid = this; 
101           if (!_this.dialog) {
102               _this.dialog = Pman.Dialog.PersonEdit;
103               
104           }
105           //_this.dialog = Pman.Dialog.FILL_IN
106           if (_this.panel.active) {
107              this.footer.onClick('first');
108           }
109       }
110     },
111     xns : Roo.grid,
112     '|xns' : 'Roo.grid',
113     footer : {
114      xtype : 'PagingToolbar',
115      displayInfo : true,
116      displayMsg : _this._strings['8444e81d652b084d70c71cd7d19ac0cf'] /* Displaying Person{0} - {1} of {2} */,
117      emptyMsg : _this._strings['f1174ecbbc232f948717979daf04cf08'] /* No Person found */,
118      pageSize : 25,
119      xns : Roo,
120      '|xns' : 'Roo',
121      items  : [
122       {
123        xtype : 'TextItem',
124        text : _this._strings['4110db87ce3ac86d603d03d691616b1e'] /* Drag person to add or remove from group */,
125        xns : Roo.Toolbar,
126        '|xns' : 'Roo.Toolbar'
127       }
128      ]
129     },
130     toolbar : {
131      xtype : 'Toolbar',
132      xns : Roo,
133      '|xns' : 'Roo',
134      items  : [
135       {
136        xtype : 'Button',
137        text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
138        listeners : {
139         click : function (_self, e)
140          {
141              
142              var params = { group_id : _this.group_id };
143              for(var i in _this.dataUpdate) {
144                  params['dataUpdate[' + i + ']'] = _this.dataUpdate[i];
145              }
146              //Roo.log(params);return;
147              
148              new Pman.Request({
149                  url : baseURL + '/Admin/GroupRights.php',
150                  method :'POST',
151                  mask: "Saving",
152                  params : params,
153                  success : function() {
154                      // do nothing
155                      
156                      //_this.grid.ds.remove(record);
157                      
158                  },
159                  failure : function() 
160                  {
161                      Roo.MessageBox.alert("Error", "saving failed", function() {
162                          _this.grid.footer.onClick('first');
163                      });
164                  }
165              });
166          }
167        },
168        xns : Roo.Toolbar,
169        '|xns' : 'Roo.Toolbar'
170       }
171      ]
172     },
173     dataSource : {
174      xtype : 'Store',
175      remoteSort : true,
176      sortInfo : { field : 'id', direction: 'ASC' },
177      listeners : {
178       beforeload : function (_self, o)
179        {
180            if (!o.params) {
181                o.params = {}
182            }
183                _this.group_id = -1;
184            var s = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelections();
185        
186            if (!s.length) {
187                o.params.group_id = -1;
188            } else {
189                o.params.group_id = s[0].data.id;
190            }
191            if (o.params.group_id < 0) {
192                _this.grid.getView().el.mask("You can not set permissions for that group");
193                return false;
194            }
195            _this.group_id = o.params.group_id;
196            _this.grid.getView().el.unmask();
197            return true;
198          
199        },
200       load : function (_self, records, options)
201        {
202            _this.dataUpdate = {};
203            var full = 'ADEPS'.split('');
204            
205            Roo.each(records, function(e){
206                _this.dataUpdate[e.id] = e.data.accessmask;
207            
208                var k = e.data.accessmask.split('');
209                var rm = e.data.FullMask.split('');
210                
211                Roo.each(full, function(ee){
212                    if (rm.indexOf(ee) < 0) {
213                        e.set('accessmask_'+ee, -1);          
214                        return;
215                    }
216                    
217                    e.set('accessmask_'+ee, (k.indexOf(ee) < 0) ? 0 : 1);
218                });
219                
220                if(e.data.accessmask == e.data.FullMask){
221                    e.set('accessmask_AA', 1);
222                }
223            });
224        },
225       update : function (_self, record, operation)
226        {
227            if (operation != 'commit') {
228                return;
229            }
230            // only used to change active status.
231            
232            new Pman.Request({
233                url : baseURL + '/Roo/GroupRights.php',
234                method :'POST',
235                params : {
236                    id : record.data.id,
237                    active: record.data.active
238                    
239                },
240                success : function() {
241                    // do nothing
242                    
243                    _this.grid.ds.remove(record);
244                    
245                },
246                failure : function() 
247                {
248                    Roo.MessageBox.alert("Error", "saving failed", function() {
249                        _this.grid.footer.onClick('first');
250                    });
251                }
252            });
253        }
254      },
255      xns : Roo.data,
256      '|xns' : 'Roo.data',
257      proxy : {
258       xtype : 'HttpProxy',
259       method : 'GET',
260       url : baseURL + '/Admin/GroupRights.php',
261       xns : Roo.data,
262       '|xns' : 'Roo.data'
263      },
264      reader : {
265       xtype : 'JsonReader',
266       fields : [
267           {
268               'name': 'id',
269               'type': 'int'
270           },
271           {
272               'name': 'rightname',
273               'type': 'string'
274           },
275           {
276               'name': 'descript',
277               'type': 'string'
278           },
279           {
280               'name': 'accessmask',
281               'type': 'string'
282           },
283           {
284               'name': 'FullMask',
285               'type': 'string'
286           },
287           {
288               'name': 'group_id',
289               'type': 'int'
290           }
291       ],
292       id : 'id',
293       root : 'data',
294       totalProperty : 'total',
295       xns : Roo.data,
296       '|xns' : 'Roo.data'
297      }
298     },
299     colModel : [
300      {
301       xtype : 'ColumnModel',
302       dataIndex : 'accessmask_AA',
303       header : _this._strings['b1c94ca2fbc3e78fc30069c8d0f01680'] /* All */,
304       renderer : function(v,x,r) {
305            
306           var state = v> 0 ?  '-checked' : '';
307       
308           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
309       },
310       sortable : false,
311       width : 50,
312       xns : Roo.grid,
313       '|xns' : 'Roo.grid'
314      },
315      {
316       xtype : 'ColumnModel',
317       dataIndex : 'rightname',
318       header : _this._strings['e55f75a29310d7b60f7ac1d390c8ae42'] /* Module */,
319       renderer : function(v,x,r) {
320           if(!v){
321               return;
322           }
323           return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
324       },
325       sortable : false,
326       width : 150,
327       xns : Roo.grid,
328       '|xns' : 'Roo.grid'
329      },
330      {
331       xtype : 'ColumnModel',
332       dataIndex : 'descript',
333       header : _this._strings['ed5dea09095f671b801bee34ea28a319'] /* Permission */,
334       renderer : function(v,x,r)
335       {
336           if (r.json.descript && r.json.descript.length) {
337               return String.format('{0}',r.json.descript);
338           }
339           
340           return '???' + v;
341       },
342       sortable : false,
343       width : 300,
344       xns : Roo.grid,
345       '|xns' : 'Roo.grid'
346      },
347      {
348       xtype : 'ColumnModel',
349       dataIndex : 'accessmask_A',
350       header : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
351       renderer : function(v) {  
352           if (v < 0) {
353               return '';
354           }
355           var state = v> 0 ?  '-checked' : '';
356       
357           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
358                       
359        },
360       width : 75,
361       xns : Roo.grid,
362       '|xns' : 'Roo.grid'
363      },
364      {
365       xtype : 'ColumnModel',
366       dataIndex : 'accessmask_E',
367       header : _this._strings['7dce122004969d56ae2e0245cb754d35'] /* Edit */,
368       renderer : function(v) {  
369          if (v < 0) {
370               return '';
371           }
372           var state = v> 0 ?  '-checked' : '';
373       
374           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
375                       
376        },
377       width : 75,
378       xns : Roo.grid,
379       '|xns' : 'Roo.grid'
380      },
381      {
382       xtype : 'ColumnModel',
383       dataIndex : 'accessmask_D',
384       header : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
385       renderer : function(v) {  
386           if (v < 0) {
387               return '';
388           }
389           var state = v> 0 ?  '-checked' : '';
390       
391           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
392                       
393        },
394       width : 75,
395       xns : Roo.grid,
396       '|xns' : 'Roo.grid'
397      },
398      {
399       xtype : 'ColumnModel',
400       dataIndex : 'accessmask_S',
401       header : _this._strings['4d2d6b41cd520fa711073fffbfe81076'] /* List/View */,
402       renderer : function(v) {  
403           
404           if (v < 0) {
405               return '';
406           }
407           var state = v> 0 ?  '-checked' : '';
408       
409           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
410                       
411        },
412       width : 75,
413       xns : Roo.grid,
414       '|xns' : 'Roo.grid'
415      },
416      {
417       xtype : 'ColumnModel',
418       dataIndex : 'accessmask_P',
419       header : _this._strings['6a0483c116671f74ffb653d4c85c4f55'] /* Print/Export */,
420       renderer : function(v,x,r) {  
421           
422           
423           if (v < 0) {
424               return '';
425           }
426           var state = v> 0 ?  '-checked' : '';
427       
428           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
429                       
430        },
431       width : 75,
432       xns : Roo.grid,
433       '|xns' : 'Roo.grid'
434      }
435     ]
436    }
437   };  }
438 });