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 AccountAddDetailsCtrl {
 
  41         constructor($scope, $log, $interval, basicAuthAccountService, $modalInstance, errorMessageByCode, ECOMP_URL_REGEX, $window, confirmBoxService, $cookies,items) {
 
  43            this.addEndpoint = () => {
 
  44                   this.account.endpointList.push({
 
  50                 this.account.endpointList = [];
 
  51                 this.passwordMatched = true;
 
  52                 this.dupliateName = false;
 
  53                 this.emptyAccountName = false;
 
  54                 this.emptyAccountUsername = false;
 
  55                 this.accountList = items.list;
 
  57                 if (items&& items.account) {
 
  58                     this.isEditMode = true;
 
  59                     this.account = _.clone(items.account);
 
  60                     this.account.repassword = this.account.password;
 
  61                     this.account.endpointList = this.account.endpoints;
 
  62                     if(this.account.isActive == 'Y')
 
  63                         this.account.active = true;
 
  65                         this.account.active = false;
 
  67                     this.isEditMode = false;
 
  68                     this.account.active = true;
 
  70                 console.log(this.account);
 
  73             let resetConflict = fieldName => {
 
  74                 delete this.conflictMessages[fieldName];
 
  75                 if($scope.widgetForm[fieldName]){
 
  76                     $scope.widgetForm[fieldName].$setValidity('conflict', true);
 
  81           /*  this.closeThisDialog = () => {
 
  82                 $scope.closeThisDialog(true);
 
  85             this.removeEndpointItem = (endpoint) => {
 
  86                         for(var i = 0; i < this.account.endpointList.length; i++){
 
  87                                 if(this.account.endpointList[i].name == endpoint.name){
 
  88                                         this.account.endpointList.splice(i, 1);
 
  94             this.updateUsername = () => {
 
  95                 this.emptyAccountUsername = false;
 
  98             this.updateAccountName = () => {
 
  99                 this.dupliateName = false;
 
 100                 for(var i = 0; i < this.accountList.length; i++){
 
 101                         if(this.accountList[i].applicationName == this.account.applicationName){
 
 102                                 this.dupliateName = true;
 
 108             this.updateAccountEndpoint = (endpoint) => {
 
 109                 endpoint.valid = true;
 
 112             this.saveChanges = () => {
 
 117                 for(var i = 0; i < this.account.endpointList.length; i++){
 
 118                         if(this.account.endpointList[i].name == undefined
 
 119                         || this.account.endpointList[i].name == null
 
 120                         || this.account.endpointList[i].name == ""){
 
 121                                 this.account.endpointList.splice(i, 1);
 
 124                                 if(!this.account.endpointList[i].name.startsWith("/")){
 
 125                                         this.account.endpointList[i].name = "/" + this.account.endpointList[i].name;
 
 127                                 if(!r.test(this.account.endpointList[i].name)){
 
 128                                         this.account.endpointList[i].valid = false;
 
 135                 if(this.account.applicationName == ''
 
 136                 || this.account.applicationName == undefined){
 
 137                         this.emptyAccountName = true;
 
 141                 if(this.account.username == ''
 
 142                 || this.account.username == undefined){
 
 143                         this.emptyAccountUsername = true;
 
 147                 if(this.dupliateName == true){
 
 151                 if(this.account.password != this.account.repassword){
 
 152                         this.passwordMatched =  false;
 
 162                 if(this.account.active == true)
 
 166                                 applicationName: this.account.applicationName,
 
 167                                 username: this.account.username,
 
 168                                 password: this.account.password,
 
 169                                 endpoints: this.account.endpointList,
 
 175                         var message = "Are you sure you want to change '" + this.account.applicationName + "'?"
 
 176                         confirmBoxService.editItem(message).then(isConfirmed => {
 
 178                                         basicAuthAccountService.updateAccount(this.account.id, newAccount).then(() => {
 
 179                                                 $modalInstance.close("confirmed");
 
 184                         basicAuthAccountService.createAccount(newAccount).then(() => {
 
 185                                  $modalInstance.close("confirmed");
 
 191             $scope.$on('$stateChangeStart', e => {
 
 196     AccountAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'basicAuthAccountService', '$modalInstance', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window', 'confirmBoxService', '$cookies','items'];
 
 197     angular.module('ecompApp').controller('AccountAddDetailsCtrl', AccountAddDetailsCtrl);