Koha/koha-tmpl/intranet-tmpl/prog/js/modal_printer.js
Martin Renvoize ef880e349f
Bug 31041: (follow-up) Clean up and generalise
This patch cleans out the print media css rules that were originally
added for modalprinting.  The window.open method is simpler to maintain
and will more reliably print modal content as expected.

We factor out the printer code into it's own JS asset that we can apply
to other printable modals and then use it in the two existing places
where such modals have been defined already (cashup summary and bundle
confirmation).

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-11-08 09:59:00 -03:00

63 lines
2 KiB
JavaScript

$(document).ready(function() {
function modalPrint() {
let title = $('.modal-dialog.focused .modal-title').html();
let contents = $('.modal-dialog.focused .modal-body').html();
let win = window.open('','');
win.document.write(`
<style>
table {
background-color: #FFFFFF;
border-bottom: 1px solid #CCCCCC;
border-collapse: collapse;
border-left: 1px solid #CCCCCC;
margin: 3px 0 5px 0;
padding: 0;
width: 99%;
}
td {
background-color: #FFF;
border-bottom: 1px solid #CCCCCC;
border-left: 0;
border-right: 1px solid #CCCCCC;
border-top: 0;
font-size: 12px;
padding: 5px 5px 5px 5px;
}
th {
background-color: #E9E9E9;
border-bottom: 1px solid #CCCCCC;
border-left: 0;
border-right: 1px solid #CCCCCC;
border-top: 0;
font-size: 14px;
font-weight: bold;
padding: 5px 5px 5px 5px;
text-align: left;
}
</style>
`)
win.document.write( title );
win.document.write( contents );
win.print();
win.close();
}
// Set focused on printable modals on open and autoprint if required
$('.modal.printable').on('shown.bs.modal', function() {
$('.modal-dialog', this).addClass('focused');
if ($(this).hasClass('autoprint')) {
modalPrint();
}
}).on('hidden.bs.modal', function() {
$('.modal-dialog', this).removeClass('focused');
});
// Trigger print on button click
$('.printModal').click(function() {
modalPrint();
});
});