From 01276808055b90bca9282931ae778b8848de2166 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 20 Nov 2013 06:06:13 +0000 Subject: [PATCH] AC-657 Fixed order of operations for prompting user to approve delete, starting spinner, sending request to API, stoping spinner and refreshing page. The key is starting the spinner using the modal.on.hidden.bs.modal to start the spinner and then not stopping it until inside postrefresh event. Applied the fix to all controllers and tested. --- awx/ui/static/js/controllers/Credentials.js | 12 +++++++----- awx/ui/static/js/controllers/Inventories.js | 12 ++++++++---- awx/ui/static/js/controllers/JobTemplates.js | 17 ++++++++++++----- awx/ui/static/js/controllers/Organizations.js | 15 +++++++++++---- awx/ui/static/js/controllers/Permissions.js | 15 +++++++++++---- awx/ui/static/js/controllers/Projects.js | 12 +++++++----- awx/ui/static/js/helpers/Groups.js | 12 ++---------- awx/ui/static/js/helpers/Hosts.js | 12 +++++++----- 8 files changed, 65 insertions(+), 42 deletions(-) diff --git a/awx/ui/static/js/controllers/Credentials.js b/awx/ui/static/js/controllers/Credentials.js index e9e8213236..e26e70c5e0 100644 --- a/awx/ui/static/js/controllers/Credentials.js +++ b/awx/ui/static/js/controllers/Credentials.js @@ -33,6 +33,10 @@ function CredentialsList ($scope, $rootScope, $location, $log, $routeParams, Res scope.removePostRefresh(); } scope.removePostRefresh = scope.$on('PostRefresh', function() { + // Cleanup after a delete + Wait('stop'); + $('#prompt-modal').off(); + list.fields.kind.searchOptions = scope.credential_kind_options; // Translate the kind value @@ -88,20 +92,18 @@ function CredentialsList ($scope, $rootScope, $location, $log, $routeParams, Res scope.deleteCredential = function(id, name) { var action = function() { - Wait('start'); + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); + $('#prompt-modal').modal('hide'); var url = defaultUrl + id + '/'; Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - Wait('stop'); - $('#prompt-modal').modal('hide'); scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); - $('#prompt-modal').modal('hide'); ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); + { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); }); }; diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index a2457ae4ec..f042f15d8f 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -67,6 +67,10 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res scope.removePostRefresh(); } scope.removePostRefresh = scope.$on('PostRefresh', function() { + //If we got here by deleting an inventory, stop the spinner and cleanup events + Wait('stop'); + $('#prompt-modal').off(); + for (var i=0; i < scope.inventories.length; i++) { // Set values for Failed Hosts column @@ -152,15 +156,15 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res scope.deleteInventory = function(id, name) { var action = function() { - Wait('start'); var url = defaultUrl + id + '/'; + $('#prompt-modal').on('hidden.bs.modal', function() { + Wait('start'); + }); $('#prompt-modal').modal('hide'); - Wait('start'); Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - scope.search(list.iterator); - Wait('stop'); + scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 36967f3b4a..b9f64cd4bc 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -25,6 +25,15 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re var scope = view.inject(list, { mode: mode }); $rootScope.flashMessage = null; + if (scope.removePostRefresh) { + scope.removePostRefresh(); + } + scope.removePostRefresh = scope.$on('PostRefresh', function() { + // Cleanup after a delete + Wait('stop'); + $('#prompt-modal').off(); + }); + SearchInit({ scope: scope, set: 'job_templates', list: list, url: defaultUrl }); PaginateInit({ scope: scope, list: list, url: defaultUrl }); @@ -51,20 +60,18 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re scope.deleteJobTemplate = function(id, name) { var action = function() { - Wait('start'); + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); + $('#prompt-modal').modal('hide'); var url = defaultUrl + id + '/'; Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - Wait('stop'); - $('#prompt-modal').modal('hide'); scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); - $('#prompt-modal').modal('hide'); ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); + { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); }); }; diff --git a/awx/ui/static/js/controllers/Organizations.js b/awx/ui/static/js/controllers/Organizations.js index f9df59c865..67dd5f908d 100644 --- a/awx/ui/static/js/controllers/Organizations.js +++ b/awx/ui/static/js/controllers/Organizations.js @@ -31,6 +31,15 @@ function OrganizationsList ($routeParams, $scope, $rootScope, $location, $log, R var url = GetBasePath('projects') + $routeParams.project_id + '/organizations/'; SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 }); + if (scope.removePostRefresh) { + scope.removePostRefresh(); + } + scope.removePostRefresh = scope.$on('PostRefresh', function() { + // Cleanup after a delete + Wait('stop'); + $('#prompt-modal').off(); + }); + // Initialize search and paginate pieces and load data SearchInit({ scope: scope, set: list.name, list: list, url: defaultUrl }); PaginateInit({ scope: scope, list: list, url: defaultUrl }); @@ -49,18 +58,16 @@ function OrganizationsList ($routeParams, $scope, $rootScope, $location, $log, R scope.deleteOrganization = function(id, name) { var action = function() { - Wait('start'); + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); + $('#prompt-modal').modal('hide'); var url = defaultUrl + id + '/'; Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - Wait('stop'); - $('#prompt-modal').modal('hide'); scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); - $('#prompt-modal').modal('hide'); ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); }); diff --git a/awx/ui/static/js/controllers/Permissions.js b/awx/ui/static/js/controllers/Permissions.js index 78f3453e72..2e4ed0e3b1 100644 --- a/awx/ui/static/js/controllers/Permissions.js +++ b/awx/ui/static/js/controllers/Permissions.js @@ -16,6 +16,15 @@ function PermissionsList ($scope, $rootScope, $location, $log, $routeParams, Res scope.selected = []; CheckAccess({ scope: scope }); + + if (scope.removePostRefresh) { + scope.removePostRefresh(); + } + scope.removePostRefresh = scope.$on('PostRefresh', function() { + // Cleanup after a delete + Wait('stop'); + $('#prompt-modal').off(); + }); SearchInit({ scope: scope, set: 'permissions', list: list, url: defaultUrl }); PaginateInit({ scope: scope, list: list, url: defaultUrl }); @@ -35,18 +44,16 @@ function PermissionsList ($scope, $rootScope, $location, $log, $routeParams, Res scope.deletePermission = function(id, name) { var action = function() { - Wait('start'); + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); + $('#prompt-modal').modal('hide'); var url = GetBasePath('base') + 'permissions/' + id + '/'; Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - Wait('stop'); - $('#prompt-modal').modal('hide'); scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); - $('#prompt-modal').modal('hide'); ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); }); diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index db71fa08e5..763d058832 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -36,6 +36,10 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, scope.removePostRefresh(); } scope.removePostRefresh = scope.$on('PostRefresh', function() { + // Cleanup after a delete + Wait('stop'); + $('#prompt-modal').off(); + if (scope.projects) { for (var i=0; i < scope.projects.length; i++) { if (scope.projects[i].status == 'ok') { @@ -114,20 +118,18 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, scope.deleteProject = function(id, name) { var action = function() { - Wait('start'); + $('#prompt-modal').on('hiden.bs.modal', function(){ Wait('start'); }); + $('#prompt-modal').modal('hide'); var url = defaultUrl + id + '/'; Rest.setUrl(url); Rest.destroy() .success( function(data, status, headers, config) { - Wait('stop'); - $('#prompt-modal').modal('hide'); scope.search(list.iterator); }) .error( function(data, status, headers, config) { Wait('stop'); - $('#prompt-modal').modal('hide'); ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); + { hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); }); }; diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index cd5534abd3..81d03788ac 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -1076,7 +1076,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' var inventory_id = params.inventory_id; var obj = scope['selectedNode']; var parent = obj.parent().parent(); - //var parent = (obj.parent().last().prop('tagName') == 'LI') ? obj.parent().last() : obj.parent().parent().last(); var url; if (parent.attr('data-group-id')) { @@ -1086,8 +1085,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' url = GetBasePath('inventory') + inventory_id + '/groups/'; } var action_to_take = function() { + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); $('#prompt-modal').modal('hide'); - Wait('start'); Rest.setUrl(url); Rest.post({ id: group_id, disassociate: 1 }) .success( function(data, status, headers, config) { @@ -1101,7 +1100,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' id: parent.attr('id'), moveable: true }); - Wait('stop'); + $('#prompt-modal').off(); }) .error( function(data, status, headers, config) { Wait('stop'); @@ -1143,13 +1142,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' 'You must first edit the group, provide Source settings, and then run an update.', 'alert-info'); } else { - if ($rootScope.removeShowStatus) { - $rootScope.removeShowStatus(); - } - $rootScope.removeShowStatus = $rootScope.$on('showStatus', function(e, results) { - - }); - // Retrieve detail record and prepopulate the form Rest.setUrl(last_update); Rest.get() diff --git a/awx/ui/static/js/helpers/Hosts.js b/awx/ui/static/js/helpers/Hosts.js index b1d3dec0ff..086d15a211 100644 --- a/awx/ui/static/js/helpers/Hosts.js +++ b/awx/ui/static/js/helpers/Hosts.js @@ -435,8 +435,8 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H .factory('HostsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'Prompt', 'ProcessErrors', 'GetBasePath', - 'HostsReload', - function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload) { + 'HostsReload', 'Wait', + function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload, Wait) { return function(params) { // Remove the selected host from the current group by disassociating @@ -454,18 +454,20 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H scope.removeHostsReload(); } scope.removeHostsReload = scope.$on('hostsReload', function() { + params.action = function() { $('#prompt-modal').off(); Wait('stop'); } HostsReload(params); }); var action_to_take = function() { + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }) + $('#prompt-modal').modal('hide'); Rest.setUrl(url); Rest.post({ id: host_id, disassociate: 1 }) - .success( function(data, status, headers, config) { - $('#prompt-modal').modal('hide'); + .success( function(data, status, headers, config) { scope.$emit('hostsReload'); }) .error( function(data, status, headers, config) { - $('#prompt-modal').modal('hide'); + Wait('stop'); scope.$emit('hostsReload'); ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Attempt to delete ' + host_name + ' failed. POST returned status: ' + status });