From fc866640be9f7e732f0fece47ae4351c7dcb5d2e Mon Sep 17 00:00:00 2001 From: artoscinote <85488244+artoscinote@users.noreply.github.com> Date: Thu, 28 Oct 2021 12:49:26 +0200 Subject: [PATCH] Improved/removed annoying reloads when managing user access [SCI-6170] (#3618) --- app/assets/javascripts/projects/index.js | 57 +------------------ .../shared/modal_close_redirect.js | 7 ++- .../experiments/modals/_edit_modal.html.erb | 2 +- .../experiments/modals/_show_modal.html.erb | 2 +- .../projects/modals/_edit_modal.html.erb | 2 +- .../projects/modals/_show_modal.html.erb | 2 +- 6 files changed, 10 insertions(+), 62 deletions(-) diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index 31cd7c216..0044f23ca 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -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("" + data.error + ''); - } - } - }); - } - - // 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(); diff --git a/app/assets/javascripts/shared/modal_close_redirect.js b/app/assets/javascripts/shared/modal_close_redirect.js index fd33745b4..15c060d03 100644 --- a/app/assets/javascripts/shared/modal_close_redirect.js +++ b/app/assets/javascripts/shared/modal_close_redirect.js @@ -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); + } }); } diff --git a/app/views/access_permissions/experiments/modals/_edit_modal.html.erb b/app/views/access_permissions/experiments/modals/_edit_modal.html.erb index 8b68f3aa0..684082584 100644 --- a/app/views/access_permissions/experiments/modals/_edit_modal.html.erb +++ b/app/views/access_permissions/experiments/modals/_edit_modal.html.erb @@ -1,6 +1,6 @@ <% # frozen_string_literal: true %> -