From e441aba31549fe4a572cf548221e7a4c5ee74875 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 18 Apr 2023 04:52:46 +0000 Subject: [PATCH] Bug 33478: Save notice format settings Save format settings for an individual notice, or for all notices This patch implements a single style field for a slip to allow for advanced CSS customisation of printed notices. There are links to insert selectors as helpers. Styles can be applied for an individual notice, or all notices. To test: 1. Apply the patches, install database updates, update schema if needed, and restart services 2. Go to Tools -> Notices and slips 3. Edit any notice 4. Go to the Format tab 5. Confirm there is a textarea for CSS, and links to insert helpful selectors for IDs like #receipt and #slip 6. Add some CSS and confirm it saves. 7. Test that 'apply these settings to all notices' option works. Test the confirmation box appears when this is checked. 8. Add a new notice and confirm CSS settings save successfully 9. The subsequent patches have specific testing plans for each printable notice. For each, confirm that SlipCSS stylesheet changes are applied first. Specific notice styles should be applied last. 10. Test with a non-HTML notice as well, such as RECALL_REQUESTER_DET. Plain (non_HTML) notices have always come with
 tags around them so the text is formatted slightly differently but any CSS from SlipCSS or the notice Format should still hold.

Sponsored-by: Colorado Library Consortium
Signed-off-by: Lucas Gass 
Signed-off-by: Katrin Fischer 
---
 .../bug_33478-add_letter_columns.pl           | 18 +++++
 installer/data/mysql/kohastructure.sql        |  1 +
 .../prog/en/modules/circ/printslip.tt         |  1 +
 .../prog/en/modules/members/printfeercpt.tt   |  1 +
 .../prog/en/modules/members/printinvoice.tt   |  1 +
 .../prog/en/modules/members/printnotice.tt    |  1 +
 .../prog/en/modules/pos/printreceipt.tt       |  1 +
 .../prog/en/modules/tools/letter.tt           | 68 +++++++++++++++++++
 koha-tmpl/intranet-tmpl/prog/js/letter.js     | 20 +++++-
 tools/letter.pl                               | 16 ++++-
 10 files changed, 123 insertions(+), 5 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_33478-add_letter_columns.pl

