Only auto-populate inventory source project when the user selects scm type from the dropdown

This commit is contained in:
Michael Abashian
2017-07-03 11:13:21 -04:00
parent 586961907c
commit 9213eec681
3 changed files with 13 additions and 14 deletions

View File

@@ -18,8 +18,9 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
init(); init();
function init() { function init() {
$scope.mode = 'add';
// apply form definition's default field values // apply form definition's default field values
GenerateForm.applyDefaults(form, $scope); GenerateForm.applyDefaults(form, $scope, true);
$scope.canAdd = inventorySourcesOptions.actions.POST; $scope.canAdd = inventorySourcesOptions.actions.POST;
$scope.envParseType = 'yaml'; $scope.envParseType = 'yaml';
initSources(); 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.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network';
$scope.sourceChange = function(source) { $scope.sourceChange = function(source) {
@@ -144,10 +144,11 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
} }
if (source === 'scm') { if (source === 'scm') {
$scope.overwrite_vars = true; $scope.projectBasePath = GetBasePath('projects');
$scope.inventory_source_form.inventory_file.$setPristine(); $scope.overwrite_vars = true;
$scope.inventory_source_form.inventory_file.$setPristine();
} else { } else {
$scope.overwrite_vars = false; $scope.overwrite_vars = false;
} }
// reset fields // reset fields

View File

@@ -564,10 +564,6 @@ function(ConfigurationUtils, i18n, $rootScope) {
_doAutoPopulate(); _doAutoPopulate();
} }
}); });
if (attrs.watchbasepath === 'projectBasePath') {
_doAutoPopulate();
}
} }
function _doAutoPopulate() { function _doAutoPopulate() {

View File

@@ -375,11 +375,13 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
return this.build(options); return this.build(options);
}, },
applyDefaults: function (form, scope) { applyDefaults: function (form, scope, ignoreMode) {
// Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js if(!ignoreMode) {
// The mode is needed by the awlookup directive to auto-populate form fields when there is a // Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js
// single related resource. // The mode is needed by the awlookup directive to auto-populate form fields when there is a
scope.mode = this.mode; // single related resource.
scope.mode = this.mode;
}
for (var fld in form.fields) { for (var fld in form.fields) {
if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) { if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) {