https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38105
--- Comment #2 from Lisette Scheer <[email protected]> --- Created attachment 211798 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211798&action=edit Bug 38105: Notice template preview should render HTML including CSS styling The preview of notice templates showed the rendered notice as plain text, whether the template is HTML or not, and without any of the CSS applied to notices. It was not representative of what patrons get. The preview now shows the notice as it is shown to patrons: - HTML templates are rendered as HTML; plain text ones as text, tags included, as they are sent and printed (in a <pre>, as on printed slips), without the notice CSS - with the CSS of the transport type: AllNoticeCSS and AllNoticeStylesheet, plus EmailNoticeCSS/EmailNoticeStylesheet for email templates, PrintNoticeCSS/PrintNoticeStylesheet for print ones - for print templates, with the CSS of the notice itself (the "Local HTML notice styles" of bug 33478) The notice is wrapped with Koha::Notice::Message->html_content and shown in a sandboxed frame, as the notices of patrons are since bug 33260: nothing in the notice can run, the CSS of the notice and the CSS of the staff interface do not apply to each other, and the notice is a whole document, so the stylesheets of the *NoticeStylesheet preferences are loaded and CSS on body applies. This also fixes: - the "HTML message" checkbox was read with .val(), so templates were always previewed as HTML; it is now read with .is(':checked') - the preview was requested with a GET request containing the whole template, which long templates did not fit in: it is now a POST, and the preview says when it fails instead of loading forever Only the latest preview is shown: when a preview is requested while an earlier one is still loading, the earlier one is cancelled, so it cannot replace the newer one. Test plan: 1. Apply the patch and restart services 2. In Administration > System preferences, set AllNoticeCSS to: h1 { color: red; } body { background: lightyellow; } and AllNoticeStylesheet to: /intranet-tmpl/prog/css/print.css 3. Go to Tools > Notices and slips and edit the CHECKOUT notice 4. In "Data for preview", enter the barcode of an item and the borrowernumber of a patron, separated by | (e.g. 39999000001310|5) 5. In the Email template, tick "HTML message" and set the message body to: <h1>Hello</h1><p>Some <b>bold</b> text</p> 6. Click Preview: => The rendered message shows "Hello" as a red heading and "bold" in bold on a light yellow background: the template is rendered as HTML, with AllNoticeCSS, including its rule for body => With the browser's inspector, the preview frame has a <link> to print.css: AllNoticeStylesheet is loaded => The staff interface around the preview is not affected by the CSS 6b. Add <script>alert(1)</script> to the message body and preview again: => No alert is shown: nothing in the notice runs 7. Untick "HTML message" and preview again: => The rendered message shows the tags as text 8. Set PrintNoticeCSS to: p { color: blue; }, and in "Local HTML notice styles" set the style to: b { color: green; } 9. Put the same HTML body in the Print template, tick "HTML message" and preview it: => The paragraph is blue and "bold" is green 10. Preview the Email template again: => The paragraph and "bold" are not blue nor green: the print CSS only applies to print templates 11. Make a template longer than 10000 characters and preview it: => The preview works 12. Preview a template, close the preview at once and preview another template: => Only the second preview is shown (In the browser's developer tools, set the network to a slow speed, e.g. "Slow 3G" in the throttling menu of the Network tab, so that this lasts long enough to see; set it back to "No throttling" afterwards) Co-Authored-By: Claude Opus 5.5 <[email protected]> -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected] website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
