diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 9256860cb2..12ee00cba3 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -55,6 +55,8 @@ import 'tower/shared/InventoryTree'; import 'tower/shared/Timer'; import 'tower/shared/Socket'; +import 'tower/job-templates/main'; + /*#if DEBUG#*/ import {__deferLoadIfEnabled} from 'tower/debug'; __deferLoadIfEnabled(); @@ -74,6 +76,7 @@ var tower = angular.module('Tower', [ 'UserFormDefinition', 'FormGenerator', 'OrganizationListDefinition', + 'jobTemplates', 'UserListDefinition', 'UserHelper', 'PromptDialog', diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 4e1b44c0ff..b109ff26f9 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -13,6 +13,7 @@ * @description This controller's for the Inventory page */ +import 'tower/job-templates/main'; export function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $compile, $filter, Rest, Alert, InventoryList, generateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, Wait, Stream, @@ -483,7 +484,7 @@ InventoriesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, generateList, OrganizationList, SearchInit, PaginateInit, LookUpInit, GetBasePath, ParseTypeChange, Wait, ToJSON, ParseVariableString, Stream, RelatedSearchInit, RelatedPaginateInit, - Prompt, PlaybookRun, CreateDialog) { + Prompt, PlaybookRun, CreateDialog, deleteJobTemplate) { ClearScope(); @@ -491,7 +492,6 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ var defaultUrl = GetBasePath('inventory'), form = InventoryForm(), generator = GenerateForm, - jobtemplateUrl = GetBasePath('job_templates'), inventory_id = $routeParams.inventory_id, master = {}, fld, json_data, data, @@ -689,15 +689,6 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ "label": "Copy", "onClick": function() { copyAction(); - // setTimeout(function(){ - // scope.$apply(function(){ - // if(mode==='survey-taker'){ - // scope.$emit('SurveyTakerCompleted'); - // } else{ - // scope.saveSurvey(); - // } - // }); - // }); }, "icon": "fa-copy", "class": "btn btn-primary", @@ -816,9 +807,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ action = function () { $('#prompt-modal').modal('hide'); Wait('start'); - var url = jobtemplateUrl+id; - Rest.setUrl(url); - Rest.destroy() + deleteJobTemplate(id) .success(function () { $('#prompt-modal').modal('hide'); $scope.search(form.related.scan_job_templates.iterator); @@ -826,7 +815,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ .error(function (data) { Wait('stop'); ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); + msg: 'DELETE returned status: ' + status }); }); }; @@ -835,14 +824,15 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ body: '
Delete job template ' + this.scan_job_template.name + '?
', action: action }); - }; + + }; } InventoriesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'generateList', 'OrganizationList', 'SearchInit', 'PaginateInit', 'LookUpInit', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', 'Stream', 'RelatedSearchInit', 'RelatedPaginateInit', - 'Prompt', 'PlaybookRun', 'CreateDialog' + 'Prompt', 'PlaybookRun', 'CreateDialog', 'deleteJobTemplate' ]; diff --git a/awx/ui/static/js/job-templates/delete-job-template.service-test.js b/awx/ui/static/js/job-templates/delete-job-template.service-test.js new file mode 100644 index 0000000000..f1fcb871fc --- /dev/null +++ b/awx/ui/static/js/job-templates/delete-job-template.service-test.js @@ -0,0 +1,24 @@ +import jobTemplates from 'tower/job-templates/main'; +import {describeModule} from '../describe-module'; + +describeModule(jobTemplates.name) + .testService('deleteJobTemplate', function(test, restStub) { + + var service; + + test.withService(function(_service) { + service = _service; + }); + + it('deletes the job template', function() { + var result = {}; + + var actual = service(); + + restStub.succeedOn('destroy', result); + restStub.flush(); + + expect(actual).to.eventually.equal(result); + + }); + }); diff --git a/awx/ui/static/js/job-templates/delete-job-template.service.js b/awx/ui/static/js/job-templates/delete-job-template.service.js new file mode 100644 index 0000000000..a61754b460 --- /dev/null +++ b/awx/ui/static/js/job-templates/delete-job-template.service.js @@ -0,0 +1,20 @@ +var rest, getBasePath; + +export default + [ 'Rest', + 'GetBasePath', + function(_rest, _getBasePath) { + rest = _rest; + getBasePath = _getBasePath; + return deleteJobTemplate; + } + ]; + +function deleteJobTemplate(id) { + var url = getBasePath('job_templates'); + + url = url + id; + + rest.setUrl(url); + return rest.destroy(); +} diff --git a/awx/ui/static/js/job-templates/main.js b/awx/ui/static/js/job-templates/main.js new file mode 100644 index 0000000000..3daabbf1d6 --- /dev/null +++ b/awx/ui/static/js/job-templates/main.js @@ -0,0 +1,5 @@ +import deleteJobTemplate from './delete-job-template.service'; + +export default + angular.module('jobTemplates', []) + .service('deleteJobTemplate', deleteJobTemplate); diff --git a/awx/ui/tests/unit/rest-stub.js b/awx/ui/tests/unit/rest-stub.js index be91f1afe7..e73c3b735b 100644 --- a/awx/ui/tests/unit/rest-stub.js +++ b/awx/ui/tests/unit/rest-stub.js @@ -35,10 +35,19 @@ RestStub.prototype = return this.deferred.promise; }, + destroy: function() { + this.deferred = this.deferred || {}; + this.deferred.destroy = this[this.currentUrl]; + + return this.deferred.destroy.promise; + }, succeedAt: function(url, value) { assertUrlDeferred(url, this); this[url].resolve(value); }, + succeedOn: function(method, value) { + this.deferred[method] = value; + }, succeed: function(value) { this.deferred.resolve(value); },