diff --git a/awx/ui/client/features/applications/list-applications.controller.js b/awx/ui/client/features/applications/list-applications.controller.js index e77ede25c0..fd67589a08 100644 --- a/awx/ui/client/features/applications/list-applications.controller.js +++ b/awx/ui/client/features/applications/list-applications.controller.js @@ -7,7 +7,6 @@ function ListApplicationsController ( $filter, $scope, $state, - Alert, Dataset, ProcessErrors, Prompt, @@ -57,82 +56,56 @@ function ListApplicationsController ( return html; }; - vm.deleteApplication = app => { - if (!app) { - Alert(strings.get('error.DELETE'), strings.get('alert.MISSING_PARAMETER')); - return; - } + vm.deleteApplication = (app) => { + const action = () => { + $('#prompt-modal').modal('hide'); + Wait('start'); + application.request('delete', app.id) + .then(() => { + let reloadListStateParams = null; - application.getDependentResourceCounts(application.id) - .then(counts => displayApplicationDeletePrompt(app, counts)); - }; + if ($scope.applications.length === 1 && $state.params.application_search && + !_.isEmpty($state.params.application_search.page) && + $state.params.application_search.page !== '1') { + const page = `${(parseInt(reloadListStateParams + .application_search.page, 10) - 1)}`; + reloadListStateParams = _.cloneDeep($state.params); + reloadListStateParams.application_search.page = page; + } - function createErrorHandler (path, action) { - return ({ data, status }) => { - const hdr = strings.get('error.HEADER'); - const msg = strings.get('error.CALL', { path, action, status }); - ProcessErrors($scope, data, status, null, { hdr, msg }); + if (parseInt($state.params.application_id, 10) === app.id) { + $state.go('^', reloadListStateParams, { reload: true }); + } else { + $state.go('.', reloadListStateParams, { reload: true }); + } + }) + .catch(({ data, status }) => { + ProcessErrors($scope, data, status, null, { + hdr: strings.get('error.HEADER'), + msg: strings.get('error.CALL', { path: `${application.path}${app.id}`, status }) + }); + }) + .finally(() => { + Wait('stop'); + }); }; - } - function handleSuccessfulDelete (app) { - const { page } = _.get($state.params, 'application_search'); - let reloadListStateParams = null; + const deleteModalBody = `