Pman.Dialog.BAdminStaffTwoFactorQRCode.bjs
[Pman.BAdmin] / Pman.Dialog.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.Dialog');
6
7 Pman.Dialog.BAdminStaff= function() {}
8 Roo.apply(Pman.Dialog.BAdminStaff.prototype, {
9
10  _strings : {
11   'ce8ae9da5b7cd6c3df2929543a9af92d' :"Email",
12   '566a352f95c879ff26e50bad767a28dc' :"Group Membership",
13   '4910043d0b2c8c864a0e8672716fee94' :"Is a Member",
14   '28974c2c793e780427dfb571b26443e6' :"Group Name",
15   'bcc254b55c4a1babdf1dcb82c207506b' :"Phone",
16   'a0f852ef8bfccd86a0e7217d7959e3e8' :"Add / Edit User",
17   '3ec365dd533ddb7ef3d1c111186ce872' :"Details",
18   '0bfe42db3eb05bf39f03812166391939' :"Use Secure Passwords",
19   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
20   '6f958ddaf50fd5ade7858ef1d1a63e51' :"Type again to confirm",
21   '49ee3087348e8d44e1feda1917443987' :"Name",
22   'bbbabdbe1b262f75d99d62880b953be1' :"Role",
23   'c9cc8cce247e49bae79f15173ce97354' :"Save",
24   '828e70f83623b262e14187c039df99c0' :"Enable Two-Factor Authentication",
25   'acf45fd8829f809b29c601a3a193804f' :"Set / Change Password",
26   '01028205a11cf95a503c4c1d005989da' :"Generate One"
27  },
28  _named_strings : {
29   'email_placeholder' : 'ce8ae9da5b7cd6c3df2929543a9af92d' /* Email */ ,
30   'secure_passwords_boxLabel' : '0bfe42db3eb05bf39f03812166391939' /* Use Secure Passwords */ ,
31   'name_placeholder' : '49ee3087348e8d44e1feda1917443987' /* Name */ ,
32   'role_fieldLabel' : 'bbbabdbe1b262f75d99d62880b953be1' /* Role */ ,
33   'name_fieldLabel' : '49ee3087348e8d44e1feda1917443987' /* Name */ ,
34   'role_placeholder' : 'bbbabdbe1b262f75d99d62880b953be1' /* Role */ ,
35   'phone_fieldLabel' : 'bcc254b55c4a1babdf1dcb82c207506b' /* Phone */ ,
36   '_enable_oath_key_boxLabel' : '828e70f83623b262e14187c039df99c0' /* Enable Two-Factor Authentication */ ,
37   'email_fieldLabel' : 'ce8ae9da5b7cd6c3df2929543a9af92d' /* Email */ ,
38   'passwd2_placeholder' : '6f958ddaf50fd5ade7858ef1d1a63e51' /* Type again to confirm */ 
39  },
40
41  dialog : false,
42  callback:  false,
43
44  show : function(data, cb)
45  {
46   if (!this.dialog) {
47    this.create();
48   }
49
50   this.callback = cb;
51   this.data = data;
52   this.dialog.show(this.data._el);
53   if (this.form) {
54    this.form.reset();
55    this.form.setValues(data);
56    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
57   }
58
59  },
60
61  create : function()
62  {
63   var _this = this;
64   this.dialog = Roo.factory({
65     xtype : 'Modal',
66     cls : 'add-user-dialog',
67     fit_content : true,
68     max_height : 680,
69     max_width : 650,
70     title : _this._strings['a0f852ef8bfccd86a0e7217d7959e3e8'] /* Add / Edit User */,
71     listeners : {
72      render : function (_self)
73       {
74           _this.dialog = this;
75       }
76     },
77     xns : Roo.bootstrap,
78     '|xns' : 'Roo.bootstrap',
79     buttons : [
80      {
81       xtype : 'Button',
82       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
83       listeners : {
84        click : function (_self, e)
85         {
86             _this.dialog.hide(); 
87         }
88       },
89       xns : Roo.bootstrap,
90       '|xns' : 'Roo.bootstrap'
91      },
92      {
93       xtype : 'Button',
94       html : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
95       weight : 'primary',
96       listeners : {
97        click : function (_self, e)
98         {
99             if(!_this.form.isValid()){
100                 //Roo.bootstrap.MessageBox.alert('Error', 'Please Correct all the errors in red');
101                 return;
102             }
103             
104             var myID = _this.form.findField('id').getValue() * 1;
105             var myName = _this.form.findField('name').getValue();
106         
107             if (_this.form.findField('company_id') && !_this.form.findField('company_id').getValue()) {
108                 Roo.bootstrap.MessageBox.alert("Error", "Select a Company");
109                 return;
110             }
111                 
112                // validate password match (only needed if we are not using generated one..
113             if (_this.form.findField('passwd1') 
114                     && _this.form.findField('passwd1').getValue().length > 0 
115                     && _this.form.findField('passwd1').inputEl().dom.type == "password") {
116                     
117                 var p1 = _this.form.findField('passwd1').getValue();
118                 var p2 = _this.form.findField('passwd2').getValue();
119                     
120                     
121                 if (Pman.Login.authUser.id < 0 && !p1.length) {
122                     Roo.bootstrap.MessageBox.alert("Error", "You must create a password for the admin account");
123                     return;
124                 }
125                     
126                     
127                 if (p1.length || p2.length) {
128                     if (p1 != p2) {
129                         Roo.bootstrap.MessageBox.alert("Error", "Passwords do not match");
130                         return;
131                     }
132                 }
133                     
134                 
135             }
136             
137             // get the list of record with tick
138             
139             _this.form.doAction("submit");
140             
141             return;
142         
143         }
144       },
145       xns : Roo.bootstrap,
146       '|xns' : 'Roo.bootstrap'
147      }
148     ],
149     items  : [
150      {
151       xtype : 'Border',
152       listeners : {
153        render : function (_self)
154         {
155             _this.layout = _self;
156         }
157       },
158       xns : Roo.bootstrap.layout,
159       '|xns' : 'Roo.bootstrap.layout',
160       center : {
161        xtype : 'Region',
162        alwaysShowTabs : true,
163        tabPosition : 'top',
164        xns : Roo.bootstrap.layout,
165        '|xns' : 'Roo.bootstrap.layout'
166       },
167       items  : [
168        {
169         xtype : 'Content',
170         autoScroll : true,
171         background : false,
172         fitContainer : true,
173         fitToFrame : true,
174         id : 'DetailPanel',
175         region : 'center',
176         title : _this._strings['3ec365dd533ddb7ef3d1c111186ce872'] /* Details */,
177         listeners : {
178          activate : function (_self)
179           {
180               /*var url = 'about:blank';
181               
182               if(_this.data.id * 1 > 0){
183                   url = baseURL + '/Coba/Report/ApplicationSummary/' + _this.data.id;
184               }
185                
186               _this.app_summary_frame.el.dom.src = url;*/
187           },
188          render : function (_self)
189           {
190               _this.detail_tab = _self;
191           }
192         },
193         xns : Roo.bootstrap.panel,
194         '|xns' : 'Roo.bootstrap.panel',
195         items  : [
196          {
197           xtype : 'Container',
198           cls : 'col-md-12',
199           xns : Roo.bootstrap,
200           '|xns' : 'Roo.bootstrap',
201           items  : [
202            {
203             xtype : 'Form',
204             errorMask : true,
205             labelAlign : 'top',
206             style : 'margin-top: 20px;',
207             url : baseURL + '/Roo/core_person',
208             listeners : {
209              actioncomplete : function (_self, action)
210               {
211                   if(action.type == 'setdata'){
212                       
213                       _this.layout.showPanel('DetailPanel');
214                       
215                       _this.dialog.setTitle("Add / Edit User");
216                       _this.form.findField('role').setDisabled(false);
217                       
218                       /*
219                       * Use for init -- Call from Pman.Login.js
220                       */
221                       if(
222                           typeof(_this.data.role) != 'undefined' &&
223                           _this.data.role == 'Administrators'
224                       ) {
225                           _this.dialog.setTitle("Create Adminstrator");
226                           _this.form.findField('role').setDisabled(true);
227                       }
228                       
229                       _this.form.findField('passwd1').el.select('input',true).first().dom.type="password";
230                       _this.form.findField('passwd2').show();
231                       _this.passwordbox.collapse();
232                       
233                       _this.form.findField('secure_passwords').setValue(1);
234                       
235                       if(_this.data.id * 1 > 0) {
236                           this.doAction('load',{ method: 'GET', params: { '_id' : _this.data.id }});
237                       }
238                       
239                       
240                       
241                       this.clearInvalid();
242                       
243                       _this.dialog.resize();
244                       
245                       return;
246                   }
247                  
248                   if (action.type == 'load') {
249                       
250                       _this.data = action.result.data;
251                       
252                       // oath handling...
253                       
254                       _this.form.findField('_enable_oath_key').setChecked(false,false);
255                       
256                       if(_this.data.length_oath_key != '0') {
257                           _this.form.findField('_enable_oath_key').setChecked(true,false);
258                       }
259                       
260                       return;
261                   }
262                   
263                   if (action.type == 'submit') { // only submitted here if we are 
264                   
265                       _this.dialog.hide();
266                      
267                       if (_this.callback) {
268                           _this.callback.call(this, action.result.data);
269                       }
270                       
271                       return;
272                   }
273               },
274              render : function (_self)
275               {
276                   _this.form = this;
277               }
278             },
279             xns : Roo.bootstrap,
280             '|xns' : 'Roo.bootstrap',
281             items  : [
282              {
283               xtype : 'Row',
284               xns : Roo.bootstrap,
285               '|xns' : 'Roo.bootstrap',
286               items  : [
287                {
288                 xtype : 'Column',
289                 md : 12,
290                 xns : Roo.bootstrap,
291                 '|xns' : 'Roo.bootstrap',
292                 items  : [
293                  {
294                   xtype : 'Input',
295                   allowBlank : false,
296                   fieldLabel : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
297                   labelAlign : 'left',
298                   name : 'name',
299                   placeholder : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
300                   xns : Roo.bootstrap,
301                   '|xns' : 'Roo.bootstrap'
302                  }
303                 ]
304                }
305               ]
306              },
307              {
308               xtype : 'Row',
309               xns : Roo.bootstrap,
310               '|xns' : 'Roo.bootstrap',
311               items  : [
312                {
313                 xtype : 'Column',
314                 md : 12,
315                 xns : Roo.bootstrap,
316                 '|xns' : 'Roo.bootstrap',
317                 items  : [
318                  {
319                   xtype : 'Input',
320                   fieldLabel : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
321                   labelAlign : 'left',
322                   name : 'role',
323                   placeholder : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
324                   xns : Roo.bootstrap,
325                   '|xns' : 'Roo.bootstrap'
326                  }
327                 ]
328                }
329               ]
330              },
331              {
332               xtype : 'Row',
333               xns : Roo.bootstrap,
334               '|xns' : 'Roo.bootstrap',
335               items  : [
336                {
337                 xtype : 'Column',
338                 md : 12,
339                 xns : Roo.bootstrap,
340                 '|xns' : 'Roo.bootstrap',
341                 items  : [
342                  {
343                   xtype : 'Input',
344                   allowBlank : false,
345                   fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
346                   labelAlign : 'left',
347                   name : 'email',
348                   placeholder : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
349                   vtype : 'email',
350                   xns : Roo.bootstrap,
351                   '|xns' : 'Roo.bootstrap'
352                  }
353                 ]
354                }
355               ]
356              },
357              {
358               xtype : 'Row',
359               xns : Roo.bootstrap,
360               '|xns' : 'Roo.bootstrap',
361               items  : [
362                {
363                 xtype : 'Column',
364                 md : 12,
365                 xns : Roo.bootstrap,
366                 '|xns' : 'Roo.bootstrap',
367                 items  : [
368                  {
369                   xtype : 'Input',
370                   fieldLabel : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
371                   labelAlign : 'left',
372                   name : 'phone',
373                   xns : Roo.bootstrap,
374                   '|xns' : 'Roo.bootstrap'
375                  }
376                 ]
377                }
378               ]
379              },
380              {
381               xtype : 'Row',
382               xns : Roo.bootstrap,
383               '|xns' : 'Roo.bootstrap',
384               items  : [
385                {
386                 xtype : 'Column',
387                 md : 12,
388                 xns : Roo.bootstrap,
389                 '|xns' : 'Roo.bootstrap',
390                 items  : [
391                  {
392                   xtype : 'CheckBox',
393                   boxLabel : _this._strings['828e70f83623b262e14187c039df99c0'] /* Enable Two-Factor Authentication */,
394                   name : '_enable_oath_key',
395                   listeners : {
396                    check : function (_self, checked)
397                     {
398                         if(checked) {
399                             
400                             this.setBoxLabel('Untick to disable Two Factor authentication');
401                             
402                             return;
403                         }
404                         
405                         this.setBoxLabel('Enable Two Factor Authentication');
406                     },
407                    click : function (_self, e)
408                     {
409                         if(!Pman.Login.authUser) {
410                             Roo.bootstrap.MessageBox.alert('Error', 'Please login again');
411                             return;
412                         }
413                         
414                         e.preventDefault();
415                         
416                         if(!this.checked) {
417                             
418                             Pman.Dialog.BAdminStaffTwoFactorQRCode.show(
419                                 {id: _this.data.id},
420                                 function(valid){
421                                    if(valid) {
422                                         _this.dialog.hide({});
423                                         return;
424                                     }
425                                     
426                                     _this.form.findField('_enable_oath_key').setChecked(false,false);
427                                 }
428                             );
429                             
430                             return;
431                         }
432                         
433                         new Pman.Request({
434                             url : baseURL + '/Roo/Core_person',
435                             method :'GET',
436                             params : {
437                                 oath_key_disable: 1,
438                                 id: _this.data.id
439                             },
440                             success : function(res)
441                             {
442                                 switch(res.data) {
443                                     case 'DONE':
444                                         Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
445                                         break;
446                                     default:
447                                         Roo.log('invalid usage');
448                                         break;
449                                 }
450                             },
451                             failure : function(res)
452                             {
453                                 Roo.bootstrap.MessageBox.alert('Error', res);
454                             }
455                         });
456                     }
457                   },
458                   xns : Roo.bootstrap,
459                   '|xns' : 'Roo.bootstrap'
460                  }
461                 ]
462                }
463               ]
464              },
465              {
466               xtype : 'Row',
467               xns : Roo.bootstrap,
468               '|xns' : 'Roo.bootstrap',
469               items  : [
470                {
471                 xtype : 'Column',
472                 md : 12,
473                 xns : Roo.bootstrap,
474                 '|xns' : 'Roo.bootstrap',
475                 items  : [
476                  {
477                   xtype : 'Container',
478                   expandable : true,
479                   expanded : false,
480                   header : _this._strings['acf45fd8829f809b29c601a3a193804f'] /* Set / Change Password */,
481                   panel : 'primary',
482                   listeners : {
483                    render : function (_self)
484                     {
485                         _this.passwordbox = this;
486                     }
487                   },
488                   xns : Roo.bootstrap,
489                   '|xns' : 'Roo.bootstrap',
490                   items  : [
491                    {
492                     xtype : 'Row',
493                     xns : Roo.bootstrap,
494                     '|xns' : 'Roo.bootstrap',
495                     items  : [
496                      {
497                       xtype : 'Column',
498                       xs : 8,
499                       xns : Roo.bootstrap,
500                       '|xns' : 'Roo.bootstrap',
501                       items  : [
502                        {
503                         xtype : 'Input',
504                         inputType : 'password',
505                         name : 'passwd1',
506                         xns : Roo.bootstrap,
507                         '|xns' : 'Roo.bootstrap'
508                        }
509                       ]
510                      },
511                      {
512                       xtype : 'Column',
513                       xs : 4,
514                       xns : Roo.bootstrap,
515                       '|xns' : 'Roo.bootstrap',
516                       items  : [
517                        {
518                         xtype : 'Button',
519                         html : _this._strings['01028205a11cf95a503c4c1d005989da'] /* Generate One */,
520                         style : 'width:100%',
521                         listeners : {
522                          click : function (_self, e)
523                           {
524                               var pw = Math.random().toString(36).replace('0.', '');
525                               _this.form.findField('passwd1').el.select('input',true).first().dom.type="input";
526                               _this.form.findField('passwd1').setValue(pw);
527                               _this.form.findField('passwd2').hide();
528                           }
529                         },
530                         xns : Roo.bootstrap,
531                         '|xns' : 'Roo.bootstrap'
532                        }
533                       ]
534                      }
535                     ]
536                    },
537                    {
538                     xtype : 'Input',
539                     inputType : 'password',
540                     name : 'passwd2',
541                     placeholder : _this._strings['6f958ddaf50fd5ade7858ef1d1a63e51'] /* Type again to confirm */,
542                     xns : Roo.bootstrap,
543                     '|xns' : 'Roo.bootstrap'
544                    },
545                    {
546                     xtype : 'CheckBox',
547                     boxLabel : _this._strings['0bfe42db3eb05bf39f03812166391939'] /* Use Secure Passwords */,
548                     name : 'secure_passwords',
549                     xns : Roo.bootstrap,
550                     '|xns' : 'Roo.bootstrap'
551                    }
552                   ]
553                  }
554                 ]
555                }
556               ]
557              },
558              {
559               xtype : 'Input',
560               inputType : 'hidden',
561               labelAlign : 'left',
562               name : 'id',
563               listeners : {
564                render : function (_self)
565                 {
566                     _this.userID = _self;
567                 }
568               },
569               xns : Roo.bootstrap,
570               '|xns' : 'Roo.bootstrap'
571              },
572              {
573               xtype : 'Input',
574               inputType : 'hidden',
575               name : 'company_id',
576               xns : Roo.bootstrap,
577               '|xns' : 'Roo.bootstrap'
578              }
579             ]
580            }
581           ]
582          }
583         ]
584        },
585        {
586         xtype : 'Grid',
587         background : true,
588         fitContainer : true,
589         fitToFrame : true,
590         region : 'center',
591         title : _this._strings['566a352f95c879ff26e50bad767a28dc'] /* Group Membership */,
592         listeners : {
593          activate : function (_self)
594           {
595               if(_this.option_grid){
596                   _this.option_grid.store.load({});
597               }
598               
599           },
600          render : function (_self)
601           {
602               _this.option_panel = this;
603               
604               
605           }
606         },
607         xns : Roo.bootstrap.panel,
608         '|xns' : 'Roo.bootstrap.panel',
609         grid : {
610          xtype : 'Table',
611          cellSelection : true,
612          cls : 'table-fixed',
613          condensed : true,
614          footerShow : false,
615          loadMask : true,
616          rowSelection : false,
617          listeners : {
618           cellclick : function (_self, el, rowIndex, columnIndex, e)
619            {
620                var di = _this.option_grid.colModel.getDataIndex(columnIndex);
621                
622                /*
623                if (di != 'is_in_group') {
624                    return;
625                }
626                 */
627                var rec = _this.option_grid.store.getAt(rowIndex);
628                
629                if(rec.data.name == 'Administrators' && _this.data.id == Pman.Login.authUser.id){
630                    Roo.bootstrap.MessageBox.alert('Error', 'You can not remove yourself from Administrators group');
631                    return;
632                }
633                
634                rec.set('is_in_group', rec.data.is_in_group * 1 == 1 ? 0 : 1);
635                rec.commit();
636            
637            },
638           render : function (_self)
639            {
640                _this.option_grid = this;
641                
642                this.store.load({})
643            }
644          },
645          xns : Roo.bootstrap,
646          '|xns' : 'Roo.bootstrap',
647          store : {
648           xtype : 'Store',
649           remoteSort : true,
650           sortInfo : { direction : 'ASC', field: 'id' },
651           listeners : {
652            beforeload : function (_self, options)
653             { 
654                 options.params = options.params || {};
655                 
656                 if(_this.data.id * 1 < 1){
657                     _this.option_grid.el.mask('Please save the member first');
658                     this.removeAll();
659                     return false;
660                 }
661                 
662                 options.params._is_in_group = _this.data.id;
663             
664             },
665            update : function (_self, record, operation)
666             {
667                 if (operation != 'commit') {
668                     return;
669                 }
670                 
671                 var params = {
672                     user_ids : _this.data.id,
673                     _action : (record.data.is_in_group * 1 == 0) ? 'sub' : 'add',
674                     group_id : record.data.id
675                 };
676                 
677                 new Pman.Request({
678                     url : baseURL + '/Roo/Core_group',
679                     method : 'POST',
680                     params : params,
681                     success : function() { 
682                         //_this.option_grid.ds.load({});
683                     }
684               });
685             }
686           },
687           xns : Roo.data,
688           '|xns' : 'Roo.data',
689           proxy : {
690            xtype : 'HttpProxy',
691            method : 'GET',
692            url : baseURL + '/Roo/core_group',
693            xns : Roo.data,
694            '|xns' : 'Roo.data'
695           },
696           reader : {
697            xtype : 'JsonReader',
698            fields : [
699                {
700                    'name': 'id',
701                    'type': 'int'
702                },
703                {
704                    'name': 'name',
705                    'type': 'string'
706                },
707                {
708                    'name': 'display_name',
709                    'type': 'string'
710                },
711                {
712                    'name': 'is_in_group',
713                    'type': 'int'
714                }
715            ],
716            id : 'id',
717            root : 'data',
718            xns : Roo.data,
719            '|xns' : 'Roo.data'
720           }
721          },
722          sm : {
723           xtype : 'RowSelectionModel',
724           singleSelect : true,
725           xns : Roo.bootstrap.Table,
726           '|xns' : 'Roo.bootstrap.Table'
727          },
728          cm : [
729           {
730            xtype : 'ColumnModel',
731            align : 'center',
732            cursor : 'pointer',
733            dataIndex : 'is_in_group',
734            header : _this._strings['4910043d0b2c8c864a0e8672716fee94'] /* Is a Member */,
735            renderer : function(v) {  
736            
737                var state = v > 0 ?  'check-' : '';
738                var cls = v > 0 ? 'text-primary' : '';
739                
740                return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
741                     
742             },
743            sortable : false,
744            xs : 3,
745            xns : Roo.grid,
746            '|xns' : 'Roo.grid'
747           },
748           {
749            xtype : 'ColumnModel',
750            cursor : 'pointer',
751            dataIndex : 'display_name',
752            header : _this._strings['28974c2c793e780427dfb571b26443e6'] /* Group Name */,
753            renderer : function(v,x,r) 
754            {
755                var vv = v.length ? v : r.data.name;
756                
757                return String.format('{0}', vv);
758            },
759            sortable : true,
760            xs : 9,
761            xns : Roo.grid,
762            '|xns' : 'Roo.grid'
763           }
764          ]
765         }
766        }
767       ]
768      }
769     ]
770    }  );
771  }
772 });
773 Roo.apply(Pman.Dialog.BAdminStaff, Pman.Dialog.BAdminStaff.prototype);