From 2b01c24dce6aecef1c8f33239ce18f6c8f3e87bf Mon Sep 17 00:00:00 2001 From: gconsidine Date: Fri, 9 Jun 2017 11:02:01 -0400 Subject: [PATCH] Add method to remove input data on credential type change --- .../edit-credentials.controller.js | 1 + .../components/input/checkbox.directive.js | 44 +++++++++++++++++++ .../components/input/checkbox.partial.html | 0 .../input/textarea-secret.directive.js | 6 ++- awx/ui/client/lib/models/Credential.js | 7 ++- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 awx/ui/client/lib/components/input/checkbox.directive.js create mode 100644 awx/ui/client/lib/components/input/checkbox.partial.html diff --git a/awx/ui/client/features/credentials/edit-credentials.controller.js b/awx/ui/client/features/credentials/edit-credentials.controller.js index 22b1cb7681..4f2ee0c122 100644 --- a/awx/ui/client/features/credentials/edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/edit-credentials.controller.js @@ -35,6 +35,7 @@ function EditCredentialsController (models, $state) { vm.form.save = data => { data.user = me.getSelf().id; + credential.clearTypeInputs(); return credential.request('put', data); }; diff --git a/awx/ui/client/lib/components/input/checkbox.directive.js b/awx/ui/client/lib/components/input/checkbox.directive.js new file mode 100644 index 0000000000..aaef13519d --- /dev/null +++ b/awx/ui/client/lib/components/input/checkbox.directive.js @@ -0,0 +1,44 @@ +function atInputCheckboxLink (scope, element, attrs, controllers) { + let formController = controllers[0]; + let inputController = controllers[1]; + + if (scope.tab === '1') { + element.find('input')[0].focus(); + } + + inputController.init(scope, element, formController); +} + +function AtInputCheckboxController (baseInputController) { + let vm = this || {}; + + vm.init = (scope, element, form) => { + baseInputController.call(vm, 'input', scope, element, form); + + vm.check(); + }; +} + +AtInputCheckboxController.$inject = ['BaseInputController']; + +function atInputCheckbox (pathService) { + return { + restrict: 'E', + transclude: true, + replace: true, + require: ['^^atForm', 'atInputCheckbox'], + templateUrl: pathService.getPartialPath('components/input/checkbox'), + controller: AtInputCheckboxController, + controllerAs: 'vm', + link: atInputCheckboxLink, + scope: { + state: '=', + col: '@', + tab: '@' + } + }; +} + +atInputCheckbox.$inject = ['PathService']; + +export default atInputCheckbox; diff --git a/awx/ui/client/lib/components/input/checkbox.partial.html b/awx/ui/client/lib/components/input/checkbox.partial.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/awx/ui/client/lib/components/input/textarea-secret.directive.js b/awx/ui/client/lib/components/input/textarea-secret.directive.js index 16b584292e..4ac462fbd0 100644 --- a/awx/ui/client/lib/components/input/textarea-secret.directive.js +++ b/awx/ui/client/lib/components/input/textarea-secret.directive.js @@ -37,9 +37,11 @@ function AtInputTextareaSecretController (baseInputController, eventService) { scope.buttonText = 'REPLACE'; } else { scope.state._hint = scope.state._hint || DEFAULT_HINT; - vm.listeners = vm.setFileListeners(textarea, input); - } + if (scope.state.format === 'ssh_private_key') { + vm.listeners = vm.setFileListeners(textarea, input); + } + } vm.updateModel(); }; diff --git a/awx/ui/client/lib/models/Credential.js b/awx/ui/client/lib/models/Credential.js index 371d2ad6e9..451472acab 100644 --- a/awx/ui/client/lib/models/Credential.js +++ b/awx/ui/client/lib/models/Credential.js @@ -33,11 +33,16 @@ function assignInputGroupValues (inputs) { }); } +function clearTypeInputs () { + delete this.model.GET.inputs; +} + function CredentialModel (method, resource) { BaseModel.call(this, 'credentials'); - + this.createFormSchema = createFormSchema.bind(this); this.assignInputGroupValues = assignInputGroupValues.bind(this); + this.clearTypeInputs = clearTypeInputs.bind(this); return this.request(method, resource) .then(() => this);