From 9213eec68117a4f61a339d353795baec25d4eb14 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 3 Jul 2017 11:13:21 -0400 Subject: [PATCH] Only auto-populate inventory source project when the user selects scm type from the dropdown --- .../related/sources/add/sources-add.controller.js | 11 ++++++----- awx/ui/client/src/shared/directives.js | 4 ---- awx/ui/client/src/shared/form-generator.js | 12 +++++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js index 96c04b7eac..e8e8e41f09 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/related/sources/add/sources-add.controller.js @@ -18,8 +18,9 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', init(); function init() { + $scope.mode = 'add'; // apply form definition's default field values - GenerateForm.applyDefaults(form, $scope); + GenerateForm.applyDefaults(form, $scope, true); $scope.canAdd = inventorySourcesOptions.actions.POST; $scope.envParseType = 'yaml'; initSources(); @@ -118,7 +119,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', }); }; - $scope.projectBasePath = GetBasePath('projects'); $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; $scope.sourceChange = function(source) { @@ -144,10 +144,11 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', } if (source === 'scm') { - $scope.overwrite_vars = true; - $scope.inventory_source_form.inventory_file.$setPristine(); + $scope.projectBasePath = GetBasePath('projects'); + $scope.overwrite_vars = true; + $scope.inventory_source_form.inventory_file.$setPristine(); } else { - $scope.overwrite_vars = false; + $scope.overwrite_vars = false; } // reset fields diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index 4fff94bca1..2967ffaba5 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -564,10 +564,6 @@ function(ConfigurationUtils, i18n, $rootScope) { _doAutoPopulate(); } }); - - if (attrs.watchbasepath === 'projectBasePath') { - _doAutoPopulate(); - } } function _doAutoPopulate() { diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index ff3bcbf568..10923c5329 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -375,11 +375,13 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat return this.build(options); }, - applyDefaults: function (form, scope) { - // Note: This is a hack. Ideally, mode should be set in each -.controller.js - // The mode is needed by the awlookup directive to auto-populate form fields when there is a - // single related resource. - scope.mode = this.mode; + applyDefaults: function (form, scope, ignoreMode) { + if(!ignoreMode) { + // Note: This is a hack. Ideally, mode should be set in each -.controller.js + // The mode is needed by the awlookup directive to auto-populate form fields when there is a + // single related resource. + scope.mode = this.mode; + } for (var fld in form.fields) { if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) {