From b0c031e4e3ffd0e434a2b1bbbe79375ada943986 Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:42:59 +0100 Subject: [PATCH] Fix duplicate assignment modals (#3636) Co-authored-by: Anton --- app/assets/javascripts/shared/modal_close_redirect.js | 7 ------- app/assets/javascripts/shared/remote_modal.js | 11 ++++++++--- .../partials/_new_assignments_form.html.erb | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/shared/modal_close_redirect.js b/app/assets/javascripts/shared/modal_close_redirect.js index ad9786519..15c060d03 100644 --- a/app/assets/javascripts/shared/modal_close_redirect.js +++ b/app/assets/javascripts/shared/modal_close_redirect.js @@ -10,13 +10,6 @@ Turbolinks.visit(targetPath); } }); - - $(document).on('ajax:success', 'form[data-action*="modal-close"]', function(_, { form, flash }) { - $(this).closest('.modal').modal('hide'); - if (flash) { - HelperModule.flashAlertMsg(flash, 'success'); - } - }); } $(document).one('turbolinks:load', initModalCloseListeners); diff --git a/app/assets/javascripts/shared/remote_modal.js b/app/assets/javascripts/shared/remote_modal.js index bd4e2745e..bc680e28a 100644 --- a/app/assets/javascripts/shared/remote_modal.js +++ b/app/assets/javascripts/shared/remote_modal.js @@ -9,9 +9,14 @@ animateSpinner(); $.get(ev.currentTarget.getAttribute('href')).then(function({ modal }) { - $(modal).on('shown.bs.modal', function() { - $(this).find('.selectpicker').selectpicker(); - }).modal('show'); + $(modal) + .on('shown.bs.modal', function() { + $(this).find('.selectpicker').selectpicker(); + }) + .on('hidden.bs.modal', function() { + $(this).remove(); + }) + .modal('show'); animateSpinner(null, false); }); }); diff --git a/app/views/access_permissions/partials/_new_assignments_form.html.erb b/app/views/access_permissions/partials/_new_assignments_form.html.erb index 01534a3b5..15f62e1f7 100644 --- a/app/views/access_permissions/partials/_new_assignments_form.html.erb +++ b/app/views/access_permissions/partials/_new_assignments_form.html.erb @@ -10,7 +10,7 @@ <%= t '.title', resource_name: resource.name %> - <%= form_with(model: form_object, url: create_path, method: :post, remote: true, html: { id: 'new-user-assignment-to-project-form', data: { action: 'modal-close' } }) do |f| %> + <%= form_with(model: form_object, url: create_path, method: :post, remote: true, html: { id: 'new-user-assignment-to-project-form', data: { action: 'replace-form', target: '#user_assignments_modal' } }) do |f| %>