Pman.Dialog.BAdminStaff.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                       this.clearInvalid();
240                       
241                       _this.dialog.resize();
242                       
243                       return;
244                   }
245                  
246                   if (action.type == 'load') {
247                       
248                       _this.data = action.result.data;
249                       
250                       _this.form.findField('_enable_oath_key').setChecked(false,false);
251                       
252                       if(_this.data.length_oath_key.length > 0) {
253                           _this.form.findField('_enable_oath_key').setChecked(true,false);
254                       }
255                       
256                       return;
257                   }
258                   
259                   if (action.type == 'submit') { // only submitted here if we are 
260                   
261                       _this.dialog.hide();
262                      
263                       if (_this.callback) {
264                           _this.callback.call(this, action.result.data);
265                       }
266                       
267                       return;
268                   }
269               },
270              render : function (_self)
271               {
272                   _this.form = this;
273               }
274             },
275             xns : Roo.bootstrap,
276             '|xns' : 'Roo.bootstrap',
277             items  : [
278              {
279               xtype : 'Row',
280               xns : Roo.bootstrap,
281               '|xns' : 'Roo.bootstrap',
282               items  : [
283                {
284                 xtype : 'Column',
285                 md : 12,
286                 xns : Roo.bootstrap,
287                 '|xns' : 'Roo.bootstrap',
288                 items  : [
289                  {
290                   xtype : 'Input',
291                   allowBlank : false,
292                   fieldLabel : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
293                   labelAlign : 'left',
294                   name : 'name',
295                   placeholder : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
296                   xns : Roo.bootstrap,
297                   '|xns' : 'Roo.bootstrap'
298                  }
299                 ]
300                }
301               ]
302              },
303              {
304               xtype : 'Row',
305               xns : Roo.bootstrap,
306               '|xns' : 'Roo.bootstrap',
307               items  : [
308                {
309                 xtype : 'Column',
310                 md : 12,
311                 xns : Roo.bootstrap,
312                 '|xns' : 'Roo.bootstrap',
313                 items  : [
314                  {
315                   xtype : 'Input',
316                   fieldLabel : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
317                   labelAlign : 'left',
318                   name : 'role',
319                   placeholder : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
320                   xns : Roo.bootstrap,
321                   '|xns' : 'Roo.bootstrap'
322                  }
323                 ]
324                }
325               ]
326              },
327              {
328               xtype : 'Row',
329               xns : Roo.bootstrap,
330               '|xns' : 'Roo.bootstrap',
331               items  : [
332                {
333                 xtype : 'Column',
334                 md : 12,
335                 xns : Roo.bootstrap,
336                 '|xns' : 'Roo.bootstrap',
337                 items  : [
338                  {
339                   xtype : 'Input',
340                   allowBlank : false,
341                   fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
342                   labelAlign : 'left',
343                   name : 'email',
344                   placeholder : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
345                   vtype : 'email',
346                   xns : Roo.bootstrap,
347                   '|xns' : 'Roo.bootstrap'
348                  }
349                 ]
350                }
351               ]
352              },
353              {
354               xtype : 'Row',
355               xns : Roo.bootstrap,
356               '|xns' : 'Roo.bootstrap',
357               items  : [
358                {
359                 xtype : 'Column',
360                 md : 12,
361                 xns : Roo.bootstrap,
362                 '|xns' : 'Roo.bootstrap',
363                 items  : [
364                  {
365                   xtype : 'Input',
366                   fieldLabel : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
367                   labelAlign : 'left',
368                   name : 'phone',
369                   xns : Roo.bootstrap,
370                   '|xns' : 'Roo.bootstrap'
371                  }
372                 ]
373                }
374               ]
375              },
376              {
377               xtype : 'Row',
378               xns : Roo.bootstrap,
379               '|xns' : 'Roo.bootstrap',
380               items  : [
381                {
382                 xtype : 'Column',
383                 md : 12,
384                 xns : Roo.bootstrap,
385                 '|xns' : 'Roo.bootstrap',
386                 items  : [
387                  {
388                   xtype : 'CheckBox',
389                   boxLabel : _this._strings['828e70f83623b262e14187c039df99c0'] /* Enable Two-Factor Authentication */,
390                   name : '_enable_oath_key',
391                   listeners : {
392                    check : function (_self, checked)
393                     {
394                         if(checked) {
395                             
396                             this.setBoxLabel('Untick to disable Two Factor authentication');
397                             
398                             return;
399                         }
400                         
401                         this.setBoxLabel('Enable Two Factor Authentication');
402                     },
403                    click : function (_self, e)
404                     {
405                         e.preventDefault();
406                         
407                         if(!this.checked) {
408                             
409                             Pman.Dialog.BAdminStaffTwoFactorQRCode.show(
410                                 {
411                                     id: _this.data.id
412                                 },
413                                 function(){_this.dialog.hide({})}
414                             );
415                             
416                             return;
417                         }
418                         
419                         new Pman.Request({
420                             url : baseURL + '/Roo/Core_person',
421                             method :'GET',
422                             params : {
423                                 oath_key_disable: 1
424                             },
425                             success : function(res)
426                             {
427                                 switch(res.data) {
428                                     case 'DONE':
429                                         Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
430                                         break;
431                                     default:
432                                         Roo.log('invalid usage');
433                                         break;
434                                 }
435                             },
436                             failure : function(res)
437                             {
438                                 Roo.bootstrap.MessageBox.alert('Error', res);
439                             }
440                         });
441                     }
442                   },
443                   xns : Roo.bootstrap,
444                   '|xns' : 'Roo.bootstrap'
445                  }
446                 ]
447                }
448               ]
449              },
450              {
451               xtype : 'Row',
452               xns : Roo.bootstrap,
453               '|xns' : 'Roo.bootstrap',
454               items  : [
455                {
456                 xtype : 'Column',
457                 md : 12,
458                 xns : Roo.bootstrap,
459                 '|xns' : 'Roo.bootstrap',
460                 items  : [
461                  {
462                   xtype : 'Container',
463                   expandable : true,
464                   expanded : false,
465                   header : _this._strings['acf45fd8829f809b29c601a3a193804f'] /* Set / Change Password */,
466                   panel : 'primary',
467                   listeners : {
468                    render : function (_self)
469                     {
470                         _this.passwordbox = this;
471                     }
472                   },
473                   xns : Roo.bootstrap,
474                   '|xns' : 'Roo.bootstrap',
475                   items  : [
476                    {
477                     xtype : 'Row',
478                     xns : Roo.bootstrap,
479                     '|xns' : 'Roo.bootstrap',
480                     items  : [
481                      {
482                       xtype : 'Column',
483                       xs : 8,
484                       xns : Roo.bootstrap,
485                       '|xns' : 'Roo.bootstrap',
486                       items  : [
487                        {
488                         xtype : 'Input',
489                         inputType : 'password',
490                         name : 'passwd1',
491                         xns : Roo.bootstrap,
492                         '|xns' : 'Roo.bootstrap'
493                        }
494                       ]
495                      },
496                      {
497                       xtype : 'Column',
498                       xs : 4,
499                       xns : Roo.bootstrap,
500                       '|xns' : 'Roo.bootstrap',
501                       items  : [
502                        {
503                         xtype : 'Button',
504                         html : _this._strings['01028205a11cf95a503c4c1d005989da'] /* Generate One */,
505                         style : 'width:100%',
506                         listeners : {
507                          click : function (_self, e)
508                           {
509                               var pw = Math.random().toString(36).replace('0.', '');
510                               _this.form.findField('passwd1').el.select('input',true).first().dom.type="input";
511                               _this.form.findField('passwd1').setValue(pw);
512                               _this.form.findField('passwd2').hide();
513                           }
514                         },
515                         xns : Roo.bootstrap,
516                         '|xns' : 'Roo.bootstrap'
517                        }
518                       ]
519                      }
520                     ]
521                    },
522                    {
523                     xtype : 'Input',
524                     inputType : 'password',
525                     name : 'passwd2',
526                     placeholder : _this._strings['6f958ddaf50fd5ade7858ef1d1a63e51'] /* Type again to confirm */,
527                     xns : Roo.bootstrap,
528                     '|xns' : 'Roo.bootstrap'
529                    },
530                    {
531                     xtype : 'CheckBox',
532                     boxLabel : _this._strings['0bfe42db3eb05bf39f03812166391939'] /* Use Secure Passwords */,
533                     name : 'secure_passwords',
534                     xns : Roo.bootstrap,
535                     '|xns' : 'Roo.bootstrap'
536                    }
537                   ]
538                  }
539                 ]
540                }
541               ]
542              },
543              {
544               xtype : 'Input',
545               inputType : 'hidden',
546               labelAlign : 'left',
547               name : 'id',
548               listeners : {
549                render : function (_self)
550                 {
551                     _this.userID = _self;
552                 }
553               },
554               xns : Roo.bootstrap,
555               '|xns' : 'Roo.bootstrap'
556              },
557              {
558               xtype : 'Input',
559               inputType : 'hidden',
560               name : 'company_id',
561               xns : Roo.bootstrap,
562               '|xns' : 'Roo.bootstrap'
563              }
564             ]
565            }
566           ]
567          }
568         ]
569        },
570        {
571         xtype : 'Grid',
572         background : true,
573         fitContainer : true,
574         fitToFrame : true,
575         region : 'center',
576         title : _this._strings['566a352f95c879ff26e50bad767a28dc'] /* Group Membership */,
577         listeners : {
578          activate : function (_self)
579           {
580               if(_this.option_grid){
581                   _this.option_grid.store.load({});
582               }
583               
584           },
585          render : function (_self)
586           {
587               _this.option_panel = this;
588               
589               
590           }
591         },
592         xns : Roo.bootstrap.panel,
593         '|xns' : 'Roo.bootstrap.panel',
594         grid : {
595          xtype : 'Table',
596          cellSelection : true,
597          cls : 'table-fixed',
598          condensed : true,
599          footerShow : false,
600          loadMask : true,
601          rowSelection : false,
602          listeners : {
603           cellclick : function (_self, el, rowIndex, columnIndex, e)
604            {
605                var di = _this.option_grid.colModel.getDataIndex(columnIndex);
606                
607                /*
608                if (di != 'is_in_group') {
609                    return;
610                }
611                 */
612                var rec = _this.option_grid.store.getAt(rowIndex);
613                
614                if(rec.data.name == 'Administrators' && _this.data.id == Pman.Login.authUser.id){
615                    Roo.bootstrap.MessageBox.alert('Error', 'You can not remove yourself from Administrators group');
616                    return;
617                }
618                
619                rec.set('is_in_group', rec.data.is_in_group * 1 == 1 ? 0 : 1);
620                rec.commit();
621            
622            },
623           render : function (_self)
624            {
625                _this.option_grid = this;
626                
627                this.store.load({})
628            }
629          },
630          xns : Roo.bootstrap,
631          '|xns' : 'Roo.bootstrap',
632          store : {
633           xtype : 'Store',
634           remoteSort : true,
635           sortInfo : { direction : 'ASC', field: 'id' },
636           listeners : {
637            beforeload : function (_self, options)
638             { 
639                 options.params = options.params || {};
640                 
641                 if(_this.data.id * 1 < 1){
642                     _this.option_grid.el.mask('Please save the member first');
643                     this.removeAll();
644                     return false;
645                 }
646                 
647                 options.params._is_in_group = _this.data.id;
648             
649             },
650            update : function (_self, record, operation)
651             {
652                 if (operation != 'commit') {
653                     return;
654                 }
655                 
656                 var params = {
657                     user_ids : _this.data.id,
658                     _action : (record.data.is_in_group * 1 == 0) ? 'sub' : 'add',
659                     group_id : record.data.id
660                 };
661                 
662                 new Pman.Request({
663                     url : baseURL + '/Roo/Core_group',
664                     method : 'POST',
665                     params : params,
666                     success : function() { 
667                         //_this.option_grid.ds.load({});
668                     }
669               });
670             }
671           },
672           xns : Roo.data,
673           '|xns' : 'Roo.data',
674           proxy : {
675            xtype : 'HttpProxy',
676            method : 'GET',
677            url : baseURL + '/Roo/core_group',
678            xns : Roo.data,
679            '|xns' : 'Roo.data'
680           },
681           reader : {
682            xtype : 'JsonReader',
683            fields : [
684                {
685                    'name': 'id',
686                    'type': 'int'
687                },
688                {
689                    'name': 'name',
690                    'type': 'string'
691                },
692                {
693                    'name': 'display_name',
694                    'type': 'string'
695                },
696                {
697                    'name': 'is_in_group',
698                    'type': 'int'
699                }
700            ],
701            id : 'id',
702            root : 'data',
703            xns : Roo.data,
704            '|xns' : 'Roo.data'
705           }
706          },
707          sm : {
708           xtype : 'RowSelectionModel',
709           singleSelect : true,
710           xns : Roo.bootstrap.Table,
711           '|xns' : 'Roo.bootstrap.Table'
712          },
713          cm : [
714           {
715            xtype : 'ColumnModel',
716            align : 'center',
717            cursor : 'pointer',
718            dataIndex : 'is_in_group',
719            header : _this._strings['4910043d0b2c8c864a0e8672716fee94'] /* Is a Member */,
720            renderer : function(v) {  
721            
722                var state = v > 0 ?  'check-' : '';
723                var cls = v > 0 ? 'text-primary' : '';
724                
725                return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
726                     
727             },
728            sortable : false,
729            xs : 3,
730            xns : Roo.grid,
731            '|xns' : 'Roo.grid'
732           },
733           {
734            xtype : 'ColumnModel',
735            cursor : 'pointer',
736            dataIndex : 'display_name',
737            header : _this._strings['28974c2c793e780427dfb571b26443e6'] /* Group Name */,
738            renderer : function(v,x,r) 
739            {
740                var vv = v.length ? v : r.data.name;
741                
742                return String.format('{0}', vv);
743            },
744            sortable : true,
745            xs : 9,
746            xns : Roo.grid,
747            '|xns' : 'Roo.grid'
748           }
749          ]
750         }
751        }
752       ]
753      }
754     ]
755    }  );
756  }
757 });
758 Roo.apply(Pman.Dialog.BAdminStaff, Pman.Dialog.BAdminStaff.prototype);