From 206fb6b288ad8a6e413976dad6d202fdb0bcaf83 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Wed, 18 Mar 2015 15:15:48 -0400 Subject: [PATCH] On Job Template save: redirect to proper dest return to job template list if adding/editing a job template from the list; likewise return to hte inventory properties if adding/editing from that page --- awx/ui/static/js/controllers/Inventories.js | 39 ++++++++++++++++---- awx/ui/static/js/controllers/JobTemplates.js | 24 +++++++++++- awx/ui/static/js/forms/Inventories.js | 8 ++-- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 67cd2cc271..8360d1463b 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -482,7 +482,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) { + LookUpInit, GetBasePath, ParseTypeChange, Wait, ToJSON, ParseVariableString, Stream, RelatedSearchInit, RelatedPaginateInit, Prompt) { ClearScope(); @@ -490,6 +490,7 @@ 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, @@ -498,7 +499,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ form.well = true; form.formLabelSize = null; form.formFieldSize = null; - $scope.inventory_id = inventory_id; + $scope.inventory_id = inventory_id; generator.inject(form, { mode: 'edit', related: true, scope: $scope }); generator.reset(); @@ -509,8 +510,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ $scope.inventoryLoadedRemove(); } $scope.projectLoadedRemove = $scope.$on('inventoryLoaded', function () { - var set, opts=[]; - + var set; for (set in relatedSets) { $scope.search(relatedSets[set].iterator); } @@ -659,14 +659,37 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $ $location.path($location.path()+'/job_templates/'+this.scan_job_template.id); }; - $scope.deleteScanJob = function(){ - $location.path($location.path()+'/job_templates/add'); - }; + $scope.deleteScanJob = function () { + var id = this.scan_job_template.id , + action = function () { + $('#prompt-modal').modal('hide'); + Wait('start'); + var url = jobtemplateUrl+id; + Rest.setUrl(url); + Rest.destroy() + .success(function () { + $('#prompt-modal').modal('hide'); + $scope.search(form.related.scan_job_templates.iterator); + }) + .error(function (data) { + Wait('stop'); + ProcessErrors($scope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); + }); + }; + + Prompt({ + hdr: 'Delete', + 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' + 'PaginateInit', 'LookUpInit', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', 'Stream', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt' ]; diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index b2a0f26331..a898c50308 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -486,7 +486,17 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ function saveCompleted() { - setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500); + setTimeout(function() { + $scope.$apply(function() { + var base = $location.path().replace(/^\//, '').split('/')[0]; + if (base === 'job_templates') { + ReturnToCaller(); + } + else { + ReturnToCaller(1); + } + }); + }, 500); } if ($scope.removeTemplateSaveSuccess) { @@ -979,7 +989,17 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, }); function saveCompleted() { - setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500); + setTimeout(function() { + $scope.$apply(function() { + var base = $location.path().replace(/^\//, '').split('/')[0]; + if (base === 'job_templates') { + ReturnToCaller(); + } + else { + ReturnToCaller(1); + } + }); + }, 500); } if ($scope.removeTemplateSaveSuccess) { diff --git a/awx/ui/static/js/forms/Inventories.js b/awx/ui/static/js/forms/Inventories.js index a67919453d..00db33e3e6 100644 --- a/awx/ui/static/js/forms/Inventories.js +++ b/awx/ui/static/js/forms/Inventories.js @@ -99,14 +99,14 @@ export default related: { scan_job_templates: { type: 'collection', - title: 'Scan Jobs', + title: 'Scan Job Templates', iterator: 'scan_job_template', index: false, open: false, actions: { add: { - ngClick: "addScanJob(inventory_id)", + ngClick: "addScanJob()", icon: 'icon-plus', label: 'Add', awToolTip: 'Add a scan job template' @@ -127,14 +127,14 @@ export default fieldActions: { edit: { label: 'Edit', - ngClick: "editScanJob(inventory_id)", + ngClick: "editScanJob()", icon: 'icon-edit', awToolTip: 'Edit the scan job template', 'class': 'btn btn-default' }, "delete": { label: 'Delete', - ngClick: "deleteScanJob(inventory_id)", + ngClick: "deleteScanJob()", icon: 'icon-trash', "class": 'btn-danger', awToolTip: 'Delete the scan job template'