3 class AccountAddDetailsCtrl {
4 constructor($scope, $log, $interval, basicAuthAccountService, errorMessageByCode, ECOMP_URL_REGEX, $window, confirmBoxService, $cookies) {
6 this.addEndpoint = () => {
7 this.account.endpointList.push({
14 this.account.endpointList = [];
15 this.passwordMatched = true;
16 this.dupliateName = false;
17 this.emptyAccountName = false;
18 this.emptyAccountUsername = false;
19 this.accountList = $scope.ngDialogData.list;
21 if ($scope.ngDialogData && $scope.ngDialogData.account) {
22 this.isEditMode = true;
23 this.account = _.clone($scope.ngDialogData.account);
24 this.account.repassword = this.account.password;
25 this.account.endpointList = this.account.endpoints;
26 if(this.account.isActive == 'Y')
27 this.account.active = true;
29 this.account.active = false;
31 this.isEditMode = false;
32 this.account.active = true;
34 console.log(this.account);
37 let resetConflict = fieldName => {
38 delete this.conflictMessages[fieldName];
39 if($scope.widgetForm[fieldName]){
40 $scope.widgetForm[fieldName].$setValidity('conflict', true);
45 this.closeThisDialog = () => {
46 $scope.closeThisDialog(true);
49 this.removeEndpointItem = (endpoint) => {
50 for(var i = 0; i < this.account.endpointList.length; i++){
51 if(this.account.endpointList[i].name == endpoint.name){
52 this.account.endpointList.splice(i, 1);
58 this.confirmPassword = () => {
59 this.passwordMatched = true;
62 this.updateUsername = () => {
63 this.emptyAccountUsername = false;
66 this.updateAccountName = () => {
67 this.dupliateName = false;
68 for(var i = 0; i < this.accountList.length; i++){
69 if(this.accountList[i].applicationName == this.account.applicationName){
70 this.dupliateName = true;
76 this.updateAccountEndpoint = (endpoint) => {
77 endpoint.valid = true;
80 this.saveChanges = () => {
85 for(var i = 0; i < this.account.endpointList.length; i++){
86 if(this.account.endpointList[i].name == undefined
87 || this.account.endpointList[i].name == null
88 || this.account.endpointList[i].name == ""){
89 this.account.endpointList.splice(i, 1);
92 if(!this.account.endpointList[i].name.startsWith("/")){
93 this.account.endpointList[i].name = "/" + this.account.endpointList[i].name;
95 if(!r.test(this.account.endpointList[i].name)){
96 this.account.endpointList[i].valid = false;
103 if(this.account.applicationName == ''
104 || this.account.applicationName == undefined){
105 this.emptyAccountName = true;
109 if(this.account.username == ''
110 || this.account.username == undefined){
111 this.emptyAccountUsername = true;
115 if(this.dupliateName == true){
119 if(this.account.password != this.account.repassword){
120 this.passwordMatched = false;
130 if(this.account.active == true)
134 applicationName: this.account.applicationName,
135 username: this.account.username,
136 password: this.account.password,
137 endpoints: this.account.endpointList,
143 var message = "Are you sure you want to change '" + this.account.applicationName + "'?"
144 confirmBoxService.editItem(message).then(isConfirmed => {
146 basicAuthAccountService.updateAccount(this.account.id, newAccount).then(() => {
147 $scope.closeThisDialog(true);
152 basicAuthAccountService.createAccount(newAccount).then(() => {
153 $scope.closeThisDialog(true);
159 $scope.$on('$stateChangeStart', e => {
164 AccountAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'basicAuthAccountService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window', 'confirmBoxService', '$cookies'];
165 angular.module('ecompApp').controller('AccountAddDetailsCtrl', AccountAddDetailsCtrl);