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