From f85e09b3cc90c231bec2c34fd1813655d437de23 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 7 Oct 2024 12:13:31 +0100 Subject: [PATCH] Bug 35267: Migrate notice printing to members/print_notice This migrates the bulk notice printing from tools/print_notice.pl using circ/printslip.tt to members/print_notice.pl using members/print_notice.tt This clarified that we are working on pre-existing notices in the message queue and as such should be applying relevant print/email notice styling and not slip styling. --- Koha/Notice/Message.pm | 51 ++++++++++++- .../prog/en/modules/members/notices.tt | 4 +- .../prog/en/modules/members/print_notice.tt | 46 ++++++++++++ .../prog/en/modules/members/printnotice.tt | 34 --------- .../prog/en/modules/tools/notices.tt | 4 +- {tools => members}/print_notice.pl | 21 ++++-- members/printnotice.pl | 73 ------------------- 7 files changed, 113 insertions(+), 120 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt rename {tools => members}/print_notice.pl (76%) delete mode 100755 members/printnotice.pl diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index a0cd923c9b5..8614989a7bd 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -57,8 +57,8 @@ with HTML headers and CSS includes for HTML formatted notices. sub html_content { my ($self) = @_; - my $title = $self->subject; - my $content = $self->content; + my $title = $self->subject; + my $content = $self->content; my $stylesheets = $self->stylesheets; my $wrapped; @@ -120,6 +120,53 @@ sub stylesheets { return $all_stylesheets; } +=head3 scoped_style + + my $scoped_style = $message->scoped_style; + +Returns a string of all the scoped styles for the message + +=cut + +sub scoped_style { + my ($self) = @_; + my $type = $self->message_transport_type; + my $scoped_class = ".type_$type"; + my $css_content; + + if ( $self->message_transport_type eq 'email' ) { + $css_content = C4::Context->preference("EmailNoticeCSS"); + } elsif ( $self->message_transport_type eq 'print' ) { + $css_content = C4::Context->preference("PrintNoticeCSS"); + } + + # Modify the CSS content, handling @media, @supports, @document + $css_content =~ s! + (@(media|supports|-moz-document)[^\{]+\{) # Match the at-rule start + ( # Capture group for block content + (?: # Non-capturing group + [^{]+\{[^}]*\} # Match CSS rules within the at-rule block + )* + ) + \} + ! + my $header = $1; + my $inner_rules = $2; # Capture the rules within the at-rule block + + # Apply the scoped class to the inner rules + $inner_rules =~ s/([^{]+)\{/ $scoped_class $1\{/g; + + # Return the modified block + "$header$inner_rules" + + !egx; + + $css_content =~ s/([^{]+)\{/$scoped_class $1\{/g + unless $css_content =~ /\@(media|supports|-moz-document)/; + + return $css_content; +} + =head3 patron my $patron = $message->patron diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt index 35774a97dd7..2b1966d54e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt @@ -53,7 +53,7 @@ [% IF ( QUEUED_MESSAGES ) %]
Select all | Clear all -