2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
40 class SearchUsersCtrl {
42 constructor($log, usersService,adminsService, $scope,confirmBoxService) {
44 $scope.UserSearchsIsNull=false;
45 $scope.userExist = false;
46 this.scrollApi = {};//scrollTop directive
47 $scope.txtResults = 'result';
49 this.showAddUser = false;
50 this.showSearch = true;
62 let activeRequests = [];
63 let clearReq = (req) => {
64 activeRequests.splice(activeRequests.indexOf(req), 1);
67 this.showAddUserSection = () => {
68 this.showAddUser = true;
69 this.showSearch = false;
72 this.addNewUserFun = () => {
73 if (this.newUser.loginId =='' || this.newUser.loginPwd == '' || this.newUser.firstName == '' || this.newUser.lastName =='' || this.newUser.emailAddress ==''||this.newUser.loginPwd ==''){
74 var warningMsg = "Please enter a value for all fields marked with *.";
75 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
77 } else if (this.newUser.loginPwd != this.newUser.loginPwdCheck) {
78 var warningMsg = "Passwords do not match, please try again.";
79 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
83 // check password length complexity.
84 var warningMsg = adminsService.isComplexPassword(this.newUser.loginPwd);
85 if (warningMsg != null) {
86 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
91 adminsService.addNewUser(this.newUser,'Yes').then(res=> {
93 if(res.message == 'Record already exist'){
95 this.showAddUser = true;
96 this.showSearch = false;
97 $scope.userExist = true;
101 $scope.userExist = false;
102 this.selectedUser = this.newUser;
103 this.selectedUser.orgUserId = this.newUser.loginId;
104 this.searchUsersResults = [];
105 this.searchUsersResults.push(this.newUser);
106 this.showAddUser = false;
107 this.showSearch = true;
117 this.searchUserString ='';
118 $scope.UserSearchsIsNull = false;
123 $log.error('adminsService: addNewUser error:: ', err);
124 // $scope.errMsg=err;
125 confirmBoxService.showInformation('Add New User failed: ' + err);
128 //this.isLoadingTable = false;
133 this.searchUsers = () => {
134 this.isLoading = true;
135 if(this.searchUsersInProgress){
138 this.selectedUser = null;
139 this.searchUsersInProgress = true;
140 this.searchUsersResults = null;
142 let searchUsersReq = usersService.searchUsers(this.searchUserString);
143 activeRequests.push(searchUsersReq);
144 searchUsersReq.promise().then(usersList => {
145 $log.debug('searchUsers found the following users: ', JSON.stringify(usersList));
146 this.searchUsersResults = usersList;
147 $log.debug('searchUsersResults length: ', usersList.length);
148 if (usersList.length != 1) {
149 $scope.txtResults = 'results'
151 $scope.txtResults = 'result'
153 $scope.UserSearchsIsNull=false;
155 $log.error('SearchUsersCtrl.searchUsers: ' + err);
156 $scope.UserSearchsIsNull=true;
158 this.scrollApi.scrollTop();
159 this.searchUsersInProgress = false;
160 clearReq(searchUsersReq);
161 this.isLoading = false;
166 this.isLoading = false;
167 this.searchUsersInProgress = false;
170 this.setSelectedUser = user => {
171 this.selectedUser = user;
176 $scope.$on('$destroy', () => {
177 activeRequests.forEach(req => {
183 SearchUsersCtrl.$inject = ['$log', 'usersService','adminsService', '$scope','confirmBoxService'];
184 angular.module('ecompApp').controller('SearchUsersCtrl', SearchUsersCtrl);