From b7a85f7f3c41fc0e38834acfd4844a11000e6d9f Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Wed, 7 Jan 2015 10:48:21 -0500 Subject: [PATCH] Job submission had to adjust the job submission to correctly pass empty strings for extra vars and for survey questions --- awx/ui/static/js/helpers/JobSubmission.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index 3dab45c91e..e86ca1038b 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -25,6 +25,7 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential // fld, extra_vars; + //found it easier to assume that there will be extra vars, and then check for a blank object at the end job_launch_data.extra_vars = {}; //gather the extra vars from the job template if survey is enabled and prompt for vars is false @@ -50,7 +51,7 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential }); }); - //build the data object to be sent to the job launch endpoint. + //build the data object to be sent to the job launch endpoint. Any variables gathered from the survey and the extra variables text editor are inserted into the extra_vars dict of the job_launch_data if (scope.removeBuildData) { scope.removeBuildData(); } @@ -63,22 +64,29 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential } if(scope.prompt_for_vars===true){ extra_vars = ToJSON(scope.parseType, scope.extra_vars, false); - $.each(extra_vars, function(key,value){ - job_launch_data.extra_vars[key] = value; - }); + if(!Empty(extra_vars)){ + $.each(extra_vars, function(key,value){ + job_launch_data.extra_vars[key] = value; + }); + } + } if(scope.survey_enabled===true){ for (var fld in scope.job_launch_form){ - if((scope[fld] || scope[fld] === 0) && scope.passwords_needed_to_start.indexOf(fld) === -1 && fld !== 'extra_vars'){ + //grab only survey question fields, including those that are zero or a blank answer (for optional questions) + if((scope[fld] || scope[fld] === 0 || scope[fld]==="") && scope.passwords_needed_to_start.indexOf(fld) === -1 && fld !== 'extra_vars'){ job_launch_data.extra_vars[fld] = scope[fld]; } } } + // include the credential used if the user was prompted to choose a cred if(!Empty(scope.credential)){ job_launch_data.credential_id = scope.credential; } - if(jQuery.isEmptyObject(job_launch_data.extra_vars)===true){ + + // If the extra_vars dict is empty, we don't want to include it if we didn't prompt for anything. + if(jQuery.isEmptyObject(job_launch_data.extra_vars)===true && scope.prompt_for_vars===false){ delete job_launch_data.extra_vars; }