1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

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.

This commit is contained in:
Chris Houseknecht 2013-11-20 06:06:13 +00:00
parent 4bc15a4392
commit 0127680805
8 changed files with 65 additions and 42 deletions

View File

@ -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 });
});
};

View File

@ -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');

View File

@ -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 });
});
};

View File

@ -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 });
});

View File

@ -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 });
});

View File

@ -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 });
});
};

View File

@ -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()

View File

@ -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 });