diff --git a/awx/ui/client/src/controllers/Credentials.js b/awx/ui/client/src/controllers/Credentials.js index 73ae12258f..3b0e68dc21 100644 --- a/awx/ui/client/src/controllers/Credentials.js +++ b/awx/ui/client/src/controllers/Credentials.js @@ -142,6 +142,8 @@ export function CredentialsAdd($scope, $rootScope, $compile, $location, $log, $r defaultUrl = GetBasePath('credentials'), url; + $scope.keyEntered = false; + generator.inject(form, { mode: 'add', related: false, scope: $scope }); generator.reset(); @@ -214,6 +216,15 @@ export function CredentialsAdd($scope, $rootScope, $compile, $location, $log, $r OwnerChange({ scope: $scope }); } + $scope.$watch("ssh_key_data", function(val) { + if (val === "" || val === null || val === undefined) { + $scope.keyEntered = false; + $scope.ssh_key_unlock_ask = false; + $scope.ssh_key_unlock = ""; + } else { + $scope.keyEntered = true; + } + }); // Handle Kind change $scope.kindChange = function () { @@ -359,6 +370,15 @@ export function CredentialsEdit($scope, $rootScope, $compile, $location, $log, $ reset: false }); OwnerChange({ scope: $scope }); + $scope.$watch("ssh_key_data", function(val) { + if (val === "" || val === null || val === undefined) { + $scope.keyEntered = false; + $scope.ssh_key_unlock_ask = false; + $scope.ssh_key_unlock = ""; + } else { + $scope.keyEntered = true; + } + }); Wait('stop'); }); diff --git a/awx/ui/client/src/forms/Credentials.js b/awx/ui/client/src/forms/Credentials.js index 4b09b3ae58..4626afa918 100644 --- a/awx/ui/client/src/forms/Credentials.js +++ b/awx/ui/client/src/forms/Credentials.js @@ -275,6 +275,7 @@ export default ngShow: "kind.value == 'ssh' || kind.value == 'scm'", addRequired: false, editRequired: false, + ngDisabled: "keyEntered === false", ask: true, hasShowInputButton: true, askShow: "kind.value == 'ssh'", // Only allow ask for machine credentials diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index 826cf1683c..9c2a9aea69 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -896,7 +896,19 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += buildId(field, fld + "_show_input_button", this.form); html += "aw-tool-tip='Toggle the display of plaintext.' aw-tip-placement='top' "; html += "ng-click='" + fld + "_field.toggleInput(\"#" + this.form.name + "_" + fld + "\")'"; - html += (field.ask) ? " ng-disabled='" + fld + "_ask'" : ""; + if (field.ngDisabled || field.ask) { + var disabled = ""; + if (field.ngDisabled) { + disabled += field.ngDisabled; + } + if (field.ngDisabled && field.ask) { + disabled += " || "; + } + if (field.ask) { + disabled += fld + "_ask"; + } + html += "ng-disabled='" + disabled + "'"; + } html += ">\n" + field.showInputInnerHTML; html += "\n\n"; html += "\n"; @@ -931,12 +943,25 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += (field.awPassMatch) ? "awpassmatch='" + field.associated + "' " : ""; html += (field.capitalize) ? "capitalize " : ""; html += (field.awSurveyQuestion) ? "aw-survey-question" : ""; - html += (field.ask) ? "ng-disabled='" + fld + "_ask' " : ""; + + if (field.ngDisabled || field.ask) { + var disabled = ""; + if (field.ngDisabled) { + disabled += field.ngDisabled; + } + if (field.ngDisabled && field.ask) { + disabled += " || "; + } + if (field.ask) { + disabled += fld + "_ask"; + } + html += "ng-disabled='" + disabled + "'"; + } html += (field.autocomplete !== undefined) ? this.attr(field, 'autocomplete') : ""; html += (field.awRequiredWhen) ? "data-awrequired-init='" + field.awRequiredWhen.init + "' aw-required-when='" + field.awRequiredWhen.variable + "' " : ""; html += (field.awValidUrl) ? "aw-valid-url " : ""; - html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled='" + field.associated + "_ask' " : ""; + html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled='" + field.associated + "_foo' " : ""; html += ">\n"; } @@ -960,6 +985,9 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += "