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 10754cb0e7..9efc8e5022 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 @@ -10,14 +10,14 @@ 'ProcessErrors', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'GetChoices', '$state', 'availableLabels', 'CreateSelect2', '$q', 'i18n', 'Inventory', 'Project', 'InstanceGroupsService', - 'MultiCredentialService', 'ConfigData', + 'MultiCredentialService', 'ConfigData', 'resolvedModels', function( $filter, $scope, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, GetBasePath, md5Setup, ParseTypeChange, Wait, Empty, ToJSON, CallbackHelpInit, GetChoices, $state, availableLabels, CreateSelect2, $q, i18n, Inventory, Project, InstanceGroupsService, - MultiCredentialService, ConfigData + MultiCredentialService, ConfigData, resolvedModels ) { // Inject dynamic view @@ -28,37 +28,38 @@ selectPlaybook, checkSCMStatus, callback; - init(); - function init(){ - // apply form definition's default field values - GenerateForm.applyDefaults(form, $scope); + const jobTemplate = resolvedModels[0]; - $scope.can_edit = true; - $scope.allow_callbacks = false; - $scope.playbook_options = []; - $scope.mode = "add"; - $scope.parseType = 'yaml'; - $scope.credentialNotPresent = false; - $scope.canGetAllRelatedResources = true; + $scope.canAddJobTemplate = jobTemplate.options('actions.POST'); - md5Setup({ - scope: $scope, - master: master, - check_field: 'allow_callbacks', - default_val: false - }); - CallbackHelpInit({ scope: $scope }); + // apply form definition's default field values + GenerateForm.applyDefaults(form, $scope); - $scope.surveyTooltip = i18n._('Please save before adding a survey to this job template.'); + $scope.can_edit = true; + $scope.allow_callbacks = false; + $scope.playbook_options = []; + $scope.mode = "add"; + $scope.parseType = 'yaml'; + $scope.credentialNotPresent = false; + $scope.canGetAllRelatedResources = true; - MultiCredentialService.getCredentialTypes() - .then(({ data }) => { - $scope.multiCredential = { - credentialTypes: data.results, - selectedCredentials: [] - }; - }); - } + md5Setup({ + scope: $scope, + master: master, + check_field: 'allow_callbacks', + default_val: false + }); + CallbackHelpInit({ scope: $scope }); + + $scope.surveyTooltip = i18n._('Please save before adding a survey to this job template.'); + + MultiCredentialService.getCredentialTypes() + .then(({ data }) => { + $scope.multiCredential = { + credentialTypes: data.results, + selectedCredentials: [] + }; + }); callback = function() { // Make sure the form controller knows there was a change diff --git a/awx/ui/client/src/templates/workflows/add-workflow/workflow-add.controller.js b/awx/ui/client/src/templates/workflows/add-workflow/workflow-add.controller.js index c725dbf1c6..5c998812ee 100644 --- a/awx/ui/client/src/templates/workflows/add-workflow/workflow-add.controller.js +++ b/awx/ui/client/src/templates/workflows/add-workflow/workflow-add.controller.js @@ -8,43 +8,47 @@ export default [ '$scope', 'WorkflowForm', 'GenerateForm', 'Alert', 'ProcessErrors', 'Wait', '$state', 'CreateSelect2', 'TemplatesService', 'ToJSON', 'ParseTypeChange', '$q', 'Rest', 'GetBasePath', 'availableLabels', 'i18n', + 'resolvedModels', function($scope, WorkflowForm, GenerateForm, Alert, ProcessErrors, Wait, $state, CreateSelect2, TemplatesService, ToJSON, - ParseTypeChange, $q, Rest, GetBasePath, availableLabels, i18n) { + ParseTypeChange, $q, Rest, GetBasePath, availableLabels, i18n, + resolvedModels) { // Inject dynamic view let form = WorkflowForm(), generator = GenerateForm; - function init() { - $scope.canEditOrg = true; - $scope.parseType = 'yaml'; - $scope.can_edit = true; - // apply form definition's default field values - GenerateForm.applyDefaults(form, $scope); + const workflowTemplate = resolvedModels[1]; - // Make the variables textarea look pretty - ParseTypeChange({ - scope: $scope, - field_id: 'workflow_job_template_variables', - onChange: function() { - // Make sure the form controller knows there was a change - $scope[form.name + '_form'].$setDirty(); - } - }); + $scope.canAddWorkflowJobTemplate = workflowTemplate.options('actions.POST'); - $scope.labelOptions = availableLabels - .map((i) => ({label: i.name, value: i.id})); + $scope.canEditOrg = true; + $scope.parseType = 'yaml'; + $scope.can_edit = true; + // apply form definition's default field values + GenerateForm.applyDefaults(form, $scope); - CreateSelect2({ - element:'#workflow_job_template_labels', - multiple: true, - addNew: true - }); + // Make the variables textarea look pretty + ParseTypeChange({ + scope: $scope, + field_id: 'workflow_job_template_variables', + onChange: function() { + // Make sure the form controller knows there was a change + $scope[form.name + '_form'].$setDirty(); + } + }); - $scope.workflowEditorTooltip = i18n._("Please save before defining the workflow graph."); - $scope.surveyTooltip = i18n._('Please save before adding a survey to this workflow.'); - } + $scope.labelOptions = availableLabels + .map((i) => ({label: i.name, value: i.id})); + + CreateSelect2({ + element:'#workflow_job_template_labels', + multiple: true, + addNew: true + }); + + $scope.workflowEditorTooltip = i18n._("Please save before defining the workflow graph."); + $scope.surveyTooltip = i18n._('Please save before adding a survey to this workflow.'); $scope.formSave = function () { let fld, data = {}; @@ -167,7 +171,5 @@ export default [ $scope.formCancel = function () { $state.transitionTo('templates'); }; - - init(); } ];