Skip to content

Commit

Permalink
AnsibleCredentials - getCredentialFormData - wait for request before …
Browse files Browse the repository at this point in the history
…touching credential_options

getCredentialFormData is called when the request for form data (edit) succeeds.
But, that function is using `vm.credential_options` which are filled only after the OPTION request succeeds.

Wait for the promise before touching `credential_options`.
  • Loading branch information
himdel committed Apr 12, 2017
1 parent 5f88c45 commit c92baff
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window', '$q', 'credentialId', 'miqService', 'API', function($window, $q, credentialId, miqService, API) {
var vm = this;

var optionsPromise = null;

var init = function() {
vm.credentialModel = {
id: null,
Expand All @@ -22,7 +24,7 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
miqService.sparkleOn();

// get credential specific options for all supported credential types
var optionsPromise = API.options('/api/authentications')
optionsPromise = API.options('/api/authentications')
.then(getCredentialOptions)
.catch(miqService.handleFailure);

Expand Down Expand Up @@ -89,19 +91,22 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
vm.credentialModel.name = response.name;
vm.credentialModel.type = response.type;

// we need to merge options and vm.credentialModel
for (var opt in response.options) {
var item = vm.credential_options[vm.credentialModel.type]['attributes'][opt];

// void the password fields first
if (item.hasOwnProperty('type') && item['type'] === 'password') {
vm.credentialModel[opt] = '';
} else {
vm.credentialModel[opt] = response.options[opt];
// we need to wait for vm.credential_options here
optionsPromise.then(function() {
// we need to merge options and vm.credentialModel
for (var opt in response.options) {
var item = vm.credential_options[vm.credentialModel.type]['attributes'][opt];

// void the password fields first
if (item.hasOwnProperty('type') && item['type'] === 'password') {
vm.credentialModel[opt] = '';
} else {
vm.credentialModel[opt] = response.options[opt];
}
}
}

vm.modelCopy = angular.copy( vm.credentialModel );
vm.modelCopy = angular.copy( vm.credentialModel );
});
}

function getBack(message, warning, error) {
Expand Down

0 comments on commit c92baff

Please sign in to comment.