Bugzilla – Attachment 172491 Details for
Bug 35267
Clarify CSS options for Notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35267: Migrate notice printing to members/print_notice
Bug-35267-Migrate-notice-printing-to-membersprintn.patch (text/plain), 14.58 KB, created by
Martin Renvoize (ashimema)
on 2024-10-07 16:00:45 UTC
(
hide
)
Description:
Bug 35267: Migrate notice printing to members/print_notice
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-10-07 16:00:45 UTC
Size:
14.58 KB
patch
obsolete
>From 0d9626571b547e422cf3d409777469ca666ea760 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >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 ) %] > <div class="page-section"> > <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span> >- <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank"> >+ <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank"> > [% INCLUDE 'csrf-token.inc' %] > > <table id="noticestable"> >@@ -121,7 +121,7 @@ > [% END %] > [% END %] > </td> >- <td class="actions">[% IF QUEUED_MESSAGE.status != 'pending' %]<a target="_blank" class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/print_notice.pl?message_ids=[% QUEUED_MESSAGE.message_id | uri %]"><i class="fa fa-print"></i> Print</a>[% END %]</td> >+ <td class="actions">[% IF QUEUED_MESSAGE.status != 'pending' %]<a target="_blank" class="btn btn-default btn-xs" href="/cgi-bin/koha/members/print_notice.pl?message_ids=[% QUEUED_MESSAGE.message_id | uri %]"><i class="fa fa-print"></i> Print</a>[% END %]</td> > </tr> > [% END %] > </tbody> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt >new file mode 100644 >index 00000000000..439ceef4fd8 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt >@@ -0,0 +1,46 @@ >+[% USE raw %] >+[% USE Asset %] >+[% USE Koha %] >+[% PROCESS 'i18n.inc' %] >+[% SET footerjs = 1 %] >+[% INCLUDE 'doc-head-open.inc' %] >+ [% UNLESS notices && notices.size %] >+ [% SET notices = [{content => notice, is_html => is_html, style => style, id => id }] %] >+ [% END %] >+ <title>[% FILTER collapse %] >+ [% IF notices.size > 1 %] >+ [% t("Print notices") | html %] › >+ [% ELSE %] >+ [% t("Print notice") | html %] › >+ [% END %] >+ [% t("Patrons") | html %] › >+ [% t("Koha") | html %] >+ [% END %]</title> >+ [% INCLUDE 'doc-head-close.inc' %] >+ [% Asset.css("css/print.css") | $raw %] >+ [% IF ( Koha.Preference('AllNoticeCSS') ) %] >+ <style>[% Koha.Preference('AllNoticeCSS') | $raw %]</style> >+ [% END %] >+ [% FOR style IN styles %] >+ <style>[% style | $raw %]</style> >+ [% END %] >+ [% FOR notice IN notices %] >+ [% IF notice.style %]<style>[% notice.style.replace('([^\{\}]+?)\s*\{', '#notice_' _ notice.id _ ' $1 {') | $raw %]</style>[% END %] >+ [% END %] >+</head> >+<body id="members_printnotice" class="member"> >+[% FOR notice IN notices %] >+ <div id="notice_[% notice.id | html %]" class="type_[% notice.type | html %]"> >+ [% IF notice.is_html %] >+ [% IF ( notice.content ) %][% notice.content | $raw %][% ELSE %]No notice template found[% END %] >+ [% ELSE %] >+ <pre>[% IF ( notice.content ) %][% notice.content | html %][% ELSE %]No notice template found[% END %]</pre> >+ [% END %] >+ </div> >+ [% IF notices.size > 1 && !loop.last%]<div class="pagebreak"></div>[% END %] >+[% END %] >+[% MACRO jsinclude BLOCK %] >+ [% INCLUDE 'slip-print.inc' #printThenClose %] >+[% END %] >+ >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt >deleted file mode 100644 >index 0e105e0a336..00000000000 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt >+++ /dev/null >@@ -1,34 +0,0 @@ >-[% USE raw %] >-[% USE Asset %] >-[% USE Koha %] >-[% PROCESS 'i18n.inc' %] >-[% SET footerjs = 1 %] >-[% INCLUDE 'doc-head-open.inc' %] >-<title>[% FILTER collapse %] >- [% title | html %] › >- [% t("Patrons") | html %] › >- [% t("Koha") | html %] >-[% END %]</title> >-[% INCLUDE 'doc-head-close.inc' %] >- >-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> >-<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" /> >- >-[% Asset.css("css/print.css") | $raw %] >-[% IF style %]<style>[% style | $raw %]</style>[% END %] >-</head> >- >-<body id="members_printslip" class="member"> >- <div id="slip"> >- [% IF plain %] >- <pre>[% IF ( slip ) %][% slip | html %][% ELSE %]No slip template found[% END %]</pre> >- [% ELSE %] >- [% IF ( slip ) %][% slip | $raw %][% ELSE %]No slip template found[% END %] >- [% END %] >- </div> >- >-[% MACRO jsinclude BLOCK %] >- [% INCLUDE 'slip-print.inc' #printThenClose %] >-[% END %] >- >-[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >index ce45c8f4c89..4a100058d54 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >@@ -58,7 +58,7 @@ > > <div class="page-section"> > <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span> >- <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank"> >+ <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank"> > [% INCLUDE 'csrf-token.inc' %] > <table id="notices"> > <thead> >@@ -127,7 +127,7 @@ > [% END %] > [% END %] > </td> >- <td class="actions"><a target="_blank" class="btn btn-default btn-xs print" href="/cgi-bin/koha/tools/print_notice.pl?message_ids=[% notice.message_id | uri %]"><i class="fa fa-print"></i> Print</a></td> >+ <td class="actions"><a target="_blank" class="btn btn-default btn-xs print" href="/cgi-bin/koha/members/print_notice.pl?message_ids=[% notice.message_id | uri %]"><i class="fa fa-print"></i> Print</a></td> > </tr> > [% END %] > </tbody> >diff --git a/tools/print_notice.pl b/members/print_notice.pl >similarity index 76% >rename from tools/print_notice.pl >rename to members/print_notice.pl >index 90f4617cff8..3a2da2c7461 100755 >--- a/tools/print_notice.pl >+++ b/members/print_notice.pl >@@ -27,33 +27,40 @@ my $input = CGI->new; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => "circ/printslip.tt", >+ template_name => "members/print_notice.tt", > query => $input, > type => "intranet", > flagsrequired => { tools => 'view_generated_notices' }, > } > ); > >+my $types_seen = {}; >+my @scoped_styles; > my @message_ids = $input->multi_param('message_ids'); >-my @slips; >+my @notices; > foreach my $message_id (@message_ids) { > my $message = Koha::Notice::Messages->find($message_id); > my $template = $message->template; > >- push @slips, { >+ push @notices, { > content => $message->content, > is_html => $message->is_html, > style => $template ? $template->style : undef, > id => $message_id, >+ type => $message->message_transport_type, > }; > >+ unless ( $types_seen->{ $message->message_transport_type } ) { >+ push @scoped_styles, $message->scoped_style; >+ $types_seen->{ $message->message_transport_type } = 1; >+ } >+ > $message->update( { status => 'sent' } ); > } > $template->param( >- slips => \@slips, >- caller => 'notice_mgmt', >- stylesheet => C4::Context->preference("SlipCSS"), >- IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS'), >+ notices => \@notices, >+ stylesheet => C4::Context->preference("AllNoticeStylesheet"), >+ styles => \@scoped_styles > ); > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/members/printnotice.pl b/members/printnotice.pl >deleted file mode 100755 >index 32ec8170a0f..00000000000 >--- a/members/printnotice.pl >+++ /dev/null >@@ -1,73 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright PTFS Europe 2022 >-# >-# This file is part of Koha. >-# >-# Koha 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 3 of the License, or >-# (at your option) any later version. >-# >-# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use C4::Auth qw( get_template_and_user ); >-use C4::Output qw( output_and_exit_if_error output_html_with_http_headers ); >-use CGI qw ( -utf8 ); >-use C4::Letters; >-use Koha::Account::Lines; >- >-my $input = CGI->new; >- >-my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >- { >- template_name => "members/printnotice.tt", >- query => $input, >- type => "intranet", >- flagsrequired => { >- borrowers => 'edit_borrowers', >- } >- } >-); >- >-my $logged_in_user = Koha::Patrons->find($loggedinuser); >-my $borrowernumber = $input->param('borrowernumber'); >-my $patron = Koha::Patrons->find($borrowernumber); >-output_and_exit_if_error( >- $input, $cookie, >- $template, >- { >- module => 'members', >- logged_in_user => $logged_in_user, >- current_patron => $patron >- } >-); >- >-my $letter_code = $input->param('notice'); >-my $letter = C4::Letters::GetPreparedLetter( >- module => 'members', >- letter_code => $letter_code, >- branchcode => C4::Context::mybranch, >- message_transport_type => 'print', >- lang => $patron->lang, >- tables => { >- borrowers => $patron->borrowernumber >- } >-); >- >-$template->param( >- title => $letter->{title}, >- slip => $letter->{content}, >- plain => !$letter->{is_html}, >- style => $letter->{style}, >-); >- >-output_html_with_http_headers $input, $cookie, $template->output; >-- >2.46.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35267
:
172414
|
172415
|
172416
|
172417
|
172418
|
172457
|
172458
|
172459
|
172460
|
172461
|
172462
|
172463
|
172474
|
172475
|
172476
|
172477
|
172478
|
172479
|
172480
|
172485
|
172486
|
172487
|
172488
|
172489
|
172490
|
172491
|
175531
|
175532
|
175533
|
175534
|
175535
|
175536
|
175706
|
175707
|
175708
|
175709
|
175710
|
175711
|
175715
|
175716
|
175717
|
175718
|
175719
|
175721
|
175723
|
175724
|
175725
|
175726
|
175727
|
175728
|
175729