Improved/removed annoying reloads when managing user access [SCI-6170] (#3618)

This commit is contained in:
artoscinote 2021-10-28 12:49:26 +02:00 committed by GitHub
parent 98be1ae0ff
commit fc866640be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 62 deletions

View file

@ -17,7 +17,6 @@ var ProjectsIndex = (function() {
var editProjectModal = '#edit-modal';
var moveToModal = '#move-to-modal';
var manageProjectUsersModal = null;
var exportProjectsModal = null;
var exportProjectsModalHeader = null;
var exportProjectsModalBody = null;
@ -173,7 +172,7 @@ var ProjectsIndex = (function() {
function initManageUsersModal() {
// Reload users tab HTML element when modal is closed
manageProjectUsersModal.on('hide.bs.modal', function() {
$(document).on('ajax:success', '#user_assignments_modal form', function() {
refreshCurrentView();
});
}
@ -259,56 +258,6 @@ var ProjectsIndex = (function() {
});
}
// Initialize ajax listeners and elements style on modal body. This
// function must be called when modal body is changed.
function initManageProjectUsersModalBody(data) {
manageProjectUsersModal.find('.modal-title').html(data.html_title);
manageProjectUsersModal.find('.modal-body').html(data.html_body).find('.selectpicker').selectpicker();
manageProjectUsersModal.find('.modal-footer').html(data.html_footer);
}
// Initialize reloading manage user modal content after posting new
// user.
function initAddUserForm() {
manageProjectUsersModal
.on('ajax:success', '.add-user-form', function(e, data) {
var errorBlock;
initManageProjectUsersModalBody(data);
if (data.status === 'error') {
$(this).addClass('has-error');
errorBlock = $(this).find('span.help-block');
if (errorBlock.length && errorBlock.length > 0) {
errorBlock.html(data.error);
} else {
$(this).append("<span class='help-block col-xs-8'>" + data.error + '</span>');
}
}
});
}
// Initialize remove user from project links.
function initRemoveUserLinks() {
manageProjectUsersModal.on('ajax:success', '.remove-user-link', function(e, data) {
initManageProjectUsersModalBody(data);
});
}
//
function initUserRoleForms() {
manageProjectUsersModal
.on('change', '.update-user-form select', function() {
$(this).parents('form').submit();
});
manageProjectUsersModal
.on('ajax:success', '.update-user-form', function(e, data) {
initManageProjectUsersModalBody(data);
})
.on('ajax:error', function() {
// TODO
});
}
function updateSelectedCards() {
$('.project-card').removeClass('selected');
$.each(selectedProjects, function(index, value) {
@ -663,7 +612,6 @@ var ProjectsIndex = (function() {
* Initializes cards view
*/
function init() {
manageProjectUsersModal = $('#manageProjectUsersModal');
exportProjectsModal = $('#export-projects-modal');
exportProjectsModalHeader = exportProjectsModal.find('.modal-title');
exportProjectsModalBody = exportProjectsModal.find('.modal-body');
@ -676,9 +624,6 @@ var ProjectsIndex = (function() {
initExportProjects();
initDeleteFoldersToolbarButton();
initArchiveRestoreToolbarButtons();
initAddUserForm();
initRemoveUserLinks();
initUserRoleForms();
initEditButton();
initMoveButton();
initProjectsViewModeSwitch();

View file

@ -4,8 +4,11 @@
function initModalCloseListeners() {
$(document).on('hidden.bs.modal', '[data-action*="modal-close"]', function({ currentTarget }) {
let targetPath = currentTarget.getAttribute('data-target');
animateSpinner();
Turbolinks.visit(targetPath);
if (targetPath) {
animateSpinner();
Turbolinks.visit(targetPath);
}
});
}

View file

@ -1,6 +1,6 @@
<% # frozen_string_literal: true %>
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close" data-target="<%= project_path %>">
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="user_assignments_modal">
<div class="modal-header">

View file

@ -1,6 +1,6 @@
<% # frozen_string_literal: true %>
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close" data-target="<%= project_path %>">
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content" id="user_assignments_modal">
<div class="modal-header">

View file

@ -1,6 +1,6 @@
<% # frozen_string_literal: true %>
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close" data-target="<%= projects_path %>">
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close">
<div class="modal-dialog modal-lg" role="document">
<%= render 'access_permissions/partials/edit_assignments_content', project: project, new_resource_path: new_resource_path, update_path: update_path %>
</div>

View file

@ -1,6 +1,6 @@
<% # frozen_string_literal: true %>
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close" data-target="<%= projects_path %>">
<div class="modal fade" tabindex="-1" role="dialog" data-action="modal-close">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="user_assignments_modal">
<div class="modal-header">