4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 var CloudAccountCreateController = function($timeout
, $state
, $stateParams
) {
21 var CloudAccountStore
= require('../missioncontrol/cloud_account/cloudAccountStore')
22 var CloudAccountActions
= require('../missioncontrol/cloud_account/cloudAccountActions')
23 self
.CloudAccountStore
= CloudAccountStore
;
27 // "account-type":"aws",
31 "account-type":"openstack",
34 "account-type":"cloudsim"
37 "account-type":"openmano"
51 label
: "Availability Zone",
52 ref
: 'availability-zone'
55 label
: "Default Subnet ID",
56 ref
: 'default-subnet-id'
81 label
: "Authentication URL",
89 label
: 'Management Network',
110 'account-type': 'openstack'
112 self
.loadDashboard = function() {
113 $state
.go('/launchpad', {management_domain
: $stateParams
.management_domain
});
115 self
.openAbout = function() {
116 $state
.go('lp-about', {management_domain
: $stateParams
.management_domain
});
118 self
.openDebug = function() {
119 $state
.go('lp-debug', {management_domain
: $stateParams
.management_domain
});
121 self
.create = function() {
122 if (self
.cloud
.name
== "") {
123 CloudAccountActions
.validateError("Please give the cloud account a name");
126 var type
= self
.cloud
['account-type'];
127 if (typeof(self
.params
[type
]) != 'undefined') {
128 var params
= self
.params
[type
];
129 for (var i
= 0; i
< params
.length
; i
++) {
130 var param
= params
[i
].ref
;
131 if (typeof(self
.cloud
[type
]) == 'undefined' || typeof(self
.cloud
[type
][param
]) == 'undefined' || self
.cloud
[type
][param
] == "") {
133 CloudAccountActions
.validateError("Please fill all account details");
139 CloudAccountActions
.validateReset();
140 CloudAccountStore
.create(self
.cloud
).then(function() {
141 $state
.go('/launchpad',{management_domain
: $stateParams
.management_domain
});
144 self
.cancel = function() {
145 $state
.go('/launchpad',{management_domain
: $stateParams
.management_domain
});
147 self
.store
= CloudAccountStore
;
148 require('../utils/utils.js').isNotAuthenticated(window
.location
, function() {
153 var CloudAccountEditController = function($timeout
, $state
, $stateParams
) {
155 var CloudAccountStore
= require('../missioncontrol/cloud_account/cloudAccountStore');
156 self
.CloudAccountStore
= CloudAccountStore
;
157 var cloud_account_name
= $stateParams
.cloud_account
;
165 // "account-type":"aws",
169 "account-type":"openstack",
172 "account-type":"cloudsim"
175 "account-type":"openmano"
189 label
: "Availability Zone",
190 ref
: 'availability-zone'
193 label
: "Default Subnet ID",
194 ref
: 'default-subnet-id'
219 label
: "Authentication URL",
227 label
: 'Management Network',
245 label
: "Data Center ID",
255 var listener = function(data
) {
256 $timeout(function() {
257 console
.log('updating', data
);
258 self
.cloud
.name
= data
.cloudAccount
.name
;
259 var accountType
= self
.cloud
['account-type'] = data
.cloudAccount
['account-type'];
260 if (data
.cloudAccount
[accountType
]) {
261 // There are extra params.
263 self
.cloud
[accountType
] = {};
264 // Iterate over them and assign to proper keys
265 for (var k
in data
.cloudAccount
[accountType
]) {
266 self
.cloud
[accountType
][k
] = data
.cloudAccount
[accountType
][k
];
272 CloudAccountStore
.listen(listener
);
273 require('../utils/utils.js').isNotAuthenticated(window
.location
, function() {
274 CloudAccountStore
.unlisten(listener
);
277 // Get the cloud account
278 CloudAccountStore
.getCloudAccount($stateParams
.cloud_account
);
279 self
.store
= CloudAccountStore
;
280 self
.update = function() {
281 if (self
.cloud
.name
== "") {
285 CloudAccountStore
.update(self
.cloud
).then(function() {
286 CloudAccountStore
.unlisten(listener
);
287 $state
.go('/launchpad',{management_domain
: $stateParams
.management_domain
});
290 self
.loadDashboard = function() {
291 $state
.go('/launchpad', {management_domain
: $stateParams
.management_domain
});
293 self
.openAbout = function() {
294 $state
.go('lp-about', {management_domain
: $stateParams
.management_domain
});
296 self
.openDebug = function() {
297 $state
.go('lp-debug', {management_domain
: $stateParams
.management_domain
});
299 self
.delete = function() {
300 console
.log('Deleting cloud account', cloud_account_name
);
301 CloudAccountStore
.delete(cloud_account_name
).then(function() {
302 CloudAccountStore
.unlisten(listener
);
303 $state
.go('/launchpad',{management_domain
: $stateParams
.management_domain
});
306 self
.cancel = function() {
307 CloudAccountStore
.unlisten(listener
);
308 $state
.go('/launchpad',{management_domain
: $stateParams
.management_domain
});
313 CloudAccountCreateController
: CloudAccountCreateController
,
314 CloudAccountEditController
: CloudAccountEditController