Skip to content

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

Replace print_handler with print controller

Oliver Güntherea34f1a1aa6f
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index b53c1e8d27b..45048056657 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -39,10 +39,6 @@ See COPYRIGHT and LICENSE files for more details.
<% @formatted_text = format_text @page, :text, attachments: @page.attachments %>
<% description strip_tags(@formatted_text) %>
-<% content_for :header_tags do %>
- <meta name="required_script" content="print_handler" />
-<% end %>
-
<%= toolbar title: title, html: {class: '-with-dropdown'} do %>
<% if @editable %>
<% if @page && User.current.allowed_to?(:edit_wiki_pages, @project) %>
@@ -100,7 +96,15 @@ See COPYRIGHT and LICENSE files for more details.
<%= li_unless_nil(link_to_if_authorized(t(:label_history), {action: 'history', id: @page}, class: 'icon-context icon-activity-history')) %>
<%= li_unless_nil(link_to_if_authorized(t(:button_manage_menu_entry), {controller: '/wiki_menu_items', action: 'edit', project_id: @project.identifier, id: @page}, class: 'icon-context icon-settings')) %>
<li>
- <%= link_to t(:button_print), '', title: t('wiki.print_hint'), class: 'icon-context icon-print op-wiki-context-print' %>
+ <%= link_to t(:button_print),
+ '',
+ title: t('wiki.print_hint'),
+ class: 'icon-context icon-print',
+ data: {
+ controller: 'print',
+ action: 'print#triggerPrint'
+ }
+ %>
</li>
<% if User.current.allowed_to?(:export_wiki_pages, @project) %>
<section data-augmented-model-wrapper
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/print_handler.js b/frontend/src/app/core/augmenting/dynamic-scripts/print_handler.js
deleted file mode 100644
index 8f06cee0df0..00000000000
--- a/frontend/src/app/core/augmenting/dynamic-scripts/print_handler.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// we cannot just use print as the handler
-function print_wiki_handler() {
- print();
-}
-
-jQuery(document.body).on('click', '.op-wiki-context-print', print_wiki_handler);
-
diff --git a/frontend/src/stimulus/controllers/print.controller.ts b/frontend/src/stimulus/controllers/print.controller.ts
new file mode 100644
index 00000000000..1e8fb322b9e
--- /dev/null
+++ b/frontend/src/stimulus/controllers/print.controller.ts
@@ -0,0 +1,8 @@
+import { ApplicationController } from 'stimulus-use';
+
+export default class PrintController extends ApplicationController {
+ triggerPrint(evt:MouseEvent) {
+ evt.preventDefault();
+ window.print();
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 7e9f45c2813..16c33919354 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -2,6 +2,7 @@ import { Application } from '@hotwired/stimulus';
import { environment } from '../environments/environment';
import { OpApplicationController } from './controllers/op-application.controller';
import OpDisableWhenCheckedController from './controllers/disable-when-checked.controller';
+import PrintController from './controllers/print.controller';
declare global {
interface Window {
@@ -19,3 +20,4 @@ instance.handleError = (error, message, detail) => {
instance.register('application', OpApplicationController);
instance.register('disable-when-checked', OpDisableWhenCheckedController);
+instance.register('print', PrintController);