From ec140fb7daa7ae90a3f99dd6876636e3436fd65d Mon Sep 17 00:00:00 2001 From: Leigh Johnson Date: Wed, 19 Oct 2016 12:45:22 -0500 Subject: [PATCH] Hack copying of job_template.related.survey_spec into ui job copy flow, resolves #3737 --- .../copy/job-templates-copy.service.js | 89 +++++++++++-------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/awx/ui/client/src/job-templates/copy/job-templates-copy.service.js b/awx/ui/client/src/job-templates/copy/job-templates-copy.service.js index 53e86a78bb..a6f937cd58 100644 --- a/awx/ui/client/src/job-templates/copy/job-templates-copy.service.js +++ b/awx/ui/client/src/job-templates/copy/job-templates-copy.service.js @@ -5,39 +5,56 @@ *************************************************/ export default - ['$rootScope', 'Rest', 'ProcessErrors', 'GetBasePath', 'moment', - function($rootScope, Rest, ProcessErrors, GetBasePath, moment){ - return { - get: function(id){ - var defaultUrl = GetBasePath('job_templates') + '?id=' + id; - Rest.setUrl(defaultUrl); - return Rest.get() - .success(function(res){ - return res; - }) - .error(function(res, status){ - ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', - msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); - }); - }, - set: function(data){ - var defaultUrl = GetBasePath('job_templates'); - Rest.setUrl(defaultUrl); - var name = this.buildName(data.results[0].name); - data.results[0].name = name + ' @ ' + moment().format('h:mm:ss a'); // 2:49:11 pm - return Rest.post(data.results[0]) - .success(function(res){ - return res; - }) - .error(function(res, status){ - ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', - msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); - }); - }, - buildName: function(name){ - var result = name.split('@')[0]; - return result; - } - }; - } - ]; + ['$rootScope', 'Rest', 'ProcessErrors', 'GetBasePath', 'moment', + function($rootScope, Rest, ProcessErrors, GetBasePath, moment){ + return { + get: function(id){ + var defaultUrl = GetBasePath('job_templates') + '?id=' + id; + Rest.setUrl(defaultUrl); + return Rest.get() + .success(function(res){ + return res; + }) + .error(function(res, status){ + ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', + msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); + }); + }, + getSurvey: function(endpoint){ + Rest.setUrl(endpoint); + return Rest.get(); + }, + copySurvey: function(source, target){ + return this.getSurvey(source.related.survey_spec).success( (data) => { + Rest.setUrl(target.related.survey_spec); + return Rest.post(data); + }); + }, + set: function(data){ + var defaultUrl = GetBasePath('job_templates'); + var self = this; + Rest.setUrl(defaultUrl); + var name = this.buildName(data.results[0].name); + data.results[0].name = name + ' @ ' + moment().format('h:mm:ss a'); // 2:49:11 pm + return Rest.post(data.results[0]) + .success(function(job_template_res){ + // also copy any associated survey_spec + if (data.results[0].related.survey_spec){ + return self.copySurvey(data.results[0], job_template_res).success( () => job_template_res); + } + else{ + return job_template_res; + } + }) + .error(function(res, status){ + ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', + msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); + }); + }, + buildName: function(name){ + var result = name.split('@')[0]; + return result; + } + }; + } + ];