From 11eb7b4d2dec9ecdb4464c0e403c283dc9e3aac4 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 Print tab 5. Confirm format settings now show underneath the notice content box 6. Change some settings and confirm they save correctly 7. Test that 'apply these settings to all notices' option works 8. Add a new notice and confirm format settings save successfully 9. Search for a patron, go to More -> Set permissions 10. Ensure they have all Tools permissions EXCEPT for new format_notices user permission 11. Log into the staff interface as this patron 12. Go to Tools -> Notices and slips 13. Edit a notice 14. Go to the Print tab 15. Confirm the format settings DO NOT show underneath the notice content box Sponsored-by: Colorado Library Consortium --- .../prog/en/modules/tools/letter.tt | 90 +++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/js/letter.js | 18 +++- tools/letter.pl | 40 ++++++++- 3 files changed, 143 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 910deebfef5..c8d6fe4406c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -49,6 +49,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' %] @@ -648,6 +667,77 @@ [% END # /FOR mtt %] + +
+ +
+
+
+ [% 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 fd03c0dc431..70d5b4b41b3 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,14 @@ $(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(); + } + } }); $("#add_notice").validate({ diff --git a/tools/letter.pl b/tools/letter.pl index c00cc6de3dc..b23e3de2289 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 { @@ -310,12 +310,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; @@ -348,7 +370,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; @@ -363,7 +391,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