Pman.Tab.BAdminStaff.bjs
[Pman.BAdmin] / Pman.Tab.BAdminStaff.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.BAdminStaff = new Roo.XComponent({
8
9  _strings : {
10   'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
11   'b15aafc19dc2ba4b788adf77268d8ca4' :"Hide Inactive",
12   'f29c99f082755399839b64ebaf9f608a' :"List / View",
13   '4f3cdff2e6a5e08440be182ef40d93f7' :"Print / Export",
14   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
15   'a37ede293936e29279ed543129451ec3' :"Groups",
16   '7dce122004969d56ae2e0245cb754d35' :"Edit",
17   '05b763f7d24f32575493b3c23f299b0e' :"Add To Group",
18   'aba9f7d7443652e858969bfc280690b1' :"Manage Groups ",
19   'e0a7cc944485bdedafb92b0cf98632fa' :"Remove From Group",
20   'bcc254b55c4a1babdf1dcb82c207506b' :"Phone",
21   '25f57527ae8a27c94fb5230b5486c743' :"Permission List",
22   '09f0c5159c5e34504e453eff3fc70324' :"Account Management",
23   '054176c3a541fb2d4b63e29360c749aa' :"Members List",
24   '8a25a3ae30ab6e8ceb5b8c4009a3336f' :"Role / Position",
25   '17050e1914aff1e423a84e76db8ab0d1' :"[All]",
26   '5bc3fd20294c17c9803942958fd7f26d' :"Show Inactive",
27   '4d1c8263ba1036754f8db14a98f9f006' :"Reload",
28   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
29   'ec3249f16ee5880d4c1acb752e5c925f' :"Switch to Selected User",
30   '4d3d769b812b6faa6b76e1a8abaece2d' :"Active",
31   '49ee3087348e8d44e1feda1917443987' :"Name",
32   'e55f75a29310d7b60f7ac1d390c8ae42' :"Module",
33   'ed5dea09095f671b801bee34ea28a319' :"Permission"
34  },
35  _named_strings : {
36   'activeButton_offtext' : '5bc3fd20294c17c9803942958fd7f26d' /* Show Inactive */ ,
37   'activeButton_ontext' : 'b15aafc19dc2ba4b788adf77268d8ca4' /* Hide Inactive */ ,
38   'activeButton_html' : '5bc3fd20294c17c9803942958fd7f26d' /* Show Inactive */ 
39  },
40
41   part     :  ["BAdmin", "Staff" ],
42   order    : '003-Pman.Tab.BAdminStaff',
43   region   : 'center',
44   parent   : 'Pman.Tab.BAdmin',
45   name     : "unnamed module",
46   disabled : false, 
47   permname : '', 
48   _tree : function(_data)
49   {
50    var _this = this;
51    var MODULE = this;
52    return {
53    xtype : 'Nest',
54    background : true,
55    title : _this._strings['09f0c5159c5e34504e453eff3fc70324'] /* Account Management */,
56    listeners : {
57     activate : function (_self)
58      {
59          if ( _this.group_grid) {
60               _this.group_grid.store.load({});
61          }
62      }
63    },
64    xns : Roo.bootstrap.panel,
65    '|xns' : 'Roo.bootstrap.panel',
66    layout : {
67     xtype : 'Border',
68     xns : Roo.bootstrap.layout,
69     '|xns' : 'Roo.bootstrap.layout',
70     center : {
71      xtype : 'Region',
72      tabPosition : 'top',
73      xns : Roo.bootstrap.layout,
74      '|xns' : 'Roo.bootstrap.layout'
75     },
76     west : {
77      xtype : 'Region',
78      split : true,
79      tabPosition : 'top',
80      width : 250,
81      xns : Roo.bootstrap.layout,
82      '|xns' : 'Roo.bootstrap.layout'
83     },
84     items  : [
85      {
86       xtype : 'Grid',
87       background : false,
88       closable : false,
89       fitContainer : true,
90       fitToFrame : true,
91       region : 'center',
92       title : _this._strings['054176c3a541fb2d4b63e29360c749aa'] /* Members List */,
93       listeners : {
94        activate : function (_self)
95         {
96             _this.edit_btn.el.hide();
97             _this.delete_btn.el.hide();
98             _this.addToGroupBtn.el.hide();
99             _this.removeFromGroupBtn.el.hide();
100             _this.switch_btn.el.hide();
101         
102             if(_this.member_grid) {
103                 _this.member_grid.footer.onClick('first');
104             }
105         },
106        render : function (_self)
107         {
108             _this.member_panel = _self; 
109         }
110       },
111       xns : Roo.bootstrap.panel,
112       '|xns' : 'Roo.bootstrap.panel',
113       toolbar : {
114        xtype : 'NavSimplebar',
115        xns : Roo.bootstrap,
116        '|xns' : 'Roo.bootstrap',
117        items  : [
118         {
119          xtype : 'NavGroup',
120          xns : Roo.bootstrap,
121          '|xns' : 'Roo.bootstrap',
122          items  : [
123           {
124            xtype : 'NavItem',
125            xns : Roo.bootstrap,
126            '|xns' : 'Roo.bootstrap',
127            items  : [
128             {
129              xtype : 'Element',
130              xns : Roo.bootstrap,
131              '|xns' : 'Roo.bootstrap',
132              items  : [
133               {
134                xtype : 'Row',
135                cls : 'roo-toolbar',
136                xns : Roo.bootstrap,
137                '|xns' : 'Roo.bootstrap',
138                items  : [
139                 {
140                  xtype : 'Column',
141                  md : 12,
142                  xns : Roo.bootstrap,
143                  '|xns' : 'Roo.bootstrap',
144                  items  : [
145                   {
146                    xtype : 'Button',
147                    cls : 'roo-toolbar-button',
148                    glyphicon : 'plus',
149                    html : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
150                    weight : 'default',
151                    listeners : {
152                     click : function (_self, e)
153                      {
154                          Pman.Dialog.BAdminStaff.show({ 
155                              id : 0,
156                              company_id : Pman.Login.authUser.company_id
157                          }, function(res) {
158                          
159                              if(res.length_oath_key * 1 < 1){
160                                  _this.member_grid.footer.onClick('first');
161                                  return;
162                              }
163                              
164                              Pman.Dialog.BAdminStaffTwoFactorQRCode.show({
165                                  id : res.id
166                              }, function(res){
167                                  _this.member_grid.footer.onClick('first');
168                              });
169                          }); 
170                      
171                      }
172                    },
173                    xns : Roo.bootstrap,
174                    '|xns' : 'Roo.bootstrap'
175                   },
176                   {
177                    xtype : 'Button',
178                    cls : 'roo-toolbar-button',
179                    glyphicon : 'edit',
180                    html : _this._strings['7dce122004969d56ae2e0245cb754d35'] /* Edit */,
181                    weight : 'default',
182                    listeners : {
183                     click : function (_self, e)
184                      {
185                          var sel = _this.member_grid.getSelectionModel().getSelections();
186                          
187                          if(!sel.length){
188                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a person');
189                              return;
190                          }
191                          
192                          if(sel.length > 1){
193                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a single person');
194                              return;
195                          }
196                          
197                          var s = _this.member_grid.getSelectionModel().getSelected();
198                          
199                          if(s.data.id * 1 < 1){
200                              Roo.bootstrap.MessageBox.alert('Error', 'Invalid person');
201                              return;
202                          }
203                          
204                          Pman.Dialog.BAdminStaff.show( { id : s.data.id }, function() {
205                              _this.member_grid.footer.onClick('first');
206                          });
207                          
208                      },
209                     render : function (_self)
210                      {
211                          _this.edit_btn = this;
212                          
213                          this.el.setVisibilityMode(Roo.Element.DISPLAY);
214                          
215                          this.el.hide();
216                      }
217                    },
218                    xns : Roo.bootstrap,
219                    '|xns' : 'Roo.bootstrap'
220                   },
221                   {
222                    xtype : 'Button',
223                    cls : 'roo-toolbar-button',
224                    glyphicon : 'trash',
225                    html : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
226                    weight : 'primary',
227                    listeners : {
228                     click : function (_self, e)
229                      {
230                          // from pman.js
231                          Pman.genericDelete(_this.member_panel, 'core_person');
232                          
233                          
234                      },
235                     render : function (_self)
236                      {
237                          _this.delete_btn = this;
238                          
239                          this.el.setVisibilityMode(Roo.Element.DISPLAY);
240                          
241                          this.el.hide();
242                      }
243                    },
244                    xns : Roo.bootstrap,
245                    '|xns' : 'Roo.bootstrap'
246                   },
247                   {
248                    xtype : 'Button',
249                    cls : 'roo-toolbar-button',
250                    glyphicon : 'plus',
251                    html : _this._strings['05b763f7d24f32575493b3c23f299b0e'] /* Add To Group */,
252                    weight : 'default',
253                    listeners : {
254                     click : function (_self, e)
255                      {
256                          var sel = _this.member_grid.getSelectionModel().getSelections();
257                          
258                          if(!sel.length){
259                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a person');
260                              return;
261                          }
262                          
263                          var ids = [];
264                          
265                          Roo.each(sel, function(r){
266                              if(r.data.id * 1 < 1){
267                                  return;
268                              }
269                              
270                              ids.push(r.data.id);
271                          });
272                          
273                          if(!ids.length){
274                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a person');
275                              return;
276                          }
277                          
278                          Pman.Dialog.BAdminAddToGroup.show({
279                              user_ids : ids.join(',')
280                              
281                          }, function(res){
282                              _this.member_grid.footer.onClick('first');
283                          });
284                          
285                      },
286                     render : function (_self)
287                      {
288                          _this.addToGroupBtn = this;
289                          
290                          this.el.setVisibilityMode(Roo.Element.DISPLAY);
291                          
292                          this.el.hide();
293                      }
294                    },
295                    xns : Roo.bootstrap,
296                    '|xns' : 'Roo.bootstrap'
297                   },
298                   {
299                    xtype : 'Button',
300                    cls : 'roo-toolbar-button',
301                    glyphicon : 'trash',
302                    html : _this._strings['e0a7cc944485bdedafb92b0cf98632fa'] /* Remove From Group */,
303                    weight : 'default',
304                    listeners : {
305                     click : function (_self, e)
306                      {
307                          var sel = _this.member_grid.getSelectionModel().getSelections();
308                          
309                          if(!sel.length){
310                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a person');
311                              return;
312                          }
313                          
314                          var ids = [];
315                          
316                          Roo.each(sel, function(r){
317                              if(r.data.id * 1 < 1){
318                                  return;
319                              }
320                              
321                              ids.push(r.data.id);
322                          });
323                          
324                          if(!ids.length){
325                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a person');
326                              return;
327                          }
328                          
329                          var group = _this.group_grid.getSelectionModel().getSelected();
330                          
331                          if(!group || group.data.id < 1){
332                              Roo.bootstrap.MessageBox.alert('Error', 'Please select a group');
333                              return;
334                          }
335                          
336                          new Pman.Request({
337                              url: baseURL + '/Roo/Core_group',
338                              method: 'POST',
339                              params: {
340                                  group_id : group.data.id,
341                                  _action : 'sub',
342                                  user_ids : ids.join(',')
343                              },
344                              success: function(res){
345                                  _this.member_grid.footer.onClick('first');
346                                  return;
347                              }
348                          });
349                          
350                          
351                      },
352                     render : function (_self)
353                      {
354                          _this.removeFromGroupBtn = this;
355                          
356                          this.el.setVisibilityMode(Roo.Element.DISPLAY);
357                          
358                          this.el.hide();
359                      }
360                    },
361                    xns : Roo.bootstrap,
362                    '|xns' : 'Roo.bootstrap'
363                   },
364                   {
365                    xtype : 'Button',
366                    cls : 'roo-toolbar-button',
367                    glyphicon : 'user',
368                    html : _this._strings['ec3249f16ee5880d4c1acb752e5c925f'] /* Switch to Selected User */,
369                    weight : 'default',
370                    listeners : {
371                     click : function (_self, e)
372                      {
373                          var s = _this.member_grid.getSelectionModel().getSelections();
374                          
375                          if (s.length != 1)  {
376                              Roo.MessageBox.alert("Error",  "Select a Person");
377                              return;
378                          }
379                          
380                          new Pman.Request({
381                              url : baseURL+ '/Login.php',
382                              params  :{
383                                  'switch' : s[0].data.id
384                              },
385                              method : 'GET',
386                              success : function() {
387                                  document.location = baseURL + '?ts=' + Math.random();
388                                  
389                              }, 
390                              failure : function(d) {
391                                  Roo.log(d);
392                                  Roo.MessageBox.alert("Error",  d);
393                              }
394                          });
395                      },
396                     render : function (_self)
397                      {
398                          _this.switch_btn = this;
399                          
400                          this.el.setVisibilityMode(Roo.Element.DISPLAY);
401                          
402                          this.el.hide();
403                      }
404                    },
405                    xns : Roo.bootstrap,
406                    '|xns' : 'Roo.bootstrap'
407                   }
408                  ]
409                 }
410                ]
411               }
412              ]
413             }
414            ]
415           }
416          ]
417         }
418        ]
419       },
420       grid : {
421        xtype : 'Table',
422        cellSelection : true,
423        cls : 'table-fixed',
424        hover : true,
425        loadMask : true,
426        responsive : true,
427        rowSelection : true,
428        striped : false,
429        listeners : {
430         cellclick : function (_self, el, rowIndex, columnIndex, e)
431          {
432              var di = _this.member_grid.colModel.getDataIndex(columnIndex);
433              
434              if (di != 'active') {
435                  return;
436              }
437               
438              var rec = _this.member_grid.store.getAt(rowIndex);
439              
440              rec.set('active', rec.data.active ? 0 : 1);
441              rec.commit();
442          
443              
444              // get the row number to make class x-row-0, x-row-1
445              
446              if(rec.data.active * 1 != 1){
447                  var el = _this.member_grid.getRowDom(rowIndex);
448                  
449                  el.addClass('x-grid-row-fadeout');
450                  
451                  el.on('transitionend',function(){
452                      _this.member_grid.ds.remove(rec);
453                      el.remove();
454                  },this,{single:true});
455              }
456          },
457         render : function (_self)
458          {
459              _this.member_grid = _self;
460             
461          },
462         rowdblclick : function (_self, el, rowIndex, e)
463          {
464              var s = _this.member_grid.store.getAt(rowIndex);
465              
466              if(s.data.id * 1 < 1){
467                  return;
468              }
469              
470              Pman.Dialog.BAdminStaff.show( { id : s.data.id }, function() {
471                  _this.member_grid.footer.onClick('first');
472              });
473          }
474        },
475        xns : Roo.bootstrap,
476        '|xns' : 'Roo.bootstrap',
477        footer : {
478         xtype : 'PagingToolbar',
479         displayInfo : false,
480         name : 'footer',
481         pageSize : 25,
482         xns : Roo.bootstrap,
483         '|xns' : 'Roo.bootstrap',
484         buttons : [
485          {
486           xtype : 'Button',
487           cls : 'btn btn-default',
488           html : _this._strings['5bc3fd20294c17c9803942958fd7f26d'] /* Show Inactive */,
489           name : 'activeButton',
490           _offtext : _this._strings['5bc3fd20294c17c9803942958fd7f26d'] /* Show Inactive */,
491           _ontext : _this._strings['b15aafc19dc2ba4b788adf77268d8ca4'] /* Hide Inactive */,
492           pressed : false,
493           style : 'margin-left: 10px;',
494           listeners : {
495            render : function (_self)
496             {
497                 _this.footerActiveBtn = this;
498             },
499            toggle : function (_self, e, pressed)
500             {
501                 this.setText(this.pressed ? this._ontext : this._offtext);
502             
503                 _this.member_grid.footer.onClick('first');
504                 
505                 return;
506                 
507             }
508           },
509           xns : Roo.bootstrap,
510           '|xns' : 'Roo.bootstrap'
511          }
512         ]
513        },
514        store : {
515         xtype : 'Store',
516         remoteSort : true,
517         sortInfo : { field: 'name', direction: 'ASC' },
518         listeners : {
519          beforeload : function (_self, options)
520           {
521               if (!Pman.buildCompleted) {
522                   return false;
523               }
524               options.params = options.params || {};
525               
526               //options.params['query[type]'] = 0;
527               //options.params.active = 1;
528               
529               if(!_this.group_grid){
530                   this.removeAll();
531                   return false;
532               }
533               
534               var group = _this.group_grid.getSelectionModel().getSelected();
535               
536               if(!group){
537                   this.removeAll();
538                   return false;
539               }
540               
541               if(_this.footerActiveBtn && !_this.footerActiveBtn.pressed){
542                   options.params.active = 1;
543               }
544               
545               options.params['query[in_group]'] = group.data.id;
546           
547           },
548          load : function (_self, records, options)
549           {
550               _this.edit_btn.el.hide();
551               _this.delete_btn.el.hide();
552               _this.addToGroupBtn.el.hide();
553               _this.removeFromGroupBtn.el.hide();
554               _this.switch_btn.el.hide();
555               
556               options.params.active = 1;
557               
558           
559               
560           },
561          update : function (_self, record, operation)
562           {
563               if (operation != 'commit') {
564                   return;
565               }
566               // only used to change active status.
567                
568               new Pman.Request({
569                   url : baseURL + '/Roo/core_person',
570                   method :'POST',
571                   params : {
572                       id : record.data.id,
573                       active: record.data.active
574                       
575                   },
576                   success : function() {
577                       // do nothing
578                       
579                   },
580                   failure : function() 
581                   {
582                       /*Roo.bootstrap.MessageBox.alert("Error", "saving failed", function() {
583                           _this.grid.footer.onClick('first');
584                       });*/
585                   }
586               });
587           }
588         },
589         xns : Roo.data,
590         '|xns' : 'Roo.data',
591         proxy : {
592          xtype : 'HttpProxy',
593          method : 'GET',
594          url : baseURL + '/Roo/core_person',
595          xns : Roo.data,
596          '|xns' : 'Roo.data'
597         },
598         reader : {
599          xtype : 'JsonReader',
600          id : 'id',
601          root : 'data',
602          totalProperty : 'total',
603          xns : Roo.data,
604          '|xns' : 'Roo.data'
605         }
606        },
607        sm : {
608         xtype : 'RowSelectionModel',
609         listeners : {
610          selectionchange : function (_self)
611           {
612               _this.edit_btn.el.hide();
613               _this.delete_btn.el.hide();
614               _this.addToGroupBtn.el.hide();
615               _this.removeFromGroupBtn.el.hide();
616               _this.switch_btn.el.hide();
617               
618               if(!_this.member_grid.getSelectionModel().getSelections().length){
619                   return;
620               }
621               
622               _this.edit_btn.el.show();
623               _this.delete_btn.el.show();
624               _this.switch_btn.el.show();
625               
626               var group = _this.group_grid.getSelectionModel().getSelected();
627               
628               if(!group || group.data.id < 1){
629                   _this.addToGroupBtn.el.show();
630                   return;
631               }
632               
633               _this.removeFromGroupBtn.el.show();
634               
635           }
636         },
637         xns : Roo.bootstrap.Table,
638         '|xns' : 'Roo.bootstrap.Table'
639        },
640        cm : [
641         {
642          xtype : 'ColumnModel',
643          align : 'center',
644          cursor : 'pointer',
645          dataIndex : 'active',
646          header : _this._strings['4d3d769b812b6faa6b76e1a8abaece2d'] /* Active */,
647          md : 1,
648          renderer : function(v) {  
649          
650              var state = v > 0 ?  'check-' : '';
651              var cls = v > 0 ? 'text-primary' : '';
652              
653              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
654                          
655           },
656          sm : 1,
657          sortable : true,
658          xs : 1,
659          xns : Roo.grid,
660          '|xns' : 'Roo.grid'
661         },
662         {
663          xtype : 'ColumnModel',
664          cursor : 'pointer',
665          dataIndex : 'name',
666          header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
667          md : 3,
668          renderer : function(v,x,r) {
669              if(r.data.active * 1 != 1){
670                  return "<span class='cell-strikethrough'>"+String.format('{0}', v)+"</span>"; 
671              }
672              return String.format('{0}', v);
673          },
674          sm : 3,
675          sortable : true,
676          xs : 3,
677          xns : Roo.grid,
678          '|xns' : 'Roo.grid'
679         },
680         {
681          xtype : 'ColumnModel',
682          cursor : 'pointer',
683          dataIndex : 'role',
684          header : _this._strings['8a25a3ae30ab6e8ceb5b8c4009a3336f'] /* Role / Position */,
685          md : 2,
686          renderer : function(v) { return String.format('{0}', v); },
687          sm : 2,
688          sortable : true,
689          xs : 2,
690          xns : Roo.grid,
691          '|xns' : 'Roo.grid'
692         },
693         {
694          xtype : 'ColumnModel',
695          cursor : 'pointer',
696          dataIndex : 'phone',
697          header : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
698          md : 2,
699          renderer : function(v) { return String.format('{0}', v); },
700          sm : 2,
701          xs : 2,
702          xns : Roo.grid,
703          '|xns' : 'Roo.grid'
704         },
705         {
706          xtype : 'ColumnModel',
707          cursor : 'pointer',
708          dataIndex : 'email',
709          header : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
710          md : 4,
711          renderer : function (v,x,r) {
712              if(r.data.active * 1 != 1){
713                  return (v.length && v.indexOf('@') > 0 ) ? 
714                      String.format('<a href="mailto:{0}" class="cell-strikethrough">{0}</a>',v) : v;
715              }
716              return (v.length && v.indexOf('@') > 0 ) ? 
717                      String.format('<a href="mailto:{0}">{0}</a>',v) : v;
718                      
719          },
720          sm : 4,
721          sortable : true,
722          xs : 4,
723          xns : Roo.grid,
724          '|xns' : 'Roo.grid'
725         }
726        ]
727       }
728      },
729      {
730       xtype : 'Grid',
731       background : true,
732       closable : false,
733       fitContainer : true,
734       fitToFrame : true,
735       region : 'center',
736       title : _this._strings['25f57527ae8a27c94fb5230b5486c743'] /* Permission List */,
737       listeners : {
738        activate : function (_self)
739         {
740             if(_this.permission_grid) {
741                 _this.permission_grid.store.load({});
742             }
743         },
744        render : function (_self)
745         {
746             _this.permission_panel = this;
747         }
748       },
749       xns : Roo.bootstrap.panel,
750       '|xns' : 'Roo.bootstrap.panel',
751       grid : {
752        xtype : 'Table',
753        cellSelection : true,
754        cls : 'table-fixed',
755        footerShow : false,
756        hover : true,
757        loadMask : true,
758        responsive : true,
759        rowSelection : true,
760        striped : true,
761        listeners : {
762         cellclick : function (_self, el, rowIndex, columnIndex, e)
763          {
764              var di = _this.permission_grid.colModel.getDataIndex(columnIndex);
765              
766              var r = _this.permission_grid.store.getAt(rowIndex);
767              
768              if(di == 'rightname' || di == 'descript' || r.data.id * 1 < 1) {
769                  return;
770              }
771              
772              if(di == 'id'){
773                  
774                  var accessmask = r.data.accessmask.split('').sort().join('');
775                  var fullmask = r.data.FullMask.split('').sort().join('');
776                  
777                  r.set('accessmask', (accessmask == fullmask) ? '' : r.data.FullMask);
778                  
779                  r.commit();
780                  
781                  return;
782              }
783              
784              var mapping = {
785                  'add' : 'A',
786                  'edit' : 'E',
787                  'delete' : 'D',
788                  'view' : 'S',
789                  'print' : 'P'
790              };
791              
792              var target = mapping[di];
793              
794              if(r.data.FullMask.indexOf(target) === -1){
795                  return;
796              }
797              
798              var accessmask = r.data.accessmask.split('');
799              
800              if(accessmask.indexOf(target) !== -1){
801                  accessmask.splice(accessmask.indexOf(target), 1);
802              } else {
803                  accessmask.push(target);
804              }
805              
806              r.set('accessmask', accessmask.sort().join(''));
807              
808              r.commit();
809              
810          },
811         render : function (_self)
812          {
813              _this.permission_grid = this;
814              
815              if(_this.permission_panel.active) {
816                  (function(){
817                      _this.permission_grid.store.load({});
818                  }).defer(50);
819              }
820          }
821        },
822        xns : Roo.bootstrap,
823        '|xns' : 'Roo.bootstrap',
824        store : {
825         xtype : 'Store',
826         remoteSort : true,
827         sortInfo : { field: 'rightname', direction: 'ASC' },
828         listeners : {
829          beforeload : function (_self, o)
830           {
831               if (!Pman.buildCompleted) {
832                   return false;
833               }
834               var group = _this.group_grid.getSelectionModel().getSelected();
835               
836               if(!group){
837                   _this.permission_panel.el.mask('Please select a group');
838                   this.removeAll();
839                   return false;
840               }
841               
842               if(group.data.id * 1 < 1){
843                   _this.permission_panel.el.mask('You can not set permissions for this group');
844                   this.removeAll();
845                   return false;
846               }
847               
848               _this.permission_panel.el.unmask();
849               
850               o.params = o.params || {};
851                
852               o.params._sort = 1;    
853               o.params.group_id = group.data.id;
854           
855           },
856          update : function (_self, record, operation)
857           {
858               if (operation != 'commit') {
859                   return;
860               }
861           
862               var group = _this.group_grid.getSelectionModel().getSelected();
863               
864               if(!group || group.data.id * 1 < 1){
865                   return;
866               }
867               
868               var params = {};
869               
870               params.group_id = group.data.id;
871               
872               params['dataUpdate[' + record.data.id + ']'] = record.data.accessmask;
873               
874               new Pman.Request({
875                   url : baseURL + '/Admin/GroupRights',
876                   method :'POST',
877                   params : params,
878                   success : function() {
879                       // do nothing
880                   },
881                   failure : function() 
882                   {
883                       Roo.bootstrap.MessageBox.alert("Error", "saving failed", function() {
884                           _this.permission_grid.store.load({});
885                       });
886                   }
887               });
888               
889           }
890         },
891         xns : Roo.data,
892         '|xns' : 'Roo.data',
893         proxy : {
894          xtype : 'HttpProxy',
895          method : 'GET',
896          url : baseURL + '/BAdmin/GroupRights.php',
897          xns : Roo.data,
898          '|xns' : 'Roo.data'
899         },
900         reader : {
901          xtype : 'JsonReader',
902          fields : [
903              {
904                  'name': 'id',
905                  'type': 'int'
906              },
907              {
908                  'name': 'rightname',
909                  'type': 'string'
910              },
911              {
912                  'name': 'descript',
913                  'type': 'string'
914              },
915              {
916                  'name': 'accessmask',
917                  'type': 'string'
918              },
919              {
920                  'name': 'FullMask',
921                  'type': 'string'
922              },
923              {
924                  'name': 'group_id',
925                  'type': 'int'
926              }
927          ],
928          id : 'id',
929          root : 'data',
930          totalProperty : 'total',
931          xns : Roo.data,
932          '|xns' : 'Roo.data'
933         }
934        },
935        sm : {
936         xtype : 'RowSelectionModel',
937         singleSelect : true,
938         xns : Roo.bootstrap.Table,
939         '|xns' : 'Roo.bootstrap.Table'
940        },
941        cm : [
942         {
943          xtype : 'ColumnModel',
944          align : 'center',
945          dataIndex : 'id',
946          header : _this._strings['17050e1914aff1e423a84e76db8ab0d1'] /* [All] */,
947          renderer : function (v,x,r) {
948              
949              if (!r.data.FullMask.length) {
950                  return '';
951              }
952              
953              var accessmask = r.data.accessmask.split('').sort().join('');
954              var fullmask = r.data.FullMask.split('').sort().join('');
955              
956              var state = (accessmask == fullmask) ? 'check-' : '';
957              
958              var cls = (accessmask == fullmask) ? 'text-primary' : '';
959              
960              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
961              
962          },
963          sortable : false,
964          xs : 1,
965          xns : Roo.grid,
966          '|xns' : 'Roo.grid'
967         },
968         {
969          xtype : 'ColumnModel',
970          dataIndex : 'rightname',
971          header : _this._strings['e55f75a29310d7b60f7ac1d390c8ae42'] /* Module */,
972          renderer : function (v) {
973              return String.format('<span tooltip="{1}">{0}</span>', v.split('.').shift(), v);
974          },
975          xs : 2,
976          xns : Roo.grid,
977          '|xns' : 'Roo.grid'
978         },
979         {
980          xtype : 'ColumnModel',
981          dataIndex : 'descript',
982          header : _this._strings['ed5dea09095f671b801bee34ea28a319'] /* Permission */,
983          renderer : function (v) {
984              return String.format('{0}', v ? v : '');
985          },
986          xs : 4,
987          xns : Roo.grid,
988          '|xns' : 'Roo.grid'
989         },
990         {
991          xtype : 'ColumnModel',
992          align : 'center',
993          dataIndex : 'add',
994          header : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
995          renderer : function (v,x,r) {
996              
997              if (r.data.FullMask.indexOf('A') === -1) {
998                  return '';
999              }
1000              
1001              var state = (r.data.accessmask.indexOf('A') !== -1) ? 'check-' : '';
1002              var cls = (r.data.accessmask.indexOf('A') !== -1) ? 'text-primary' : '';
1003              
1004              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
1005          },
1006          sortable : false,
1007          xs : 1,
1008          xns : Roo.grid,
1009          '|xns' : 'Roo.grid'
1010         },
1011         {
1012          xtype : 'ColumnModel',
1013          align : 'center',
1014          dataIndex : 'edit',
1015          header : _this._strings['7dce122004969d56ae2e0245cb754d35'] /* Edit */,
1016          renderer : function (v,x,r) {
1017              
1018              if (r.data.FullMask.indexOf('E') === -1) {
1019                  return '';
1020              }
1021              
1022              var state = (r.data.accessmask.indexOf('E') !== -1) ? 'check-' : '';
1023              var cls = (r.data.accessmask.indexOf('E') !== -1) ? 'text-primary' : '';
1024              
1025              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
1026          },
1027          sortable : false,
1028          xs : 1,
1029          xns : Roo.grid,
1030          '|xns' : 'Roo.grid'
1031         },
1032         {
1033          xtype : 'ColumnModel',
1034          align : 'center',
1035          dataIndex : 'delete',
1036          header : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1037          renderer : function (v,x,r) {
1038              
1039              if (r.data.FullMask.indexOf('D') === -1) {
1040                  return '';
1041              }
1042              
1043              var state = (r.data.accessmask.indexOf('D') !== -1) ? 'check-' : '';
1044              var cls = (r.data.accessmask.indexOf('D') !== -1) ? 'text-primary' : '';
1045              
1046              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
1047              
1048          },
1049          sortable : false,
1050          xs : 1,
1051          xns : Roo.grid,
1052          '|xns' : 'Roo.grid'
1053         },
1054         {
1055          xtype : 'ColumnModel',
1056          align : 'center',
1057          dataIndex : 'view',
1058          header : _this._strings['f29c99f082755399839b64ebaf9f608a'] /* List / View */,
1059          renderer : function (v,x,r) {
1060              
1061              if (r.data.FullMask.indexOf('S') === -1) {
1062                  return '';
1063              }
1064              
1065              var state = (r.data.accessmask.indexOf('S') !== -1) ? 'check-' : '';
1066              var cls = (r.data.accessmask.indexOf('S') !== -1) ? 'text-primary' : '';
1067              
1068              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
1069              
1070          },
1071          sortable : false,
1072          xs : 1,
1073          xns : Roo.grid,
1074          '|xns' : 'Roo.grid'
1075         },
1076         {
1077          xtype : 'ColumnModel',
1078          align : 'center',
1079          dataIndex : 'print',
1080          header : _this._strings['4f3cdff2e6a5e08440be182ef40d93f7'] /* Print / Export */,
1081          renderer : function (v,x,r) {
1082              
1083              if (r.data.FullMask.indexOf('P') === -1) {
1084                  return '';
1085              }
1086              
1087              var state = (r.data.accessmask.indexOf('P') !== -1) ? 'check-' : '';
1088              var cls = (r.data.accessmask.indexOf('P') !== -1) ? 'text-primary' : '';
1089              
1090              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
1091              
1092          },
1093          sortable : false,
1094          xs : 1,
1095          xns : Roo.grid,
1096          '|xns' : 'Roo.grid'
1097         }
1098        ]
1099       }
1100      },
1101      {
1102       xtype : 'Grid',
1103       background : false,
1104       fitContainer : true,
1105       fitToFrame : true,
1106       region : 'west',
1107       title : _this._strings['a37ede293936e29279ed543129451ec3'] /* Groups */,
1108       listeners : {
1109        activate : function (_self)
1110         {
1111             if (_this.group_grid) {
1112                 _this.group_grid.store.load({});
1113             }
1114         },
1115        render : function (_self)
1116         {
1117             _this.group_panel = _self;
1118         }
1119       },
1120       xns : Roo.bootstrap.panel,
1121       '|xns' : 'Roo.bootstrap.panel',
1122       toolbar : {
1123        xtype : 'NavSimplebar',
1124        xns : Roo.bootstrap,
1125        '|xns' : 'Roo.bootstrap',
1126        items  : [
1127         {
1128          xtype : 'NavGroup',
1129          xns : Roo.bootstrap,
1130          '|xns' : 'Roo.bootstrap',
1131          items  : [
1132           {
1133            xtype : 'NavSidebarItem',
1134            glyphicon : 'menu-hamburger',
1135            html : _this._strings['aba9f7d7443652e858969bfc280690b1'] /* Manage Groups  */,
1136            preventDefault : true,
1137            xns : Roo.bootstrap,
1138            '|xns' : 'Roo.bootstrap',
1139            menu : {
1140             xtype : 'Menu',
1141             xns : Roo.bootstrap,
1142             '|xns' : 'Roo.bootstrap',
1143             items  : [
1144              {
1145               xtype : 'MenuItem',
1146               fa : 'fa fa-plus',
1147               html : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
1148               isContainer : false,
1149               preventDefault : true,
1150               listeners : {
1151                click : function (_self, e)
1152                 {
1153                     Pman.Dialog.BAdminGroups.show({ id : 0 }, function(res){
1154                         _this.group_grid.store.load({});
1155                     });
1156                 }
1157               },
1158               xns : Roo.bootstrap,
1159               '|xns' : 'Roo.bootstrap'
1160              },
1161              {
1162               xtype : 'MenuItem',
1163               fa : 'fa fa-pencil',
1164               html : _this._strings['7dce122004969d56ae2e0245cb754d35'] /* Edit */,
1165               isContainer : false,
1166               preventDefault : true,
1167               listeners : {
1168                click : function (_self, e)
1169                 {
1170                     var sel = _this.group_grid.getSelectionModel().getSelected();
1171                     
1172                     if(!sel){
1173                         Roo.bootstrap.MessageBox.alert('Error', 'Please select a group');
1174                         return;
1175                     }
1176                     
1177                     if(sel.data.id * 1 < 1){
1178                         Roo.bootstrap.MessageBox.alert('Error', 'The selected group is not editable');
1179                         return;
1180                     }
1181                     
1182                     Pman.Dialog.BAdminGroups.show({ id : sel.data.id }, function(res){
1183                         _this.group_grid.store.load({});
1184                     });
1185                 }
1186               },
1187               xns : Roo.bootstrap,
1188               '|xns' : 'Roo.bootstrap'
1189              },
1190              {
1191               xtype : 'MenuItem',
1192               fa : 'fa fa-trash',
1193               html : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1194               isContainer : false,
1195               preventDefault : true,
1196               listeners : {
1197                click : function (_self, e)
1198                 {
1199                     var sel = _this.group_grid.getSelectionModel().getSelected();
1200                     
1201                     if(!sel){
1202                         Roo.bootstrap.MessageBox.alert('Error', 'Please select a group');
1203                         return;
1204                     }
1205                     
1206                     if(sel.data.id * 1 < 1){
1207                         Roo.bootstrap.MessageBox.alert('Error', 'The selected group is not editable');
1208                         return;
1209                     }
1210                     
1211                     var deleteIt = function()
1212                     {
1213                         new Pman.Request({
1214                             url: baseURL + '/Roo/Core_group',
1215                             method: 'POST',
1216                             params: {
1217                                 _delete : sel.data.id
1218                             },
1219                             success: function(res){
1220                                 _this.group_grid.store.load({});
1221                                 return;
1222                             }
1223                         });
1224                     }
1225                     
1226                     Roo.bootstrap.MessageBox.confirm('Confirm', 'Are you sure to delete the group?',function(ret) {
1227                         
1228                         if(ret == 'no'){
1229                             return;
1230                         }
1231                         
1232                         deleteIt();
1233                         
1234                      }, this);
1235                     
1236                     
1237                 }
1238               },
1239               xns : Roo.bootstrap,
1240               '|xns' : 'Roo.bootstrap'
1241              },
1242              {
1243               xtype : 'MenuItem',
1244               fa : 'fa fa-refresh',
1245               html : _this._strings['4d1c8263ba1036754f8db14a98f9f006'] /* Reload */,
1246               isContainer : false,
1247               preventDefault : true,
1248               listeners : {
1249                click : function (_self, e)
1250                 {
1251                     _this.group_grid.store.load({});
1252                 }
1253               },
1254               xns : Roo.bootstrap,
1255               '|xns' : 'Roo.bootstrap'
1256              }
1257             ]
1258            }
1259           }
1260          ]
1261         }
1262        ]
1263       },
1264       grid : {
1265        xtype : 'Table',
1266        cls : 'table-fixed',
1267        footerShow : false,
1268        hover : true,
1269        loadMask : true,
1270        responsive : true,
1271        rowSelection : true,
1272        striped : true,
1273        listeners : {
1274         render : function (_self)
1275          {
1276              _this.group_grid = _self; 
1277          
1278              if (_this.group_panel.active) {
1279                  _this.group_grid.store.load({});
1280              }
1281          },
1282         rowdblclick : function (_self, el, rowIndex, e)
1283          {
1284              var sel = _this.group_grid.store.getAt(rowIndex);
1285              
1286              if(!sel || sel.data.id * 1 < 1){
1287                  return;
1288              }
1289              
1290              Pman.Dialog.BAdminGroups.show({ id : sel.data.id }, function(res){
1291                  _this.group_grid.store.load({});
1292              });
1293          },
1294         rowsrendered : function (_self)
1295          {
1296              if(this.ds.getCount() * 1 < 1){
1297                  return;
1298              }
1299              
1300              var sm = _this.group_grid.getSelectionModel();
1301              
1302              sm.selectFirstRow();
1303              sm.fireEvent('afterselectionchange', sm);
1304              
1305          }
1306        },
1307        xns : Roo.bootstrap,
1308        '|xns' : 'Roo.bootstrap',
1309        store : {
1310         xtype : 'Store',
1311         remoteSort : true,
1312         sortInfo : { field: 'name', direction: 'ASC'},
1313         listeners : {
1314          beforeload : function (_self, options)
1315           {
1316               if (!Pman.buildCompleted) {
1317                   return false;
1318               }
1319               options.params = options.params || {};
1320               
1321               options.params.type = 0;
1322               
1323               options.params._add_everyone = 1;
1324           
1325           }
1326         },
1327         xns : Roo.data,
1328         '|xns' : 'Roo.data',
1329         proxy : {
1330          xtype : 'HttpProxy',
1331          method : 'GET',
1332          url : baseURL + '/Roo/core_group',
1333          xns : Roo.data,
1334          '|xns' : 'Roo.data'
1335         },
1336         reader : {
1337          xtype : 'JsonReader',
1338          fields : [
1339              {
1340                  'name': 'id',
1341                  'type': 'int'
1342              },
1343              {
1344                  'name': 'leader',
1345                  'type': 'string'
1346              },
1347              {
1348                  'name': 'group_member_count',
1349                  'type': 'int'
1350              },
1351              {
1352                  'name': 'display_name',
1353                  'type': 'string'
1354              },
1355              {
1356                  'name': 'name',
1357                  'type': 'string'
1358              }
1359          ],
1360          id : 'id',
1361          root : 'data',
1362          totalProperty : 'total',
1363          xns : Roo.data,
1364          '|xns' : 'Roo.data'
1365         }
1366        },
1367        sm : {
1368         xtype : 'RowSelectionModel',
1369         singleSelect : true,
1370         listeners : {
1371          afterselectionchange : function (_self)
1372           {
1373               if(_this.footerActiveBtn){
1374                   _this.footerActiveBtn.setActive(false);
1375                   _this.footerActiveBtn.fireEvent('toggle', _this.footerActiveBtn);
1376               }
1377               
1378               if(_this.permission_grid){
1379                   _this.permission_grid.store.load({});
1380               }
1381               
1382           }
1383         },
1384         xns : Roo.bootstrap.Table,
1385         '|xns' : 'Roo.bootstrap.Table'
1386        },
1387        cm : [
1388         {
1389          xtype : 'ColumnModel',
1390          cursor : 'pointer',
1391          dataIndex : 'name',
1392          header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
1393          md : 12,
1394          renderer : function(v,x,r) { 
1395          
1396              if (r.data.id == 0) {
1397                  return '<b>' + "All Staff" + '</b>';
1398              }
1399              
1400              if (r.data.id == -1) {
1401                  return '<b>' + "Not in a Group" + '</b>';
1402              }
1403              Roo.log(r);
1404              var vv = (r.data.display_name.length) ? r.data.display_name : v;
1405              
1406              if (v == 'Administrators') {
1407                  return '<b>' + vv + '</b>';
1408              }
1409              
1410              if (r.data.leader) {
1411                  return vv + ' (' + r.data.leader_name + ')';
1412              }
1413              
1414              return String.format('{0} ({1})',vv, r.data.group_member_count);
1415          },
1416          sm : 12,
1417          sortable : false,
1418          xs : 12,
1419          xns : Roo.grid,
1420          '|xns' : 'Roo.grid'
1421         }
1422        ]
1423       }
1424      }
1425     ]
1426    }
1427   };  }
1428 });