diff --git a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js index 85d7480957..1438f89f37 100644 --- a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js +++ b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js @@ -37,6 +37,8 @@ $scope.mode = "add"; $scope.parseType = 'yaml'; $scope.credentialNotPresent = false; + $scope.canChangeProject = true; + $scope.canChangeInventory = true; md5Setup({ scope: $scope, diff --git a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js index 0884a04ca2..5e38774766 100644 --- a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js +++ b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js @@ -18,13 +18,15 @@ export default 'Empty', 'Prompt', 'ToJSON', 'GetChoices', 'CallbackHelpInit', 'InitiatePlaybookRun' , 'initSurvey', '$state', 'CreateSelect2', 'ToggleNotification','$q', 'InstanceGroupsService', 'InstanceGroupsData', 'MultiCredentialService', 'availableLabels', + 'canChangeProject', 'canChangeInventory', 'jobTemplateData', 'ParseVariableString', function( $filter, $scope, $rootScope, $location, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, GetBasePath, md5Setup, ParseTypeChange, Wait, selectedLabels, i18n, Empty, Prompt, ToJSON, GetChoices, CallbackHelpInit, InitiatePlaybookRun, SurveyControllerInit, $state, - CreateSelect2, ToggleNotification, $q, InstanceGroupsService, InstanceGroupsData, MultiCredentialService, availableLabels + CreateSelect2, ToggleNotification, $q, InstanceGroupsService, InstanceGroupsData, MultiCredentialService, availableLabels, + canChangeProject, canChangeInventory, jobTemplateData, ParseVariableString ) { $scope.$watch('job_template_obj.summary_fields.user_capabilities.edit', function(val) { @@ -47,6 +49,7 @@ export default function init() { CallbackHelpInit({ scope: $scope }); + $scope.playbook_options = null; $scope.playbook = null; $scope.mode = 'edit'; @@ -57,6 +60,8 @@ export default $scope.surveyTooltip = i18n._('Surveys allow users to be prompted at job launch with a series of questions related to the job. This allows for variables to be defined that affect the playbook run at time of launch.'); $scope.job_tag_options = []; $scope.skip_tag_options = []; + $scope.canChangeProject = canChangeProject; + $scope.canChangeInventory = canChangeInventory; SurveyControllerInit({ scope: $scope, @@ -253,7 +258,194 @@ export default $scope.rmoveLoadJobs(); } $scope.removeLoadJobs = $scope.$on('LoadJobs', function() { - $scope.fillJobTemplate(); + $scope.job_template_obj = jobTemplateData; + $scope.name = jobTemplateData.name; + var fld, i; + for (fld in form.fields) { + if (fld !== 'variables' && fld !== 'survey' && fld !== 'forks' && jobTemplateData[fld] !== null && jobTemplateData[fld] !== undefined) { + if (form.fields[fld].type === 'select') { + if ($scope[fld + '_options'] && $scope[fld + '_options'].length > 0) { + for (i = 0; i < $scope[fld + '_options'].length; i++) { + if (jobTemplateData[fld] === $scope[fld + '_options'][i].value) { + $scope[fld] = $scope[fld + '_options'][i]; + } + } + } else { + $scope[fld] = jobTemplateData[fld]; + } + } else { + $scope[fld] = jobTemplateData[fld]; + if(!Empty(jobTemplateData.summary_fields.survey)) { + $scope.survey_exists = true; + } + } + master[fld] = $scope[fld]; + } + if (fld === 'forks') { + if (jobTemplateData[fld] !== 0) { + $scope[fld] = jobTemplateData[fld]; + master[fld] = $scope[fld]; + } + } + if (fld === 'variables') { + // Parse extra_vars, converting to YAML. + $scope.variables = ParseVariableString(jobTemplateData.extra_vars); + master.variables = $scope.variables; + } + if (form.fields[fld].type === 'lookup' && jobTemplateData.summary_fields[form.fields[fld].sourceModel]) { + $scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + jobTemplateData.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + $scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField]; + } + if (form.fields[fld].type === 'checkbox_group') { + for(var j=0; j