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============================================
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;});
81 } else if(/[^a-zA-Z0-9\-\@\_]/.test(this.newUser.loginId)){
82 var warningMsg = "Login ID should not contain special characters except '@', '-', and '_'.";
83 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
87 // check password length complexity.
88 var warningMsg = adminsService.isComplexPassword(this.newUser.loginPwd);
89 if (warningMsg != null) {
90 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
95 adminsService.addNewUser(this.newUser,'Yes').then(res=> {
97 if(res.message == 'Record already exist'){
99 this.showAddUser = true;
100 this.showSearch = false;
101 $scope.userExist = true;
105 $scope.userExist = false;
106 this.selectedUser = this.newUser;
107 this.selectedUser.orgUserId = this.newUser.loginId;
108 this.searchUsersResults = [];
109 this.searchUsersResults.push(this.newUser);
110 this.showAddUser = false;
111 this.showSearch = true;
121 this.searchUserString ='';
122 $scope.UserSearchsIsNull = false;
127 $log.error('adminsService: addNewUser error:: ', err);
128 // $scope.errMsg=err;
129 confirmBoxService.showInformation('Add New User failed: ' + err);
132 //this.isLoadingTable = false;
137 this.searchUsers = () => {
138 this.isLoading = true;
139 if(this.searchUsersInProgress){
142 this.selectedUser = null;
143 this.searchUsersInProgress = true;
144 this.searchUsersResults = null;
146 let searchUsersReq = usersService.searchUsers(this.searchUserString);
147 activeRequests.push(searchUsersReq);
148 searchUsersReq.promise().then(usersList => {
149 $log.debug('searchUsers found the following users: ', JSON.stringify(usersList));
150 this.searchUsersResults = usersList;
151 $log.debug('searchUsersResults length: ', usersList.length);
152 if (usersList.length != 1) {
153 $scope.txtResults = 'results'
155 $scope.txtResults = 'result'
157 $scope.UserSearchsIsNull=false;
159 $log.error('SearchUsersCtrl.searchUsers: ' + err);
160 $scope.UserSearchsIsNull=true;
162 this.scrollApi.scrollTop();
163 this.searchUsersInProgress = false;
164 clearReq(searchUsersReq);
165 this.isLoading = false;
170 this.isLoading = false;
171 this.searchUsersInProgress = false;
174 this.setSelectedUser = user => {
175 this.selectedUser = user;
180 $scope.$on('$destroy', () => {
181 activeRequests.forEach(req => {
187 SearchUsersCtrl.$inject = ['$log', 'usersService','adminsService', '$scope','confirmBoxService'];
188 angular.module('ecompApp').controller('SearchUsersCtrl', SearchUsersCtrl);