Skip to content

Commit

Permalink
Merge pull request #1017 from himdel/fix-credential-request-dependency
Browse files Browse the repository at this point in the history
AnsibleCredentials - getCredentialFormData - wait for request before touching credential_options
  • Loading branch information
mzazrivec authored Apr 12, 2017
2 parents 0556af1 + c92baff commit ff8e3e3
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 ff8e3e3

Please sign in to comment.