Finally fixed issue with editing a credential. Need to call Owner change after loading data and after resetting form. Also removed default from Owner radio button on create and set to required so that user has to actively make a choice. Started working on Job Template detail changes. Job Template is currently broke.

This commit is contained in:
Chris Houseknecht 2013-11-02 19:37:52 +00:00 committed by Chris Church
parent 413a799829
commit 0466629718
6 changed files with 74 additions and 50 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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',

View File

@ -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;

View File

@ -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');
}

View File

@ -462,29 +462,35 @@ angular.module('Utilities',['RestServices', 'Utilities'])
}
}])
/* DeugForm(form_name)
/* DeugForm({ form: <form object>, scope: <current scope object> });
*
* 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() {