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