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