2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 class SearchUsersCtrl {
25 constructor($log, usersService,adminsService, $scope,confirmBoxService) {
27 $scope.UserSearchsIsNull=false;
28 $scope.userExist = false;
29 this.scrollApi = {};//scrollTop directive
31 this.showAddUser = false;
32 this.showSearch = true;
44 let activeRequests = [];
45 let clearReq = (req) => {
46 activeRequests.splice(activeRequests.indexOf(req), 1);
49 this.showAddUserSection = () => {
50 this.showAddUser = true;
51 this.showSearch = false;
54 this.addNewUserFun = () => {
55 if (this.newUser.loginId =='' || this.newUser.loginPwd == '' || this.newUser.firstName == '' || this.newUser.lastName =='' || this.newUser.emailAddress ==''||this.newUser.loginPwd ==''){
56 var warningMsg = "Please enter a value for all fields marked with *.";
57 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
59 } else if (this.newUser.loginPwd != this.newUser.loginPwdCheck) {
60 var warningMsg = "Passwords do not match, please try again.";
61 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
65 // check password length complexity.
66 var warningMsg = adminsService.isComplexPassword(this.newUser.loginPwd);
67 if (warningMsg != null) {
68 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
73 adminsService.addNewUser(this.newUser,'Yes').then(res=> {
75 if(res.message == 'Record already exist'){
77 this.showAddUser = true;
78 this.showSearch = false;
79 $scope.userExist = true;
83 $scope.userExist = false;
84 this.selectedUser = this.newUser;
85 this.selectedUser.orgUserId = this.newUser.loginId;
86 this.searchUsersResults = [];
87 this.searchUsersResults.push(this.newUser);
88 this.showAddUser = false;
89 this.showSearch = true;
99 this.searchUserString ='';
100 $scope.UserSearchsIsNull = false;
105 $log.error('adminsService: addNewUser error:: ', err);
106 // $scope.errMsg=err;
107 confirmBoxService.showInformation('Add New User failed: ' + err);
110 //this.isLoadingTable = false;
115 this.searchUsers = () => {
116 this.isLoading = true;
117 if(this.searchUsersInProgress){
120 this.selectedUser = null;
121 this.searchUsersInProgress = true;
122 this.searchUsersResults = null;
124 let searchUsersReq = usersService.searchUsers(this.searchUserString);
125 activeRequests.push(searchUsersReq);
126 searchUsersReq.promise().then(usersList => {
127 $log.debug('searchUsers found the following users: ', JSON.stringify(usersList));
128 this.searchUsersResults = usersList;
129 $scope.UserSearchsIsNull=false;
131 $log.error('SearchUsersCtrl.searchUsers: ' + err);
132 $scope.UserSearchsIsNull=true;
134 this.scrollApi.scrollTop();
135 this.searchUsersInProgress = false;
136 clearReq(searchUsersReq);
137 this.isLoading = false;
142 this.isLoading = false;
143 this.searchUsersInProgress = false;
146 this.setSelectedUser = user => {
147 this.selectedUser = user;
152 $scope.$on('$destroy', () => {
153 activeRequests.forEach(req => {
159 SearchUsersCtrl.$inject = ['$log', 'usersService','adminsService', '$scope','confirmBoxService'];
160 angular.module('ecompApp').controller('SearchUsersCtrl', SearchUsersCtrl);