1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
'use strict';
(function () {
class AccountAddDetailsCtrl {
constructor($scope, $log, $interval, basicAuthAccountService, errorMessageByCode, ECOMP_URL_REGEX, $window, confirmBoxService, $cookies) {
this.addEndpoint = () => {
this.account.endpointList.push({
valid: true
});
}
let init = () => {
this.account = [];
this.account.endpointList = [];
this.passwordMatched = true;
this.dupliateName = false;
this.emptyAccountName = false;
this.emptyAccountUsername = false;
this.accountList = $scope.ngDialogData.list;
if ($scope.ngDialogData && $scope.ngDialogData.account) {
this.isEditMode = true;
this.account = _.clone($scope.ngDialogData.account);
this.account.repassword = this.account.password;
this.account.endpointList = this.account.endpoints;
if(this.account.isActive == 'Y')
this.account.active = true;
else
this.account.active = false;
} else {
this.isEditMode = false;
this.account.active = true;
}
console.log(this.account);
};
let resetConflict = fieldName => {
delete this.conflictMessages[fieldName];
if($scope.widgetForm[fieldName]){
$scope.widgetForm[fieldName].$setValidity('conflict', true);
}
};
this.closeThisDialog = () => {
$scope.closeThisDialog(true);
}
this.removeEndpointItem = (endpoint) => {
for(var i = 0; i < this.account.endpointList.length; i++){
if(this.account.endpointList[i].name == endpoint.name){
this.account.endpointList.splice(i, 1);
return;
}
}
}
this.confirmPassword = () => {
this.passwordMatched = true;
}
this.updateUsername = () => {
this.emptyAccountUsername = false;
}
this.updateAccountName = () => {
this.dupliateName = false;
for(var i = 0; i < this.accountList.length; i++){
if(this.accountList[i].applicationName == this.account.applicationName){
this.dupliateName = true;
return;
}
}
}
this.updateAccountEndpoint = (endpoint) => {
endpoint.valid = true;
}
this.saveChanges = () => {
var isValid = true;
var r = /\/[^ "]+$/;
for(var i = 0; i < this.account.endpointList.length; i++){
if(this.account.endpointList[i].name == undefined
|| this.account.endpointList[i].name == null
|| this.account.endpointList[i].name == ""){
this.account.endpointList.splice(i, 1);
i--;
}else{
if(!this.account.endpointList[i].name.startsWith("/")){
this.account.endpointList[i].name = "/" + this.account.endpointList[i].name;
}
if(!r.test(this.account.endpointList[i].name)){
this.account.endpointList[i].valid = false;
isValid = false;
}
}
}
if(this.account.applicationName == ''
|| this.account.applicationName == undefined){
this.emptyAccountName = true;
isValid = false;
}
if(this.account.username == ''
|| this.account.username == undefined){
this.emptyAccountUsername = true;
isValid = false;
}
if(this.dupliateName == true){
isValid = false;
}
if(this.account.password != this.account.repassword){
this.passwordMatched = false;
isValid = false;
}
if(!isValid)
return;
var active = 'N';
if(this.account.active == true)
active = 'Y';
var newAccount = {
applicationName: this.account.applicationName,
username: this.account.username,
password: this.account.password,
endpoints: this.account.endpointList,
isActive: active
};
if(this.isEditMode){
var message = "Are you sure you want to change '" + this.account.applicationName + "'?"
confirmBoxService.editItem(message).then(isConfirmed => {
if(isConfirmed){
basicAuthAccountService.updateAccount(this.account.id, newAccount).then(() => {
$scope.closeThisDialog(true);
});
}
});
}else{
basicAuthAccountService.createAccount(newAccount).then(() => {
$scope.closeThisDialog(true);
});
}
}
init();
$scope.$on('$stateChangeStart', e => {
e.preventDefault();
});
}
}
AccountAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'basicAuthAccountService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window', 'confirmBoxService', '$cookies'];
angular.module('ecompApp').controller('AccountAddDetailsCtrl', AccountAddDetailsCtrl);
})();
|