Default to POST for Login
[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                                 allow_close: false,
421                                 allow_cancel : true
422                             }, function(valid){
423                                    if(valid) {
424                                         _this.dialog.hide({});
425                                         return;
426                                     }
427                                     
428                                     _this.form.findField('_enable_oath_key').setChecked(false,false);
429                                 }
430                             );
431                             
432                             return;
433                         }
434                         
435                         new Pman.Request({
436                             url : baseURL + '/Roo/Core_person',
437                             method :'GET',
438                             params : {
439                                 oath_key_disable: 1,
440                                 id: _this.data.id
441                             },
442                             success : function(res)
443                             {
444                                 switch(res.data) {
445                                     case 'DONE':
446                                         Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
447                                         break;
448                                     default:
449                                         Roo.log('invalid usage');
450                                         break;
451                                 }
452                             },
453                             failure : function(res)
454                             {
455                                 Roo.bootstrap.MessageBox.alert('Error', res);
456                             }
457                         });
458                     }
459                   },
460                   xns : Roo.bootstrap,
461                   '|xns' : 'Roo.bootstrap'
462                  }
463                 ]
464                }
465               ]
466              },
467              {
468               xtype : 'Row',
469               xns : Roo.bootstrap,
470               '|xns' : 'Roo.bootstrap',
471               items  : [
472                {
473                 xtype : 'Column',
474                 md : 12,
475                 xns : Roo.bootstrap,
476                 '|xns' : 'Roo.bootstrap',
477                 items  : [
478                  {
479                   xtype : 'Container',
480                   expandable : true,
481                   expanded : false,
482                   header : _this._strings['acf45fd8829f809b29c601a3a193804f'] /* Set / Change Password */,
483                   panel : 'primary',
484                   listeners : {
485                    render : function (_self)
486                     {
487                         _this.passwordbox = this;
488                     }
489                   },
490                   xns : Roo.bootstrap,
491                   '|xns' : 'Roo.bootstrap',
492                   items  : [
493                    {
494                     xtype : 'Row',
495                     xns : Roo.bootstrap,
496                     '|xns' : 'Roo.bootstrap',
497                     items  : [
498                      {
499                       xtype : 'Column',
500                       xs : 8,
501                       xns : Roo.bootstrap,
502                       '|xns' : 'Roo.bootstrap',
503                       items  : [
504                        {
505                         xtype : 'Input',
506                         inputType : 'password',
507                         name : 'passwd1',
508                         xns : Roo.bootstrap,
509                         '|xns' : 'Roo.bootstrap'
510                        }
511                       ]
512                      },
513                      {
514                       xtype : 'Column',
515                       xs : 4,
516                       xns : Roo.bootstrap,
517                       '|xns' : 'Roo.bootstrap',
518                       items  : [
519                        {
520                         xtype : 'Button',
521                         html : _this._strings['01028205a11cf95a503c4c1d005989da'] /* Generate One */,
522                         style : 'width:100%',
523                         listeners : {
524                          click : function (_self, e)
525                           {
526                               var pw = Math.random().toString(36).replace('0.', '');
527                               _this.form.findField('passwd1').el.select('input',true).first().dom.type="input";
528                               _this.form.findField('passwd1').setValue(pw);
529                               _this.form.findField('passwd2').hide();
530                           }
531                         },
532                         xns : Roo.bootstrap,
533                         '|xns' : 'Roo.bootstrap'
534                        }
535                       ]
536                      }
537                     ]
538                    },
539                    {
540                     xtype : 'Input',
541                     inputType : 'password',
542                     name : 'passwd2',
543                     placeholder : _this._strings['6f958ddaf50fd5ade7858ef1d1a63e51'] /* Type again to confirm */,
544                     xns : Roo.bootstrap,
545                     '|xns' : 'Roo.bootstrap'
546                    },
547                    {
548                     xtype : 'CheckBox',
549                     boxLabel : _this._strings['0bfe42db3eb05bf39f03812166391939'] /* Use Secure Passwords */,
550                     name : 'secure_passwords',
551                     xns : Roo.bootstrap,
552                     '|xns' : 'Roo.bootstrap'
553                    }
554                   ]
555                  }
556                 ]
557                }
558               ]
559              },
560              {
561               xtype : 'Input',
562               inputType : 'hidden',
563               labelAlign : 'left',
564               name : 'id',
565               listeners : {
566                render : function (_self)
567                 {
568                     _this.userID = _self;
569                 }
570               },
571               xns : Roo.bootstrap,
572               '|xns' : 'Roo.bootstrap'
573              },
574              {
575               xtype : 'Input',
576               inputType : 'hidden',
577               name : 'company_id',
578               xns : Roo.bootstrap,
579               '|xns' : 'Roo.bootstrap'
580              }
581             ]
582            }
583           ]
584          }
585         ]
586        },
587        {
588         xtype : 'Grid',
589         background : true,
590         fitContainer : true,
591         fitToFrame : true,
592         region : 'center',
593         title : _this._strings['566a352f95c879ff26e50bad767a28dc'] /* Group Membership */,
594         listeners : {
595          activate : function (_self)
596           {
597               if(_this.option_grid){
598                   _this.option_grid.store.load({});
599               }
600               
601           },
602          render : function (_self)
603           {
604               _this.option_panel = this;
605               
606               
607           }
608         },
609         xns : Roo.bootstrap.panel,
610         '|xns' : 'Roo.bootstrap.panel',
611         grid : {
612          xtype : 'Table',
613          cellSelection : true,
614          cls : 'table-fixed',
615          condensed : true,
616          footerShow : false,
617          loadMask : true,
618          rowSelection : false,
619          listeners : {
620           cellclick : function (_self, el, rowIndex, columnIndex, e)
621            {
622                var di = _this.option_grid.colModel.getDataIndex(columnIndex);
623                
624                /*
625                if (di != 'is_in_group') {
626                    return;
627                }
628                 */
629                var rec = _this.option_grid.store.getAt(rowIndex);
630                
631                if(rec.data.name == 'Administrators' && _this.data.id == Pman.Login.authUser.id){
632                    Roo.bootstrap.MessageBox.alert('Error', 'You can not remove yourself from Administrators group');
633                    return;
634                }
635                
636                rec.set('is_in_group', rec.data.is_in_group * 1 == 1 ? 0 : 1);
637                rec.commit();
638            
639            },
640           render : function (_self)
641            {
642                _this.option_grid = this;
643                
644                this.store.load({})
645            }
646          },
647          xns : Roo.bootstrap,
648          '|xns' : 'Roo.bootstrap',
649          store : {
650           xtype : 'Store',
651           remoteSort : true,
652           sortInfo : { direction : 'ASC', field: 'id' },
653           listeners : {
654            beforeload : function (_self, options)
655             { 
656                 options.params = options.params || {};
657                 
658                 if(_this.data.id * 1 < 1){
659                     _this.option_grid.el.mask('Please save the member first');
660                     this.removeAll();
661                     return false;
662                 }
663                 
664                 options.params._is_in_group = _this.data.id;
665             
666             },
667            update : function (_self, record, operation)
668             {
669                 if (operation != 'commit') {
670                     return;
671                 }
672                 
673                 var params = {
674                     user_ids : _this.data.id,
675                     _action : (record.data.is_in_group * 1 == 0) ? 'sub' : 'add',
676                     group_id : record.data.id
677                 };
678                 
679                 new Pman.Request({
680                     url : baseURL + '/Roo/Core_group',
681                     method : 'POST',
682                     params : params,
683                     success : function() { 
684                         //_this.option_grid.ds.load({});
685                     }
686               });
687             }
688           },
689           xns : Roo.data,
690           '|xns' : 'Roo.data',
691           proxy : {
692            xtype : 'HttpProxy',
693            method : 'GET',
694            url : baseURL + '/Roo/core_group',
695            xns : Roo.data,
696            '|xns' : 'Roo.data'
697           },
698           reader : {
699            xtype : 'JsonReader',
700            fields : [
701                {
702                    'name': 'id',
703                    'type': 'int'
704                },
705                {
706                    'name': 'name',
707                    'type': 'string'
708                },
709                {
710                    'name': 'display_name',
711                    'type': 'string'
712                },
713                {
714                    'name': 'is_in_group',
715                    'type': 'int'
716                }
717            ],
718            id : 'id',
719            root : 'data',
720            xns : Roo.data,
721            '|xns' : 'Roo.data'
722           }
723          },
724          sm : {
725           xtype : 'RowSelectionModel',
726           singleSelect : true,
727           xns : Roo.bootstrap.Table,
728           '|xns' : 'Roo.bootstrap.Table'
729          },
730          cm : [
731           {
732            xtype : 'ColumnModel',
733            align : 'center',
734            cursor : 'pointer',
735            dataIndex : 'is_in_group',
736            header : _this._strings['4910043d0b2c8c864a0e8672716fee94'] /* Is a Member */,
737            renderer : function(v) {  
738            
739                var state = v > 0 ?  'check-' : '';
740                var cls = v > 0 ? 'text-primary' : '';
741                
742                return '<i class=\"far fa-'+ state + 'square-o ' + cls + '\" aria-hidden=\"true\"></i>';
743                     
744             },
745            sortable : false,
746            xs : 3,
747            xns : Roo.grid,
748            '|xns' : 'Roo.grid'
749           },
750           {
751            xtype : 'ColumnModel',
752            cursor : 'pointer',
753            dataIndex : 'display_name',
754            header : _this._strings['28974c2c793e780427dfb571b26443e6'] /* Group Name */,
755            renderer : function(v,x,r) 
756            {
757                var vv = v.length ? v : r.data.name;
758                
759                return String.format('{0}', vv);
760            },
761            sortable : true,
762            xs : 9,
763            xns : Roo.grid,
764            '|xns' : 'Roo.grid'
765           }
766          ]
767         }
768        }
769       ]
770      }
771     ]
772    }  );
773  }
774 });
775 Roo.apply(Pman.Dialog.BAdminStaff, Pman.Dialog.BAdminStaff.prototype);