From c92baffb9362265b5ab996b901e7686a68a9c38c Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 12 Apr 2017 11:42:34 +0000 Subject: [PATCH] AnsibleCredentials - getCredentialFormData - wait for request before 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`. --- .../ansible_credentials_form_controller.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/controllers/ansible_credentials/ansible_credentials_form_controller.js b/app/assets/javascripts/controllers/ansible_credentials/ansible_credentials_form_controller.js index 08b8ee7ea85..85267ef6c63 100644 --- a/app/assets/javascripts/controllers/ansible_credentials/ansible_credentials_form_controller.js +++ b/app/assets/javascripts/controllers/ansible_credentials/ansible_credentials_form_controller.js @@ -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, @@ -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); @@ -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) {