PHP8
[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   'bcc254b55c4a1babdf1dcb82c207506b' :"Phone",
13   'a0f852ef8bfccd86a0e7217d7959e3e8' :"Add / Edit User",
14   '0bfe42db3eb05bf39f03812166391939' :"Use Secure Passwords",
15   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
16   '6f958ddaf50fd5ade7858ef1d1a63e51' :"Type again to confirm",
17   'bbbabdbe1b262f75d99d62880b953be1' :"Role",
18   '49ee3087348e8d44e1feda1917443987' :"Name",
19   'c9cc8cce247e49bae79f15173ce97354' :"Save",
20   '828e70f83623b262e14187c039df99c0' :"Enable Two-Factor Authentication",
21   'acf45fd8829f809b29c601a3a193804f' :"Set / Change Password",
22   '01028205a11cf95a503c4c1d005989da' :"Generate One"
23  },
24  _named_strings : {
25   'email_placeholder' : 'ce8ae9da5b7cd6c3df2929543a9af92d' /* Email */ ,
26   'secure_passwords_boxLabel' : '0bfe42db3eb05bf39f03812166391939' /* Use Secure Passwords */ ,
27   'name_placeholder' : '49ee3087348e8d44e1feda1917443987' /* Name */ ,
28   'role_fieldLabel' : 'bbbabdbe1b262f75d99d62880b953be1' /* Role */ ,
29   'name_fieldLabel' : '49ee3087348e8d44e1feda1917443987' /* Name */ ,
30   'role_placeholder' : 'bbbabdbe1b262f75d99d62880b953be1' /* Role */ ,
31   'phone_fieldLabel' : 'bcc254b55c4a1babdf1dcb82c207506b' /* Phone */ ,
32   '_enable_oath_key_boxLabel' : '828e70f83623b262e14187c039df99c0' /* Enable Two-Factor Authentication */ ,
33   'email_fieldLabel' : 'ce8ae9da5b7cd6c3df2929543a9af92d' /* Email */ ,
34   'passwd2_placeholder' : '6f958ddaf50fd5ade7858ef1d1a63e51' /* Type again to confirm */ 
35  },
36
37  dialog : false,
38  callback:  false,
39
40  show : function(data, cb)
41  {
42   if (!this.dialog) {
43    this.create();
44   }
45
46   this.callback = cb;
47   this.data = data;
48   this.dialog.show.apply(this.dialog,  Array.prototype.slice.call(arguments).slice(2));
49   if (this.form) {
50    this.form.reset();
51    this.form.setValues(data);
52    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
53   }
54
55  },
56
57  create : function()
58  {
59   var _this = this;
60   this.dialog = Roo.factory({
61     xtype : 'Modal',
62     cls : 'add-user-dialog',
63     fit_content : true,
64     title : _this._strings['a0f852ef8bfccd86a0e7217d7959e3e8'] /* Add / Edit User */,
65     listeners : {
66      render : function (_self)
67       {
68           _this.dialog = this;
69       }
70     },
71     xns : Roo.bootstrap,
72     '|xns' : 'Roo.bootstrap',
73     buttons : [
74      {
75       xtype : 'Button',
76       html : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
77       listeners : {
78        click : function (_self, e)
79         {
80             _this.dialog.hide(); 
81         }
82       },
83       xns : Roo.bootstrap,
84       '|xns' : 'Roo.bootstrap'
85      },
86      {
87       xtype : 'Button',
88       html : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
89       weight : 'primary',
90       listeners : {
91        click : function (_self, e)
92         {
93             if(!_this.form.isValid()){
94                 //Roo.bootstrap.MessageBox.alert('Error', 'Please Correct all the errors in red');
95                 return;
96             }
97             
98             var myID = _this.form.findField('id').getValue() * 1;
99             var myName = _this.form.findField('name').getValue();
100         
101             if (_this.form.findField('company_id') && !_this.form.findField('company_id').getValue()) {
102                 Roo.bootstrap.MessageBox.alert("Error", "Select a Company");
103                 return;
104             }
105                 
106                // validate password match (only needed if we are not using generated one..
107             if (_this.form.findField('passwd1') 
108                     && _this.form.findField('passwd1').getValue().length > 0 
109                     && _this.form.findField('passwd1').inputEl().dom.type == "password") {
110                     
111                 var p1 = _this.form.findField('passwd1').getValue();
112                 var p2 = _this.form.findField('passwd2').getValue();
113                     
114                     
115                 if (Pman.Login.authUser.id < 0 && !p1.length) {
116                     Roo.bootstrap.MessageBox.alert("Error", "You must create a password for the admin account");
117                     return;
118                 }
119                     
120                     
121                 if (p1.length || p2.length) {
122                     if (p1 != p2) {
123                         Roo.bootstrap.MessageBox.alert("Error", "Passwords do not match");
124                         return;
125                     }
126                 }
127                     
128                 
129             }
130             
131             // get the list of record with tick
132             
133             _this.form.doAction("submit");
134             
135             return;
136         
137         }
138       },
139       xns : Roo.bootstrap,
140       '|xns' : 'Roo.bootstrap'
141      }
142     ],
143     items  : [
144      {
145       xtype : 'Form',
146       errorMask : true,
147       labelAlign : 'top',
148       style : 'margin-top: 20px;',
149       url : baseURL + '/Roo/core_person',
150       listeners : {
151        actioncomplete : function (_self, action)
152         {
153             if(action.type == 'setdata'){
154                 
155                // _this.layout.showPanel('DetailPanel');
156                 
157                 _this.dialog.setTitle(_this.data.id *1 > 0 ? "Edit User: " + _this.data.name : 'Add User');
158                 _this.form.findField('role').setDisabled(false);
159                 
160                 /*
161                 * Use for init -- Call from Pman.Login.js
162                 */
163                 if(
164                     typeof(_this.data.role) != 'undefined' &&
165                     _this.data.role == 'Administrators'
166                 ) {
167                     _this.dialog.setTitle("Create Adminstrator");
168                     _this.form.findField('role').setDisabled(true);
169                 }
170                 
171                 _this.form.findField('passwd1').el.select('input',true).first().dom.type="password";
172                 _this.form.findField('passwd2').show();
173                 _this.passwordbox.collapse();
174                 
175                 _this.form.findField('secure_passwords').setValue(1);
176                 
177                 if(_this.data.id * 1 > 0) {
178                     this.doAction('load',{ method: 'GET', params: { '_id' : _this.data.id }});
179                 }
180                 
181                 
182                 
183                 this.clearInvalid();
184                 
185                 _this.dialog.resize();
186                 
187                 return;
188             }
189            
190             if (action.type == 'load') {
191                 
192                 _this.data = action.result.data;
193                 
194                 // oath handling...
195                 
196                 _this.form.findField('_enable_oath_key').setChecked(false,false);
197                 
198                 if(_this.data.length_oath_key != '0') {
199                     _this.form.findField('_enable_oath_key').setChecked(true,false);
200                 }
201                 
202                 return;
203             }
204             
205             if (action.type == 'submit') { // only submitted here if we are 
206             
207                 _this.dialog.hide();
208                
209                 if (_this.callback) {
210                     _this.callback.call(this, action.result.data);
211                 }
212                 
213                 return;
214             }
215         },
216        render : function (_self)
217         {
218             _this.form = this;
219         }
220       },
221       xns : Roo.bootstrap,
222       '|xns' : 'Roo.bootstrap',
223       items  : [
224        {
225         xtype : 'Row',
226         xns : Roo.bootstrap,
227         '|xns' : 'Roo.bootstrap',
228         items  : [
229          {
230           xtype : 'Column',
231           md : 12,
232           xns : Roo.bootstrap,
233           '|xns' : 'Roo.bootstrap',
234           items  : [
235            {
236             xtype : 'Input',
237             allowBlank : false,
238             fieldLabel : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
239             labelAlign : 'left',
240             name : 'name',
241             placeholder : _this._strings['49ee3087348e8d44e1feda1917443987'] /* Name */,
242             xns : Roo.bootstrap,
243             '|xns' : 'Roo.bootstrap'
244            }
245           ]
246          }
247         ]
248        },
249        {
250         xtype : 'Row',
251         xns : Roo.bootstrap,
252         '|xns' : 'Roo.bootstrap',
253         items  : [
254          {
255           xtype : 'Column',
256           md : 12,
257           xns : Roo.bootstrap,
258           '|xns' : 'Roo.bootstrap',
259           items  : [
260            {
261             xtype : 'Input',
262             fieldLabel : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
263             labelAlign : 'left',
264             name : 'role',
265             placeholder : _this._strings['bbbabdbe1b262f75d99d62880b953be1'] /* Role */,
266             xns : Roo.bootstrap,
267             '|xns' : 'Roo.bootstrap'
268            }
269           ]
270          }
271         ]
272        },
273        {
274         xtype : 'Row',
275         xns : Roo.bootstrap,
276         '|xns' : 'Roo.bootstrap',
277         items  : [
278          {
279           xtype : 'Column',
280           md : 12,
281           xns : Roo.bootstrap,
282           '|xns' : 'Roo.bootstrap',
283           items  : [
284            {
285             xtype : 'Input',
286             allowBlank : false,
287             fieldLabel : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
288             labelAlign : 'left',
289             name : 'email',
290             placeholder : _this._strings['ce8ae9da5b7cd6c3df2929543a9af92d'] /* Email */,
291             vtype : 'email',
292             xns : Roo.bootstrap,
293             '|xns' : 'Roo.bootstrap'
294            }
295           ]
296          }
297         ]
298        },
299        {
300         xtype : 'Row',
301         xns : Roo.bootstrap,
302         '|xns' : 'Roo.bootstrap',
303         items  : [
304          {
305           xtype : 'Column',
306           md : 12,
307           xns : Roo.bootstrap,
308           '|xns' : 'Roo.bootstrap',
309           items  : [
310            {
311             xtype : 'Input',
312             fieldLabel : _this._strings['bcc254b55c4a1babdf1dcb82c207506b'] /* Phone */,
313             labelAlign : 'left',
314             name : 'phone',
315             xns : Roo.bootstrap,
316             '|xns' : 'Roo.bootstrap'
317            }
318           ]
319          }
320         ]
321        },
322        {
323         xtype : 'Row',
324         xns : Roo.bootstrap,
325         '|xns' : 'Roo.bootstrap',
326         items  : [
327          {
328           xtype : 'Column',
329           md : 12,
330           xns : Roo.bootstrap,
331           '|xns' : 'Roo.bootstrap',
332           items  : [
333            {
334             xtype : 'CheckBox',
335             boxLabel : _this._strings['828e70f83623b262e14187c039df99c0'] /* Enable Two-Factor Authentication */,
336             name : '_enable_oath_key',
337             listeners : {
338              check : function (_self, checked)
339               {
340                   if(checked) {
341                       
342                       this.setBoxLabel('Untick to disable Two Factor authentication');
343                       
344                       return;
345                   }
346                   
347                   this.setBoxLabel('Enable Two Factor Authentication');
348               },
349              click : function (_self, e)
350               {
351                   if(!Pman.Login.authUser) {
352                       Roo.bootstrap.MessageBox.alert('Error', 'Please login again');
353                       return;
354                   }
355                   
356                   e.preventDefault();
357                   
358                   if(!this.checked) {
359                       
360                       Pman.Dialog.BAdminStaffTwoFactorQRCode.show({
361                           id: _this.data.id,
362                           allow_close: false,
363                           allow_cancel : true
364                       }, function(valid){
365                              if(valid) {
366                                   _this.dialog.hide({});
367                                   return;
368                               }
369                               
370                               _this.form.findField('_enable_oath_key').setChecked(false,false);
371                           }
372                       );
373                       
374                       return;
375                   }
376                   
377                   new Pman.Request({
378                       url : baseURL + '/Roo/Core_person',
379                       method :'GET',
380                       params : {
381                           oath_key_disable: 1,
382                           id: _this.data.id
383                       },
384                       success : function(res)
385                       {
386                           switch(res.data) {
387                               case 'DONE':
388                                   Roo.bootstrap.MessageBox.alert('Success', 'The two factor authentication has been disabled');
389                                   break;
390                               default:
391                                   Roo.log('invalid usage');
392                                   break;
393                           }
394                       },
395                       failure : function(res)
396                       {
397                           Roo.bootstrap.MessageBox.alert('Error', res);
398                       }
399                   });
400               }
401             },
402             xns : Roo.bootstrap,
403             '|xns' : 'Roo.bootstrap'
404            }
405           ]
406          }
407         ]
408        },
409        {
410         xtype : 'Row',
411         xns : Roo.bootstrap,
412         '|xns' : 'Roo.bootstrap',
413         items  : [
414          {
415           xtype : 'Column',
416           md : 12,
417           xns : Roo.bootstrap,
418           '|xns' : 'Roo.bootstrap',
419           items  : [
420            {
421             xtype : 'Container',
422             expandable : true,
423             expanded : false,
424             header : _this._strings['acf45fd8829f809b29c601a3a193804f'] /* Set / Change Password */,
425             panel : 'primary',
426             listeners : {
427              render : function (_self)
428               {
429                   _this.passwordbox = this;
430               }
431             },
432             xns : Roo.bootstrap,
433             '|xns' : 'Roo.bootstrap',
434             items  : [
435              {
436               xtype : 'Row',
437               xns : Roo.bootstrap,
438               '|xns' : 'Roo.bootstrap',
439               items  : [
440                {
441                 xtype : 'Column',
442                 xs : 8,
443                 xns : Roo.bootstrap,
444                 '|xns' : 'Roo.bootstrap',
445                 items  : [
446                  {
447                   xtype : 'Input',
448                   inputType : 'password',
449                   name : 'passwd1',
450                   xns : Roo.bootstrap,
451                   '|xns' : 'Roo.bootstrap'
452                  }
453                 ]
454                },
455                {
456                 xtype : 'Column',
457                 xs : 4,
458                 xns : Roo.bootstrap,
459                 '|xns' : 'Roo.bootstrap',
460                 items  : [
461                  {
462                   xtype : 'Button',
463                   html : _this._strings['01028205a11cf95a503c4c1d005989da'] /* Generate One */,
464                   style : 'width:100%',
465                   listeners : {
466                    click : function (_self, e)
467                     {
468                         var pw = Math.random().toString(36).replace('0.', '');
469                         _this.form.findField('passwd1').el.select('input',true).first().dom.type="input";
470                         _this.form.findField('passwd1').setValue(pw);
471                         _this.form.findField('passwd2').hide();
472                     }
473                   },
474                   xns : Roo.bootstrap,
475                   '|xns' : 'Roo.bootstrap'
476                  }
477                 ]
478                }
479               ]
480              },
481              {
482               xtype : 'Input',
483               inputType : 'password',
484               name : 'passwd2',
485               placeholder : _this._strings['6f958ddaf50fd5ade7858ef1d1a63e51'] /* Type again to confirm */,
486               xns : Roo.bootstrap,
487               '|xns' : 'Roo.bootstrap'
488              },
489              {
490               xtype : 'CheckBox',
491               boxLabel : _this._strings['0bfe42db3eb05bf39f03812166391939'] /* Use Secure Passwords */,
492               name : 'secure_passwords',
493               xns : Roo.bootstrap,
494               '|xns' : 'Roo.bootstrap'
495              }
496             ]
497            }
498           ]
499          }
500         ]
501        },
502        {
503         xtype : 'Input',
504         inputType : 'hidden',
505         labelAlign : 'left',
506         name : 'id',
507         listeners : {
508          render : function (_self)
509           {
510               _this.userID = _self;
511           }
512         },
513         xns : Roo.bootstrap,
514         '|xns' : 'Roo.bootstrap'
515        },
516        {
517         xtype : 'Input',
518         inputType : 'hidden',
519         name : 'company_id',
520         xns : Roo.bootstrap,
521         '|xns' : 'Roo.bootstrap'
522        }
523       ]
524      }
525     ]
526    }  );
527  }
528 });
529 Roo.apply(Pman.Dialog.BAdminStaff, Pman.Dialog.BAdminStaff.prototype);