[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-os / client / src / views / header / profile-edit-dialogs / profile-edit.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21 (function () {
22     class EditProfileModalCtrl {
23         constructor($log,ngDialog,usersService,confirmBoxService,adminsService) {
24                 this.firstName ='';
25                 this.middleName ='';
26                 this.lastName ='';
27                 this.email ='';
28                 this.loginId ='';
29                 this.loginPwd ='';
30                 this.confirmLoginPwd=''
31                 this.isLoading = false;
32                 let getUser  = () => {
33                         this.isLoading = true;
34                         usersService.getLoggedInUser()
35                 .then(user=> {
36                         var data = user.response;
37                         console.log(data);
38                         this.firstName =data.firstName;
39                         this.middleName =data.middleName;
40                         this.lastName =data.lastName;
41                         this.email =data.email;
42                         this.loginId =data.loginId;
43                         this.loginPwd =data.loginPassword;
44                         this.isLoading = false;
45                 }).catch(err=> {
46                         $log.error('EditProfileModalCtrl.getUser:: Error retrieving ECMOP portal user: ' + err);
47                 });
48             }
49                 getUser();
50                 
51                 this.save = ()=>{
52                         var profileDetail ={
53                                         firstName :     this.firstName,
54                                 middleName :this.middleName,
55                         lastName :this.lastName,
56                         email :this.email,
57                         loginId :this.loginId,
58                         loginPassword :this.loginPwd
59                         }
60                         if (this.firstName =='' || this.lastName == '' || this.email == '' || this.loginId =='' || this.loginPwd ==''|| this.confirmLoginPwd ==''){
61                                 var warningMsg = "Please enter a value for all fields marked with *.";
62                                 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
63                                 return;
64                         } else if (this.loginPwd != this.confirmLoginPwd) {
65                                 var warningMsg = "Passwords do not match, please try again.";
66                                 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
67                                 return;
68                         } else {
69                                 // check password length complexity.
70                                 var warningMsg = adminsService.isComplexPassword(this.loginPwd);
71                                 if (warningMsg != null) {
72                                         confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
73                                         return;
74                                 }
75                         }
76                         usersService.modifyLoggedInUser(profileDetail).then(res=> {
77                                 confirmBoxService.showInformation("Profile detail updated").then(isConfirmed => {return;});
78                         }).catch(err=> {
79                                 $log.error('EditProfileModalCtrl.getUser:: Error retrieving ECMOP portal user: ' + err);
80                                 confirmBoxService.showInformation("Error while updating profile detail: "+ err).then(isConfirmed => {return;});
81                         });
82                 }
83         }
84     }
85     EditProfileModalCtrl.$inject = ['$log', 'ngDialog','usersService','confirmBoxService','adminsService'];
86     angular.module('ecompApp').controller('EditProfileModalCtrl', EditProfileModalCtrl);
87 })();