split user management
[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        responsive : true,
477        rowSelection : true,
478        striped : false,
479        listeners : {
480         cellclick : function (_self, el, rowIndex, columnIndex, e)
481          {
482              var di = _this.member_grid.colModel.getDataIndex(columnIndex);
483              
484              if (di != 'active') {
485                  return;
486              }
487               
488              var rec = _this.member_grid.store.getAt(rowIndex);
489              
490              rec.set('active', rec.data.active ? 0 : 1);
491              rec.commit();
492          
493              
494              // get the row number to make class x-row-0, x-row-1
495              
496              if(rec.data.active * 1 != 1){
497                  var el = _this.member_grid.getRowDom(rowIndex);
498                  
499                  el.addClass('x-grid-row-fadeout');
500                  
501                  el.on('transitionend',function(){
502                      _this.member_grid.ds.remove(rec);
503                      el.remove();
504                  },this,{single:true});
505              }
506          },
507         celldblclick : function (_self, el, rowIndex, columnIndex, e)
508          {
509              var di = _this.member_grid.colModel.getDataIndex(columnIndex);
510          
511              if (di == 'active') {
512                  return;
513              }
514              var s = _this.member_grid.store.getAt(rowIndex);
515              
516              if(s.data.id * 1 < 1){
517                  return;
518              }
519              
520              if (di == 'member_of') {
521                  Pman.Dialog.BAdminStaffGroups.show(   s.data , function() {
522                      _this.member_grid.footer.onClick('first');
523                  });
524                  return;
525              }
526              // show edit user dialog..
527               
528              Pman.Dialog.BAdminStaff.show( s.data , function() {
529                  _this.member_grid.footer.onClick('first');
530              });
531               
532          },
533         render : function (_self)
534          {
535              _this.member_grid = _self;
536             
537          }
538        },
539        xns : Roo.bootstrap,
540        '|xns' : 'Roo.bootstrap',
541        footer : {
542         xtype : 'PagingToolbar',
543         displayInfo : false,
544         name : 'footer',
545         pageSize : 25,
546         xns : Roo.bootstrap,
547         '|xns' : 'Roo.bootstrap',
548         buttons : [
549          {
550           xtype : 'Button',
551           cls : 'roo-toolbar-button',
552           html : _this._strings['5bc3fd20294c17c9803942958fd7f26d'] /* Show Inactive */,
553           name : 'activeButton',
554           _offtext : _this._strings['5bc3fd20294c17c9803942958fd7f26d'] /* Show Inactive */,
555           _ontext : _this._strings['b15aafc19dc2ba4b788adf77268d8ca4'] /* Hide Inactive */,
556           pressed : false,
557           weight : 'default',
558           listeners : {
559            render : function (_self)
560             {
561                 _this.footerActiveBtn = this;
562             },
563            toggle : function (_self, e, pressed)
564             {
565                 this.setText(this.pressed ? this._ontext : this._offtext);
566             
567                 _this.member_grid.footer.onClick('first');
568                 
569                 return;
570                 
571             }
572           },
573           xns : Roo.bootstrap,
574           '|xns' : 'Roo.bootstrap'
575          }
576         ]
577        },
578        store : {
579         xtype : 'Store',
580         remoteSort : true,
581         sortInfo : { field: 'name', direction: 'ASC' },
582         listeners : {
583          beforeload : function (_self, options)
584           {
585               if (!Pman.buildCompleted) {
586                   return false;
587               }
588               options.params = options.params || {};
589               
590               //options.params['query[type]'] = 0;
591               //options.params.active = 1;
592               
593               if(!_this.group_grid){
594                   this.removeAll();
595                   return false;
596               }
597               
598               var group = _this.group_grid.getSelectionModel().getSelected();
599               
600               if(!group){
601                   this.removeAll();
602                   return false;
603               }
604               
605               if(_this.footerActiveBtn && !_this.footerActiveBtn.pressed){
606                   options.params.active = 1;
607               }
608               
609               options.params._with_group_membership = 1;
610               options.params['query[name]'] =    _this.searchBox.getValue();
611               
612               options.params['query[in_group]'] = group.data.id;
613             
614           },
615          load : function (_self, records, options)
616           {
617               _this.edit_btn.el.hide();
618               _this.delete_btn.el.hide();
619               _this.addToGroupBtn.el.hide();
620               _this.removeFromGroupBtn.el.hide();
621               _this.switch_btn.el.hide();
622               
623               options.params.active = 1;
624               
625           
626               
627           },
628          update : function (_self, record, operation)
629           {
630               if (operation != 'commit') {
631                   return;
632               }
633               // only used to change active status.
634                
635               new Pman.Request({
636                   url : baseURL + '/Roo/core_person',
637                   method :'POST',
638                   params : {
639                       id : record.data.id,
640                       active: record.data.active
641                       
642                   },
643                   success : function() {
644                       // do nothing
645                       
646                   },
647                   failure : function() 
648                   {
649                       /*Roo.bootstrap.MessageBox.alert("Error", "saving failed", function() {
650                           _this.grid.footer.onClick('first');
651                       });*/
652                   }
653               });
654           }
655         },
656         xns : Roo.data,
657         '|xns' : 'Roo.data',
658         proxy : {
659          xtype : 'HttpProxy',
660          method : 'GET',
661          url : baseURL + '/Roo/core_person',
662          xns : Roo.data,
663          '|xns' : 'Roo.data'
664         },
665         reader : {
666          xtype : 'JsonReader',
667          id : 'id',
668          root : 'data',
669          totalProperty : 'total',
670          xns : Roo.data,
671          '|xns' : 'Roo.data'
672         }
673        },
674        sm : {
675         xtype : 'RowSelectionModel',
676         listeners : {
677          selectionchange : function (_self)
678           {
679               _this.edit_btn.el.hide();
680               _this.delete_btn.el.hide();
681               _this.addToGroupBtn.el.hide();
682               _this.removeFromGroupBtn.el.hide();
683               _this.switch_btn.el.hide();
684               
685               if(!_this.member_grid.getSelectionModel().getSelections().length){
686                   return;
687               }
688               
689               _this.edit_btn.el.show();
690               _this.delete_btn.el.show();
691               _this.switch_btn.el.show();
692               
693               var group = _this.group_grid.getSelectionModel().getSelected();
694               
695               if(!group || group.data.id < 1){
696                   _this.addToGroupBtn.el.show();
697                   return;
698               }
699               
700               _this.removeFromGroupBtn.el.show();
701               
702           }
703         },
704         xns : Roo.bootstrap.Table,
705         '|xns' : 'Roo.bootstrap.Table'
706        },
707        cm : [
708         {
709          xtype : 'ColumnModel',
710          align : 'center',
711          cursor : 'pointer',
712          dataIndex : 'active',
713          header : _this._strings['4d3d769b812b6faa6b76e1a8abaece2d'] /* Active */,
714          md : 1,
715          renderer : function(v) {  
716          
717              var state = v > 0 ?  'check-' : '';
718              var cls = v > 0 ? 'text-primary' : '';
719              
720              return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
721                   
722           },
723          sm : 1,
724          sortable : true,
725          xs : 1,
726          xns : Roo.grid,
727          '|xns' : 'Roo.grid'
728         },
729         {
730          xtype : 'ColumnModel',
731          cursor : 'pointer',
732          dataIndex : 'name',
733          header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
734          md : 3,
735          renderer : function(v,x,r) {
736              if(r.data.active * 1 != 1){
737                  return "<span class='cell-strikethrough'>"+String.format('{0}', v)+"</span>"; 
738              }
739              return String.format('{0}', v);
740          },
741          sm : 3,
742          sortable : true,
743          xs : 3,
744          xns : Roo.grid,
745          '|xns' : 'Roo.grid'
746         },
747         {
748          xtype : 'ColumnModel',
749          cursor : 'pointer',
750          dataIndex : 'role',
751          header : _this._strings['8a25a3ae30ab6e8ceb5b8c4009a3336f'] /* Role / Position */,
752          md : 2,
753          renderer : function(v) { return String.format('{0}', v); },
754          sm : 2,
755          sortable : true,
756          xs : 2,
757          xns : Roo.grid,
758          '|xns' : 'Roo.grid'
759         },
760         {
761          xtype : 'ColumnModel',
762          cursor : 'pointer',
763          dataIndex : 'member_of',
764          header : _this._strings['a37ede293936e29279ed543129451ec3'] /* Groups */,
765          md : 2,
766          renderer : function(v) {
767               return String.format('{0}', v).split("\n").join("<br/>"); 
768           },
769          sm : 2,
770          xs : 2,
771          xns : Roo.grid,
772          '|xns' : 'Roo.grid'
773         },
774         {
775          xtype : 'ColumnModel',
776          cursor : 'pointer',
777          dataIndex : 'email',
778          header : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
779          md : 4,
780          renderer : function (v,x,r) {
781              if(r.data.active * 1 != 1){
782                  return (v.length && v.indexOf('@') > 0 ) ? 
783                      String.format('<a href="mailto:{0}" class="cell-strikethrough">{0}</a>',v) : v;
784              }
785              return (v.length && v.indexOf('@') > 0 ) ? 
786                      String.format('<a href="mailto:{0}">{0}</a>',v) : v;
787                      
788          },
789          sm : 2,
790          sortable : true,
791          xs : 4,
792          xns : Roo.grid,
793          '|xns' : 'Roo.grid'
794         }
795        ]
796       }
797      },
798      {
799       xtype : 'Grid',
800       background : true,
801       closable : false,
802       fitContainer : true,
803       fitToFrame : true,
804       region : 'center',
805       title : _this._strings['25f57527ae8a27c94fb5230b5486c743'] /* Permission List */,
806       listeners : {
807        activate : function (_self)
808         {
809             if(_this.permission_grid) {
810                 _this.permission_grid.store.load({});
811             }
812         },
813        render : function (_self)
814         {
815             _this.permission_panel = this;
816         }
817       },
818       xns : Roo.bootstrap.panel,
819       '|xns' : 'Roo.bootstrap.panel',
820       grid : {
821        xtype : 'Table',
822        cellSelection : true,
823        cls : 'table-fixed',
824        footerShow : false,
825        hover : true,
826        loadMask : true,
827        responsive : 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        responsive : true,
1347        rowSelection : true,
1348        striped : true,
1349        listeners : {
1350         render : function (_self)
1351          {
1352              _this.group_grid = _self; 
1353          
1354              if (_this.group_panel.active) {
1355                  _this.group_grid.store.load({});
1356              }
1357          },
1358         rowdblclick : function (_self, el, rowIndex, e)
1359          {
1360              var sel = _this.group_grid.store.getAt(rowIndex);
1361              
1362              if(!sel || sel.data.id * 1 < 1){
1363                  return;
1364              }
1365              
1366              Pman.Dialog.BAdminGroups.show({ id : sel.data.id }, function(res){
1367                  _this.group_grid.store.load({});
1368              });
1369          },
1370         rowsrendered : function (_self)
1371          {
1372              if(this.ds.getCount() * 1 < 1){
1373                  return;
1374              }
1375              
1376              var sm = _this.group_grid.getSelectionModel();
1377              
1378              sm.selectFirstRow();
1379              sm.fireEvent('afterselectionchange', sm);
1380              
1381          }
1382        },
1383        xns : Roo.bootstrap,
1384        '|xns' : 'Roo.bootstrap',
1385        store : {
1386         xtype : 'Store',
1387         remoteSort : true,
1388         sortInfo : { field: 'name', direction: 'ASC'},
1389         listeners : {
1390          beforeload : function (_self, options)
1391           {
1392               if (!Pman.buildCompleted) {
1393                   return false;
1394               }
1395               options.params = options.params || {};
1396               
1397               options.params.type = 0;
1398               
1399               options.params._add_everyone = 1;
1400           options.params.limit = 999;
1401           }
1402         },
1403         xns : Roo.data,
1404         '|xns' : 'Roo.data',
1405         proxy : {
1406          xtype : 'HttpProxy',
1407          method : 'GET',
1408          url : baseURL + '/Roo/core_group',
1409          xns : Roo.data,
1410          '|xns' : 'Roo.data'
1411         },
1412         reader : {
1413          xtype : 'JsonReader',
1414          fields : [
1415              {
1416                  'name': 'id',
1417                  'type': 'int'
1418              },
1419              {
1420                  'name': 'leader',
1421                  'type': 'string'
1422              },
1423              {
1424                  'name': 'group_member_count',
1425                  'type': 'int'
1426              },
1427              {
1428                  'name': 'display_name',
1429                  'type': 'string'
1430              },
1431              {
1432                  'name': 'name',
1433                  'type': 'string'
1434              }
1435          ],
1436          id : 'id',
1437          root : 'data',
1438          totalProperty : 'total',
1439          xns : Roo.data,
1440          '|xns' : 'Roo.data'
1441         }
1442        },
1443        sm : {
1444         xtype : 'RowSelectionModel',
1445         singleSelect : true,
1446         listeners : {
1447          afterselectionchange : function (_self)
1448           {
1449               if(_this.footerActiveBtn){
1450                   _this.footerActiveBtn.setActive(false);
1451                   _this.footerActiveBtn.fireEvent('toggle', _this.footerActiveBtn);
1452               }
1453               
1454               if(_this.permission_grid){
1455                   _this.permission_grid.store.load({});
1456               }
1457               
1458           }
1459         },
1460         xns : Roo.bootstrap.Table,
1461         '|xns' : 'Roo.bootstrap.Table'
1462        },
1463        cm : [
1464         {
1465          xtype : 'ColumnModel',
1466          cursor : 'pointer',
1467          dataIndex : 'name',
1468          header : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
1469          md : 12,
1470          renderer : function(v,x,r) { 
1471          
1472              if (r.data.id == 0) {
1473                  return '<b>' + "All Staff" + '</b>';
1474              }
1475              
1476              if (r.data.id == -1) {
1477                  return '<b>' + "Not in a Group" + '</b>';
1478              }
1479          
1480              var vv = (r.json.display_name.length) ? r.json.display_name : v;
1481              
1482              if (v == 'Administrators') {
1483                  return '<b>' + vv + '</b>';
1484              }
1485              
1486              if (r.data.leader) {
1487                  return vv + ' (' + r.json.leader_name + ')';
1488              }
1489              
1490              return String.format('{0} ({1})',vv, r.json.group_member_count);
1491          },
1492          sm : 12,
1493          sortable : false,
1494          xs : 12,
1495          xns : Roo.grid,
1496          '|xns' : 'Roo.grid'
1497         }
1498        ]
1499       }
1500      }
1501     ]
1502    }
1503   };  }
1504 });