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