From 0a94fab9e3d4867e7b07a04bcf4c9607da49721d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 8 May 2024 17:05:26 +0100 Subject: [PATCH] Bug 36815: Expose to the UI This patch adds a modal to preview the sample notices in the UI and allow replacing the template content with that content of that modal. Signed-off-by: Emily Lamancusa --- .../prog/en/modules/tools/letter.tt | 50 +++++++++++++++++++ tools/letter.pl | 4 ++ 2 files changed, 54 insertions(+) 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 22379532e5..ead1d171b4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -132,6 +132,27 @@ + + + [% IF add_form or copy_form %]
@@ -673,6 +694,12 @@ Preview [% END %] + [% IF letter.sample %] +
  • + + +
  • + [% END %] [% END %] @@ -761,6 +788,29 @@ '}'; }); }); + + $(".notice-sample").on("click", function(e){ + e.preventDefault(); + var noticeid = $(this).data("noticeid"); + var replaceid = $(this).data("replace"); + var body = $("#notice" + noticeid ).val(); + $("#noticeSampleModal .template-body").text(body); + $("#noticeSampleModal").attr("data-replaceid", replaceid); + $("#noticeSampleModal").modal("show"); + }); + + $("#noticeSampleModal").on("hide.bs.modal", function(){ + $("#noticeSampleModalLabel").text(""); + $("#noticeSampleModal .template-body").text(""); + $("#noticeSampleModal").attr("data-replaceid", ''); + }); + + $("#noticeSampleModal").on("click", ".copy", function(){ + var content = $('#noticeSampleModal .template-body').text(); + var replaceid = $('#noticeSampleModal').data('replaceid'); + $('#'+replaceid).val(content); + $('#noticeSampleModal').modal('hide'); + }); }); [% Asset.js("js/letter.js") | $raw %] diff --git a/tools/letter.pl b/tools/letter.pl index 9e9b9e386f..dbe84aa26c 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -227,6 +227,10 @@ sub add_form { tt_error => $letter->{tt_error}, }; $letters{ $lang }{params} = $letter; + + my $object = Koha::Notice::Templates->find( { id => $letter->{id} } ); + $letters{ $lang }{templates}{$mtt}{sample} = $object->get_default; + $letters{ $lang }{templates}{$mtt}{id} = $letter->{id}; } } else { -- 2.34.1