OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Use a global turbo:submit-end event to close modal-dialogs when the form inside is submitted successfully.
Dombi Attilaa98c2d89ff1a
diff --git a/app/helpers/stimulus_helper.rb b/app/helpers/stimulus_helper.rbindex 524d12b45d5..7b3d726f1e4 100644--- a/app/helpers/stimulus_helper.rb+++ b/app/helpers/stimulus_helper.rb@@ -41,12 +41,4 @@ module StimulusHelperend# rubocop:enable Rails/HelperInstanceVariable-- def close_dialog_on_success_data- {- controller: 'form-dialog',- 'application-target': 'dynamic',- action: 'turbo:submit-end->form-dialog#closeOnSuccess'- }- endenddiff --git a/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.ts b/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.tsdeleted file mode 100644index 89b8117ecd2..00000000000--- a/frontend/src/stimulus/controllers/dynamic/form-dialog.controller.ts+++ /dev/null@@ -1,41 +0,0 @@-/*- * -- copyright- * OpenProject is an open source project management software.- * Copyright (C) 2023 the OpenProject GmbH- *- * This program is free software; you can redistribute it and/or- * modify it under the terms of the GNU General Public License version 3.- *- * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:- * Copyright (C) 2006-2013 Jean-Philippe Lang- * Copyright (C) 2010-2013 the ChiliProject Team- *- * This program is free software; you can redistribute it and/or- * modify it under the terms of the GNU General Public License- * as published by the Free Software Foundation; either version 2- * of the License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with this program; if not, write to the Free Software- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.- *- * See COPYRIGHT and LICENSE files for more details.- * ++- */--import { ModalDialogElement } from '@openproject/primer-view-components/app/components/primer/alpha/modal_dialog';-import { Controller } from '@hotwired/stimulus';--export default class extends Controller {- closeOnSuccess({ detail: { success } }:CustomEvent) {- if (success) {- const dialog = this.element.closest('modal-dialog') as ModalDialogElement;- dialog && dialog.close(true);- }- }-}diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.tsindex c74cf15cd4a..214cd914094 100644--- a/frontend/src/turbo/setup.ts+++ b/frontend/src/turbo/setup.ts@@ -1,4 +1,6 @@import * as Turbo from '@hotwired/turbo';+import { ModalDialogElement } from '@openproject/primer-view-components/app/components/primer/alpha/modal_dialog';+// Disable default turbo-drive for now as we don't need it for now AND it breaks angular routingTurbo.session.drive = false;// Start turbo@@ -10,3 +12,15 @@ document.addEventListener('turbo:frame-missing', (event:CustomEvent) => {event.preventDefault();visit(response.url);});++// Close the primer dialog when the form inside has been submitted with a success response+// It is necessary to close the primer dialog using the `close()` method, otherwise+// it will leave an overflow:hidden attribute on the body, which prevents scrolling on the page.+document.addEventListener('turbo:submit-end', (event:CustomEvent) => {+ const { detail: { success }, target } = event as { detail:{ success:boolean }, target:EventTarget };++ if (success && target instanceof HTMLFormElement) {+ const dialog = target.closest('modal-dialog') as ModalDialogElement;+ dialog && dialog.close(true);+ }+});diff --git a/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb b/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erbindex 5d40c1862f9..4931236d2be 100644--- a/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb+++ b/modules/meeting/app/components/meetings/sidebar/details_form_component.html.erb@@ -3,8 +3,7 @@primer_form_with(model: @meeting,method: :put,- url: update_details_meeting_path(@meeting),- data: helpers.close_dialog_on_success_data+ url: update_details_meeting_path(@meeting)) do |f|component_collection do |collection|collection.with_component(Primer::Alpha::Dialog::Body.new) dodiff --git a/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb b/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erbindex 87a86d16b15..dbd369a60c7 100644--- a/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb+++ b/modules/meeting/app/components/meetings/sidebar/participants_form_component.html.erb@@ -3,8 +3,7 @@primer_form_with(model: @meeting,method: :put,- url: update_participants_meeting_path(@meeting),- data: helpers.close_dialog_on_success_data+ url: update_participants_meeting_path(@meeting)) do |f|component_collection do |collection|collection.with_component(Primer::Alpha::Dialog::Body.new(style: "max-height: 460px;", my: 3)) dodiff --git a/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb b/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erbindex ed25d639578..30319961c8f 100644--- a/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb+++ b/modules/meeting/app/components/work_package_meetings_tab/add_work_package_to_meeting_form_component.html.erb@@ -4,8 +4,7 @@primer_form_with(model: @meeting_agenda_item,method: :post,- url: work_package_meeting_agenda_items_path(@work_package),- data: helpers.close_dialog_on_success_data+ url: work_package_meeting_agenda_items_path(@work_package)) do |f|component_collection do |collection|collection.with_component(Primer::Alpha::Dialog::Body.new(test_selector: 'op-add-work-package-to-meeting-dialog-body')) do