diff --git a/awx/ui/static/js/controllers/Credentials.js b/awx/ui/static/js/controllers/Credentials.js index 18470deceb..5dc5d3f5f7 100644 --- a/awx/ui/static/js/controllers/Credentials.js +++ b/awx/ui/static/js/controllers/Credentials.js @@ -116,7 +116,7 @@ function CredentialsAdd ($scope, $rootScope, $compile, $location, $log, $routePa LookUpInit({ scope: scope, form: form, - current_item: ($routeParams.user_id) ? $routeParams.user_id : null, + current_item: (!Empty($routeParams.user_id)) ? $routeParams.user_id : null, list: UserList, field: 'user' }); @@ -124,7 +124,7 @@ function CredentialsAdd ($scope, $rootScope, $compile, $location, $log, $routePa LookUpInit({ scope: scope, form: form, - current_item: ($routeParams.team_id) ? $routeParams.team_id : null, + current_item: (!Empty($routeParams.team_id)) ? $routeParams.team_id : null, list: TeamList, field: 'team' }); @@ -188,7 +188,7 @@ function CredentialsAdd ($scope, $rootScope, $compile, $location, $log, $routePa data['kind'] = scope['kind'].value; - if (!Empty(data.team) && Empty(data.user)) { + if (Empty(data.team) && Empty(data.user)) { Alert('Missing User or Team', 'You must provide either a User or a Team. If this credential will only be accessed by a specific ' + 'user, select a User. To allow a team of users to access this credential, select a Team.', 'alert-danger'); } @@ -306,7 +306,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP LookUpInit({ scope: scope, form: form, - current_item: ($scope['user_id']) ? scope['user_id'] : null, + current_item: (!Empty($scope['user_id'])) ? scope['user_id'] : null, list: UserList, field: 'user' }); @@ -314,13 +314,14 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP LookUpInit({ scope: scope, form: form, - current_item: ($scope['team_id']) ? scope['team_id'] : null, + current_item: (!Empty($scope['team_id'])) ? scope['team_id'] : null, list: TeamList, field: 'team' }); setAskCheckboxes(); KindChange({ scope: scope, form: form, reset: false }); + OwnerChange({ scope: scope }); }); if (scope.removeChoicesReady) { @@ -428,6 +429,8 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP scope[fld] = master[fld]; } setAskCheckboxes(); + KindChange({ scope: scope, form: form, reset: false }); + OwnerChange({ scope: scope }); }; // Related set: Add button diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 6b3905c042..98d8392202 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -124,6 +124,7 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP }); LookUpInit({ + url: GetBasePath('credentials') + '?cloud=false', scope: scope, form: form, current_item: null, @@ -131,6 +132,15 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP field: 'credential' }); + LookUpInit({ + url: GetBasePath('credentials') + '?cloud=true', + scope: scope, + form: form, + current_item: null, + list: CredentialList, + field: 'cloud_credential' + }); + // Update playbook select whenever project value changes var selectPlaybook = function(oldValue, newValue) { if (oldValue != newValue) { diff --git a/awx/ui/static/js/forms/JobTemplates.js b/awx/ui/static/js/forms/JobTemplates.js index 9df0df72ce..a7bc3eaeb6 100644 --- a/awx/ui/static/js/forms/JobTemplates.js +++ b/awx/ui/static/js/forms/JobTemplates.js @@ -72,7 +72,7 @@ angular.module('JobTemplateFormDefinition', []) awRequiredWhen: {variable: "playbookrequired", init: "true" }, column: 1 }, - credential: { // FIXME: Lookup only credentials with kind=ssh + credential: { label: 'Credential', type: 'lookup', sourceModel: 'credential', @@ -82,7 +82,7 @@ angular.module('JobTemplateFormDefinition', []) editRequired: false, column: 1 }, - cloud_credential: { // FIXME: Lookup only credentials with kind=aws/rax + cloud_credential: { label: 'Cloud Credential', type: 'lookup', sourceModel: 'cloud_credential', diff --git a/awx/ui/static/js/helpers/Credentials.js b/awx/ui/static/js/helpers/Credentials.js index 239858e9d8..2d3fd0708f 100644 --- a/awx/ui/static/js/helpers/Credentials.js +++ b/awx/ui/static/js/helpers/Credentials.js @@ -16,34 +16,36 @@ angular.module('CredentialsHelper', ['Utilities']) var form = params.form; var reset = params.reset; - // Set field labels - if (scope.kind.value !== 'ssh') { - scope['usernameLabel'] = 'Username'; - scope['passwordLabel'] = 'Password'; - scope['passwordConfirmLabel'] = 'Confirm Password'; - scope['sshKeyDataLabel'] = 'SCM Private Key'; - } - else { - scope['usernameLabel'] = 'SSH Username'; - scope['passwordLabel'] = 'SSH Password'; - scope['passwordConfirmLabel'] = 'Confirm SSH Password'; - scope['sshKeyDataLabel'] = 'SSH Private Key'; - } + // Put things in a default state + scope['usernameLabel'] = 'Username'; + scope['passwordLabel'] = 'Password'; + scope['passwordConfirmLabel'] = 'Confirm Password'; + scope['aws_required'] = false; + scope['rackspace_required'] = false; + scope['sshKeyDataLabel'] = 'SSH Private Key'; + form.fields['password'].clear = true; + form.fields['password'].ask = true; - scope['aws_required'] = (scope.kind.value == 'aws') ? true : false; - - if (scope.kind.value == 'rax') { - scope['rackspace_required'] = true; - form.fields['password'].clear = true; - form.fields['password'].ask = true; - } - else { - scope['rackspace_required'] = false; - form.fields['password'].clear = false; - form.fields['password'].ask = false; - } + // Apply kind specific settings + switch(scope['kind'].value) { + case 'aws': + scope['aws_required'] = true; + break; + case 'rax': + scope['rackspace_required'] = true; + form.fields['password'].ask = false; + break; + case 'ssh': + scope['usernameLabel'] = 'SSH Username'; + scope['passwordLabel'] = 'SSH Password'; + scope['passwordConfirmLabel'] = 'Confirm SSH Password'; + break; + case 'scm': + scope['sshKeyDataLabel'] = 'SCM Private Key'; + break; + } - // Reset all the fields related to Kind. + // Reset all the field values related to Kind. if (reset) { scope['access_key'] = null; scope['secret_key'] = null; diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 70f8050d04..8f6a328b9c 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -610,15 +610,18 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' } var data = { - name: form.name, - description: form.description, - scm_tags: '' }; + name: scope['name'], + description: scope['description'], + }; if (inventory_id) { data['inventory'] = inventory_id; } - if (json_data) { + if ($.isEmptyObject(json_data)) { + data['variables'] = ""; + } + else { data['variables'] = JSON.stringify(json_data, undefined, '\t'); } diff --git a/awx/ui/static/lib/ansible/Utilities.js b/awx/ui/static/lib/ansible/Utilities.js index b709fa0fa6..b626bc529a 100644 --- a/awx/ui/static/lib/ansible/Utilities.js +++ b/awx/ui/static/lib/ansible/Utilities.js @@ -462,29 +462,35 @@ angular.module('Utilities',['RestServices', 'Utilities']) } }]) - /* DeugForm(form_name) + /* DeugForm({ form:
, scope: }); * - * Use to log the $pristine and $invalid properties of each form element. Helpful when form + * Use to log the $pristine and $valid properties of each form element. Helpful when form * buttons fail to enable/disable properly. * */ .factory('DebugForm', [ function() { - return function(form_name) { - $('form[name="' + form_name + '"]').find('select, input, button, textarea').each(function(index){ - var name = $(this).attr('name'); - if (name) { - if (scope['job_templates_form'][name]) { - console.log(name + ' pristine: ' + scope['job_templates_form'][name].$pristine); - console.log(name + ' invalid: ' + scope['job_templates_form'][name].$invalid); - } - } - }); + return function(params) { + var form = params.form; + var scope = params.scope; + for (var fld in form.fields) { + if (scope[form.name + '_form'][fld]) { + console.log(fld + ' valid: ' + scope[form.name + '_form'][fld].$valid); + } + if (form.fields[fld].sourceModel) { + if (scope[form.name + '_form'][form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField]) { + console.log(form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField + ' valid: ' + + scope[form.name + '_form'][form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField].$valid); + } + } + } + console.log('form pristine: ' + scope[form.name + '_form'].$pristine); + console.log('form valid: ' + scope[form.name + '_form'].$valid); } }]) /* Empty() * - * Test if a value is 'empty'. Returns true if val is null/''/undefined + * Test if a value is 'empty'. Returns true if val is null | '' | undefined * */ .factory('Empty', [ function() {