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 * ================================================================================
21 * Created by nnaffar on 12/8/15.
25 class NewPortalAdminModalCtrl {
26 constructor($log, portalAdminsService, $scope, confirmBoxService) {
29 this.isSaving = false;
30 /* istanbul ignore if */
31 if($scope.ngDialogData && $scope.ngDialogData.selectedUser && $scope.ngDialogData.dialogState){
32 this.selectedUser = $scope.ngDialogData.selectedUser;
33 this.dialogState = $scope.ngDialogData.dialogState;
35 this.selectedUser = null;
38 //this.searchUsersInProgress = false;
39 //this.showNewAdminAppDropdown = false;
40 $log.info('NewPortalAdminModalCtrl:: initiated');
43 this.addNewPortalAdmin = () => {
44 confirmBoxService.makeAdminChanges('Are you sure you want to add "' + this.selectedUser.firstName + ' ' + this.selectedUser.lastName + '" as a Portal Admin?')
45 .then(isConfirmed => {
47 if (!this.selectedUser || !this.selectedUser.orgUserId) {
48 $log.error('NewPortalAdminModalCtrl::makeAdminChanges: No portal admin or ID... cannot add');
51 portalAdminsService.addPortalAdmin(this.selectedUser.orgUserId)
53 $log.debug("NewPortalAdminModalCtrl::addNewPortalAdmin: portal admin added successfully");
54 $scope.$dismiss('cancel');
56 if(err.status === 409) { //Conflict
57 confirmBoxService.showInformation('This user already exists as a portal admin!').then(function (isConfirmed) {
58 $scope.$dismiss('cancel');
61 confirmBoxService.showInformation('There was a unknown problem adding the portal admin. ' + 'Please try again later. Error Status: '+ err.status).then(function (isConfirmed) {
62 $scope.$dismiss('cancel');
68 confirmBoxService.showInformation('There was a unknown problem adding the portal admin. ' + 'Please try again later. Error Status: '+ err.status).then(function (isConfirmed) {
69 $scope.$dismiss('cancel');
71 $log.error('portalAdminsService.addPortalAdmin error status: '+ err.status);
76 * this function set the selected user
77 * @param user: selected user object
79 this.setSelectedUser = (user) => {
80 $log.debug('NewPortalAdminModalCtrl::setSelectedUser: selected user: ', user);
81 this.selectedUser = user;
86 $scope.$on('$stateChangeStart', e => {
87 //Disable navigation when modal is opened
88 //**Nabil - note: this will cause the history back state to be replaced with current state
93 NewPortalAdminModalCtrl.$inject = ['$log', 'portalAdminsService', '$scope', 'confirmBoxService'];
94 angular.module('ecompApp').controller('NewPortalAdminModalCtrl', NewPortalAdminModalCtrl);