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
Add confirm dialog helper to render dialog from rails
Oliver Günthere6d34c0f1387
diff --git a/app/helpers/confirmation_dialog_helper.rb b/app/helpers/confirmation_dialog_helper.rbnew file mode 100644index 00000000000..9b2e7ce5ada--- /dev/null+++ b/app/helpers/confirmation_dialog_helper.rb@@ -0,0 +1,46 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++module ConfirmationDialogHelper+ ##+ # Show an angular modal confirmation dialog using the augmented+ # ConfirmationDialogService+ def augmented_confirmation_dialog(title:, text:, danger_zone: false, button_continue: nil, button_cancel: nil)+ {+ 'augmented-confirm-dialog': {+ text: {+ title:,+ text:,+ button_continue:,+ button_cancel:+ }.compact,+ dangerHighlighting: danger_zone+ }.to_json+ }+ end+enddiff --git a/app/views/admin/settings/working_days_settings/show.html.erb b/app/views/admin/settings/working_days_settings/show.html.erbindex 49d3a621330..0ff07f02982 100644--- a/app/views/admin/settings/working_days_settings/show.html.erb+++ b/app/views/admin/settings/working_days_settings/show.html.erb@@ -39,7 +39,16 @@ See COPYRIGHT and LICENSE files for more details.</div></div>-<%= styled_form_tag(admin_settings_working_days_path, method: :patch) do %>+<%= styled_form_tag(+ admin_settings_working_days_path,+ method: :patch,+ data: augmented_confirmation_dialog(+ title: t('working_days.change_button'),+ button_continue: t('working_days.change_button'),+ text: "#{t('working_days.warning')}\n#{t(:text_are_you_sure_continue)}",+ danger_zone: true+ )+ ) do %><section class="form--section"><p><%= t("working_days.info").html_safe %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 7b0234ff8dc..1d94b1d3c3e 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2693,6 +2693,7 @@ en:text_access_token_hint: "Access tokens allow you to grant external applications access to resources in OpenProject."text_analyze: "Further analyze: %{subject}"text_are_you_sure: "Are you sure?"+ text_are_you_sure_continue: "Are you sure you want to continue?"text_are_you_sure_with_children: "Delete work package and all child work packages?"text_assign_to_project: "Assign to the project"text_form_configuration: >@@ -3106,6 +3107,7 @@ en:info: ><b>Define days considered part of the work week</b><br/>Days that are not selected are skipped when scheduling work packages (and not included in the day count). These can be overriden at a work-package level.+ change_button: "Change working days"warning: >Changing which days of the week are considered working days can affect the start and finish days of all work packages in all projects in this instance.nothing_to_preview: "Nothing to preview"diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.htmlindex 725b55e0cca..6ea83516b1c 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html@@ -1,11 +1,14 @@<div- class="spot-modal loading-indicator--location"+ class="spot-modal op-confirm-dialog loading-indicator--location"data-indicator-name="modal"><div class="spot-modal--header">{{text.title}}</div>+ <div class="spot-divider"></div><div class="spot-modal--body">- <span [textContent]="text.text"></span>+ <span class="op-confirm-dialog--text"+ [textContent]="text.text"+ ></span><span *ngFor="let data of passedData"><br/><strong>{{data}}</strong>diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sass b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sassnew file mode 100644index 00000000000..4ebc798b1c8--- /dev/null+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sass@@ -0,0 +1,3 @@+.op-confirm-dialog+ &--text+ white-space: pre-wrapdiff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.tsindex e0caf6ce832..9ca1c96a428 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts@@ -59,6 +59,7 @@ export interface ConfirmDialogOptions {@Component({templateUrl: './confirm-dialog.modal.html',+ styleUrls: ['./confirm-dialog.modal.sass'],changeDetection: ChangeDetectionStrategy.OnPush,})export class ConfirmDialogModalComponent extends OpModalComponent {diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.tsindex 70d44e72510..df7e9764c5b 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts@@ -31,12 +31,29 @@ import {ConfirmDialogOptions,} from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.modal';import { OpModalService } from 'core-app/shared/components/modal/modal.service';-import { Injectable, Injector } from '@angular/core';+import {+ Injectable,+ Injector,+} from '@angular/core';@Injectable()export class ConfirmDialogService {- constructor(readonly opModalService:OpModalService,- readonly injector:Injector) {+ constructor(+ readonly opModalService:OpModalService,+ readonly injector:Injector,+ ) {+ document.addEventListener('submit', (evt:Event) => {+ const target = evt.target as HTMLFormElement;+ const options = target.dataset.augmentedConfirmDialog;+ if (options) {+ this.augmentFormSubmit(target, JSON.parse(options));++ evt.preventDefault();+ return false;+ }++ return true;+ });}/**@@ -54,4 +71,21 @@ export class ConfirmDialogService {});});}++ /**+ * Augment a Rails form submit with a confirmation dialog+ *+ * @param target+ * @param options+ * @private+ */+ private augmentFormSubmit(target:HTMLFormElement, options:ConfirmDialogOptions) {+ void this+ .confirm(options)+ .then(() => {+ target.removeAttribute('data-augmented-confirm-dialog');+ target.submit();+ })+ .catch(() => undefined /* Dialog cancelled, nothing to do */);+ }}