diff --git a/installer/data/mysql/atomicupdate/bug_33478-add_letter_columns.pl b/installer/data/mysql/atomicupdate/bug_33478-add_letter_columns.pl
new file mode 100644
index 0000000000..91caa66079
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_33478-add_letter_columns.pl
@@ -0,0 +1,18 @@
+use Modern::Perl;
+
+return {
+    bug_number => "33478",
+    description => "Customise the format of notices when they are printed",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        if( !column_exists( 'letter', 'style' ) ) {
+          $dbh->do(q{
+              ALTER TABLE letter ADD COLUMN `style` mediumtext DEFAULT NULL AFTER `updated_on`
+          });
+
+          say $out "Added column 'letter.style'";
+        }
+    },
+};
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 5d71ee0ba9..7c805d536b 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -4284,6 +4284,7 @@ CREATE TABLE `letter` (
   `message_transport_type` varchar(20) NOT NULL DEFAULT 'email' COMMENT 'transport type for this notice',
   `lang` varchar(25) NOT NULL DEFAULT 'default' COMMENT 'lang of the notice',
   `updated_on` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'last modification',
+  `style` mediumtext DEFAULT NULL COMMENT 'custom styles for this notice',
   PRIMARY KEY (`id`),
   UNIQUE KEY `letter_uniq_1` (`module`,`code`,`branchcode`,`message_transport_type`,`lang`),
   KEY `message_transport_type_fk` (`message_transport_type`),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt
index f4d35cf1b1..85157a6d55 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt
@@ -29,6 +29,7 @@
 [% IF ( Koha.Preference('SlipCSS') ) %]
 
 [% END %]
+[% IF slip.style %][% END %]
 
 [% INCLUDE 'slip-print.inc' #printThenClose %]
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt
index 5693c3188c..a2ed265577 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt
@@ -15,6 +15,7 @@
 
 
 [% Asset.css("css/printreceiptinvoice.css") | $raw %]
+[% IF slip.style %][% END %]
 [% INCLUDE 'blocking_errors.inc' %]
 
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt
index 4fb3442ad8..8a1a3f9505 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt
@@ -15,6 +15,7 @@
 
 
 [% Asset.css("css/printreceiptinvoice.css") | $raw %]
+[% IF slip.style %][% END %]
 [% INCLUDE 'blocking_errors.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
index 85b1660e93..3566bc6d0c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt
@@ -18,6 +18,7 @@
 [% IF ( Koha.Preference('SlipCSS') ) %]
 
 [% END %]
+[% IF slip.style %][% END %]
 
 
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt
index 7374498b32..95e2d7d8f9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt
@@ -14,6 +14,7 @@
 
 
 [% Asset.css("css/printreceiptinvoice.css") | $raw %]
+[% IF slip.style %][% END %]
 [% INCLUDE 'blocking_errors.inc' %]
 
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt
index afe2778d85..107bc47220 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt
@@ -51,6 +51,12 @@
         .panel-group {
             margin-top: 3px;
         }
+        .css-helper::after {
+            content: " | ";
+        }
+        .css-helper:last-child::after {
+            content: none;
+        }
     
 [% END %]
 
@@ -657,6 +663,42 @@
                 [% END %]
             [% END # /collapse_item %]
         [% END # /FOR mtt %]
+
+        
+ +
+
+
+
These format settings apply when a notice is printed.
+
+
    +
  1. + + Headings + Tables + All text +
  2. +
  3. + + +
  4. +
  5. + + + Existing format settings will be overwritten. +
  6. +
+
+
+
+
+
[% END # /WRAPPER accordion %] [% END %] @@ -676,6 +718,32 @@ var new_lettercode = '[% new_lettercode | html %]'; var new_branchcode = '[% new_branchcode | html %]'; var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'notices', 'lettert', 'json' ) | $raw %]; + $(document).ready(function(){ + $("#headings").click(function(){ + $("#style").val(function(i, text) { + return text + 'pre, #slip, #slip h1, #slip h2, #slip h3, #slip h4, #slip h5, #slip h6,\n' + + '#receipt, #receipt h1, #receipt h2, #receipt h3, #receipt h4, #receipt h5, #receipt h6 {\n' + + '// insert CSS here\n' + + '}'; + }); + }); + $("#tables").click(function(){ + $("#style").val(function(i, text) { + return text + '\nbody, table, th, td, th:last-child, td:last-child {\n' + + '// insert CSS here\n' + + '}'; + }); + }); + $("#text").click(function(){ + $("#style").val(function(i, text) { + return text + 'pre, #slip, #slip h1, #slip h2, #slip h3, #slip h4, #slip h5, #slip h6,\n' + + '#receipt, #receipt h1, #receipt h2, #receipt h3, #receipt h4, #receipt h5, #receipt h6,\n' + + 'table, th, td, th:last-child, td:last-child {\n' + + '// insert CSS here\n' + + '}'; + }); + }); + }); [% Asset.js("js/letter.js") | $raw %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/letter.js b/koha-tmpl/intranet-tmpl/prog/js/letter.js index 8a1894a1f7..5ea32df655 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/letter.js +++ b/koha-tmpl/intranet-tmpl/prog/js/letter.js @@ -48,6 +48,14 @@ function confirmOverwrite( new_lettercode, new_branchcode ){ } } +function confirmFormatOverwrite( event ) { + if ( confirm(__("Existing format settings for all notices will be overwritten by these format settings.")) ) { + return true; + } else { + return false; + } +} + var Sticky; $(document).ready(function() { @@ -85,8 +93,16 @@ $(document).ready(function() { window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode; }); - $("#submit_form").on("click",function(){ - $("#add_notice").submit(); + $("#submit_form").on("click",function(e){ + if ( $("#format_all").is(":checked") ){ + if ( confirmFormatOverwrite(e) ) { + $("#add_notice").submit(); + } else { + e.preventDefault(); + } + } else { + $("#add_notice").submit(); + } }); $("#add_notice").validate({ diff --git a/tools/letter.pl b/tools/letter.pl index 7239961e81..430bc2e32e 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -49,7 +49,6 @@ use C4::Context; use C4::Output qw( output_html_with_http_headers ); use C4::Letters qw( GetMessageTransportTypes ); use C4::Log qw( logaction ); - use Koha::Notice::Templates; use Koha::Patron::Attribute::Types; @@ -228,6 +227,7 @@ sub add_form { content => $letter->{content} // '', tt_error => $letter->{tt_error}, }; + $letters{ $lang }{params} = $letter; } } else { @@ -307,12 +307,20 @@ sub add_validate { my $oldmodule = $input->param('oldmodule'); my $code = $input->param('code'); my $name = $input->param('name'); + my $style = $input->param('style'); + my $format_all = $input->param('format_all'); my @mtt = $input->multi_param('message_transport_type'); my @title = $input->multi_param('title'); my @content = $input->multi_param('content'); my @lang = $input->multi_param('lang'); for my $mtt ( @mtt ) { my $lang = shift @lang; + if ( $format_all ) { + my @letters = Koha::Notice::Templates->search({ lang => $lang })->as_list; + foreach my $letter ( @letters ) { + $letter->set({ style => $style })->store; + } + } my $is_html = $input->param("is_html_$mtt\_$lang"); my $title = shift @title; my $content = shift @content; @@ -345,7 +353,8 @@ sub add_validate { is_html => $is_html || 0, title => $title, content => $content, - lang => $lang + lang => $lang, + style => $style } )->store; @@ -360,7 +369,8 @@ sub add_validate { title => $title, content => $content, message_transport_type => $mtt, - lang => $lang + lang => $lang, + style => $style } )->store; logaction( 'NOTICES', 'CREATE', $letter->id, $letter->content, -- 2.39.5