From 45cdfc912120363749aa5159e0d9ae98795210ef Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 18 Apr 2023 04:58:29 +0000 Subject: [PATCH] Bug 33478: Save notice format settings Save format settings for an individual notice, or for 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 format settings are available to edit 6. Change some settings and confirm they save correctly 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 format settings save successfully Sponsored-by: Colorado Library Consortium Signed-off-by: Sam Lau --- .../prog/en/modules/tools/letter.tt | 91 +++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/js/letter.js | 20 +++- tools/letter.pl | 40 +++++++- 3 files changed, 146 insertions(+), 5 deletions(-) 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 c3d24871783..df61bd0ccf7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -55,6 +55,25 @@ [% END %] +[% text_justification_types = [ 'L','C','R' ] %] +[% BLOCK translate_justification_types %] + [% SWITCH type %] + [% CASE 'L' %]Left + [% CASE 'C' %]Center + [% CASE 'R' %]Right + [% END %] +[% END %] + +[% units = [ 'POINT','INCH','MM','CM' ] %] +[% BLOCK translate_unit_types %] + [% SWITCH type %] + [% CASE 'POINT' %]PostScript points + [% CASE 'INCH' %]US Inches + [% CASE 'MM' %]SI Millimeters + [% CASE 'CM' %]SI Centimeters + [% END %] +[% END %] + [% WRAPPER 'header.inc' %] [% INCLUDE 'letters-search.inc' %] @@ -657,6 +676,78 @@ [% END # /FOR mtt %] + +
+ +
+
+
+
These format settings apply when a notice is printed.
+ [% SET param = letters.$lang.params %] +
+
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + + Existing format settings will be overwritten. +
  6. +
+
+
+
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + +
  8. +
+
+
+
+
+
+ [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/letter.js b/koha-tmpl/intranet-tmpl/prog/js/letter.js index 8a1894a1f79..5ea32df655e 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 0e3ece1363c..98acb0ccdba 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,34 @@ sub add_validate { my $oldmodule = $input->param('oldmodule'); my $code = $input->param('code'); my $name = $input->param('name'); + my $text_justify = $input->param('text_justify'); + my $font_size = $input->param('font_size'); + my $units = $input->param('units'); + my $notice_width = $input->param('notice_width'); + my $top_margin = $input->param('top_margin'); + my $left_margin = $input->param('left_margin'); + 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( + { + text_justify => $text_justify, + font_size => $font_size, + units => $units, + notice_width => $notice_width, + top_margin => $top_margin, + left_margin => $left_margin, + } + )->store; + } + } my $is_html = $input->param("is_html_$mtt\_$lang"); my $title = shift @title; my $content = shift @content; @@ -345,7 +367,13 @@ sub add_validate { is_html => $is_html || 0, title => $title, content => $content, - lang => $lang + lang => $lang, + text_justify => $text_justify, + font_size => $font_size, + units => $units, + notice_width => $notice_width, + top_margin => $top_margin, + left_margin => $left_margin, } )->store; @@ -360,7 +388,13 @@ sub add_validate { title => $title, content => $content, message_transport_type => $mtt, - lang => $lang + lang => $lang, + text_justify => $text_justify, + font_size => $font_size, + units => $units, + notice_width => $notice_width, + top_margin => $top_margin, + left_margin => $left_margin, } )->store; logaction( 'NOTICES', 'CREATE', $letter->id, $letter->content, -- 2.30.2