diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 5bc029b3..8749cbe3 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -54,6 +54,10 @@ public function render_completepage($page) { */ public function render_reportpage($page) { $data = $page->export_for_template($this); + $printparam = optional_param('target', '', PARAM_TEXT); + + $data->printparam = $printparam == 'print'; + return $this->render_from_template('mod_questionnaire/reportpage', $data); } diff --git a/lang/en/questionnaire.php b/lang/en/questionnaire.php index f6e35b11..1fa8f1ad 100644 --- a/lang/en/questionnaire.php +++ b/lang/en/questionnaire.php @@ -419,6 +419,7 @@ $string['previous'] = 'Previous'; $string['previouspage'] = 'Previous Page'; $string['print'] = 'Print this Response'; +$string['printbutton'] = 'Print'; $string['printblank'] = 'Print Blank'; $string['printblanktooltip'] = 'Opens printer-friendly window with blank Questionnaire'; $string['printtooltip'] = 'Opens printer-friendly window with current Response'; diff --git a/module.js b/module.js index 1c8d0070..c4758336 100644 --- a/module.js +++ b/module.js @@ -266,6 +266,16 @@ M.mod_questionnaire.init_sendmessage = function(Y) { }, '#checkstarted'); }; + +M.mod_questionnaire.init_printing = function(Y) { + var printbutton = Y.one('#print-button'); + if (printbutton) { + printbutton.on('click', function(e) { + e.preventDefault(); + window.print(); + }); + } +}; M.mod_questionnaire.init_slider = function() { const allRanges = document.querySelectorAll(".question-slider"); allRanges.forEach(wrap => { diff --git a/report.php b/report.php index e66b3555..eff6cd01 100755 --- a/report.php +++ b/report.php @@ -125,6 +125,7 @@ $PAGE->set_context($context); if ($outputtarget == 'print') { $PAGE->set_pagelayout('popup'); + $PAGE->requires->js_init_call('M.mod_questionnaire.init_printing'); } // Tab setup. diff --git a/styles.css b/styles.css index 41dcd324..38ae144f 100644 --- a/styles.css +++ b/styles.css @@ -175,6 +175,12 @@ td.selected { display: inline; } +@media print { + #page-mod-questionnaire-report #print-button { + display: none; + } +} + #page-mod-questionnaire-complete .notice .buttons input { margin-bottom: 10px; } diff --git a/templates/reportpage.mustache b/templates/reportpage.mustache index e6c17b49..55e7533a 100644 --- a/templates/reportpage.mustache +++ b/templates/reportpage.mustache @@ -82,5 +82,10 @@ {{#feedbacknotes}}{{{.}}}{{/feedbacknotes}} {{#responses}}{{{.}}}{{/responses}} {{#bottomnavigationbar}}
{{/bottomnavigationbar}} + {{#printparam}} + + {{/printparam}} - \ No newline at end of file +