Skip to content

Commit

Permalink
Maintain pagination when an user role changes
Browse files Browse the repository at this point in the history
https://progress.opensuse.org/issues/47210

Problem: In the user administration page. When a role is changed
the page is reloaded loosing the page in the paginator.

Solution: Programmatically summit the form to prevent the page
reload. This solves the problem.
  • Loading branch information
ilausuch committed Jun 5, 2020
1 parent cafc562 commit 42e1242
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions assets/javascripts/admin_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@ function setup_admin_user() {
var username = $(this).parents('tr').find('.name').text();
var role = $(this).attr('id');
role = $('label[for="' + role + '"]').text();
if (confirm("Are you sure to put " + username + " into role: " + $.trim(role) + "?")) {
$(this).parent('form').submit();
} else {
$(this).parent('form').find('input[class="default"]').first().prop('checked', 'checked');

function findDefault(form) {
return form.find('input[class="default"]').first();
}

function rollback(form) {
findDefault(form).prop('checked', 'checked');
}
});

var form = $(this).parent('form');

if (confirm("Are you sure to put " + username + " into role: " + $.trim(role) + "?")) {
var data = form.serializeArray();
var newRole = data[1].value;

$.ajax({
type: 'POST',
url: form.attr('action'),
data: jQuery.param(data),
success: function(data){
findDefault(form).removeClass('default');
form.find('input[value="' + newRole + '"]').addClass('default');
},
error: function(err){
rollback(form);
addFlash('danger', 'An error occurred when changing the user role');
}
});
} else
rollback(form);
});
}

0 comments on commit 42e1242

Please sign in to comment.