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 * ================================================================================
22 class NewPortalAdminModalCtrl {
23 constructor($log, portalAdminsService, $scope, confirmBoxService) {
26 this.isSaving = false;
27 if($scope.ngDialogData && $scope.ngDialogData.selectedUser && $scope.ngDialogData.dialogState){
28 this.selectedUser = $scope.ngDialogData.selectedUser;
29 this.dialogState = $scope.ngDialogData.dialogState;
31 this.selectedUser = null;
34 $log.info('NewPortalAdminModalCtrl:: initiated');
37 this.addNewPortalAdmin = () => {
38 portalAdminsService.getPortalAdmins().then(result=> {
39 var dupNameCheck = JSON.stringify(result).search(this.selectedUser.orgUserId);
40 if (dupNameCheck != -1) {
41 $log.error("NewPortalAdminModalCtrl::addNewPortalAdmin: userId already exists as a portal admin! dupNameCheck=",dupNameCheck);
42 confirmBoxService.showInformation('This user already exists as a portal admin!').then(function (isConfirmed) {
43 $scope.closeThisDialog(true);
46 confirmBoxService.makeAdminChanges('Are you sure you want to add "' + this.selectedUser.firstName + ' ' + this.selectedUser.lastName + '" as a Portal Admin?')
47 .then(isConfirmed => {
49 if (!this.selectedUser || !this.selectedUser.orgUserId) {
50 $log.error('NewPortalAdminModalCtrl::makeAdminChanges: No portal admin or ID... cannot add');
53 portalAdminsService.addPortalAdmin(this.selectedUser.orgUserId)
55 $log.debug("NewPortalAdminModalCtrl::addNewPortalAdmin: portal admin added successfully");
56 $scope.closeThisDialog(true);
58 $log.error('NewPortalAdminModalCtrl::addNewPortalAdmin error status: ' + err.status);
59 confirmBoxService.showInformation('There was a unknown problem adding the portal admin. ' + 'Please try again later. Error Status: '+ err.status).then(function (isConfirmed) {});
63 $log.error('portalAdminsService.addPortalAdmin error status: '+ err.status);
67 $log.error('NewPortalAdminModalCtrl::addNewPortalAdmin error getting portal admins list:',err);
71 this.setSelectedUser = (user) => {
72 $log.debug('NewPortalAdminModalCtrl::setSelectedUser: selected user: ', user);
73 this.selectedUser = user;
78 $scope.$on('$stateChangeStart', e => {
83 NewPortalAdminModalCtrl.$inject = ['$log', 'portalAdminsService', '$scope', 'confirmBoxService'];
84 angular.module('ecompApp').controller('NewPortalAdminModalCtrl', NewPortalAdminModalCtrl);