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
30 $scope.txtResults = 'result';
32 this.showAddUser = false;
33 this.showSearch = true;
45 let activeRequests = [];
46 let clearReq = (req) => {
47 activeRequests.splice(activeRequests.indexOf(req), 1);
50 this.showAddUserSection = () => {
51 this.showAddUser = true;
52 this.showSearch = false;
55 this.addNewUserFun = () => {
56 if (this.newUser.loginId =='' || this.newUser.loginPwd == '' || this.newUser.firstName == '' || this.newUser.lastName =='' || this.newUser.emailAddress ==''||this.newUser.loginPwd ==''){
57 var warningMsg = "Please enter a value for all fields marked with *.";
58 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
60 } else if (this.newUser.loginPwd != this.newUser.loginPwdCheck) {
61 var warningMsg = "Passwords do not match, please try again.";
62 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
66 // check password length complexity.
67 var warningMsg = adminsService.isComplexPassword(this.newUser.loginPwd);
68 if (warningMsg != null) {
69 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
74 adminsService.addNewUser(this.newUser,'Yes').then(res=> {
76 if(res.message == 'Record already exist'){
78 this.showAddUser = true;
79 this.showSearch = false;
80 $scope.userExist = true;
84 $scope.userExist = false;
85 this.selectedUser = this.newUser;
86 this.selectedUser.orgUserId = this.newUser.loginId;
87 this.searchUsersResults = [];
88 this.searchUsersResults.push(this.newUser);
89 this.showAddUser = false;
90 this.showSearch = true;
100 this.searchUserString ='';
101 $scope.UserSearchsIsNull = false;
106 $log.error('adminsService: addNewUser error:: ', err);
107 // $scope.errMsg=err;
108 confirmBoxService.showInformation('Add New User failed: ' + err);
111 //this.isLoadingTable = false;
116 this.searchUsers = () => {
117 this.isLoading = true;
118 if(this.searchUsersInProgress){
121 this.selectedUser = null;
122 this.searchUsersInProgress = true;
123 this.searchUsersResults = null;
125 let searchUsersReq = usersService.searchUsers(this.searchUserString);
126 activeRequests.push(searchUsersReq);
127 searchUsersReq.promise().then(usersList => {
128 $log.debug('searchUsers found the following users: ', JSON.stringify(usersList));
129 this.searchUsersResults = usersList;
130 $log.debug('searchUsersResults length: ', usersList.length);
131 if (usersList.length != 1) {
132 $scope.txtResults = 'results'
134 $scope.txtResults = 'result'
136 $scope.UserSearchsIsNull=false;
138 $log.error('SearchUsersCtrl.searchUsers: ' + err);
139 $scope.UserSearchsIsNull=true;
141 this.scrollApi.scrollTop();
142 this.searchUsersInProgress = false;
143 clearReq(searchUsersReq);
144 this.isLoading = false;
149 this.isLoading = false;
150 this.searchUsersInProgress = false;
153 this.setSelectedUser = user => {
154 this.selectedUser = user;
159 $scope.$on('$destroy', () => {
160 activeRequests.forEach(req => {
166 SearchUsersCtrl.$inject = ['$log', 'usersService','adminsService', '$scope','confirmBoxService'];
167 angular.module('ecompApp').controller('SearchUsersCtrl', SearchUsersCtrl);