From b3613c1458c76c49c90e2b94b77d103164e008a8 Mon Sep 17 00:00:00 2001 From: hieuvu Date: Fri, 18 Dec 2020 14:31:55 +0700 Subject: [PATCH] add a 'Print' button for response view --- classes/output/renderer.php | 6 +++++- lang/en/questionnaire.php | 3 ++- module.js | 12 +++++++++++- report.php | 3 ++- styles.css | 7 ++++++- templates/reportpage.mustache | 7 ++++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 44e6cbca..4c796746 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -55,6 +55,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); } @@ -553,4 +557,4 @@ public function download_dataformat_selector($label, $base, $name = 'dataformat' return $this->render_from_template('mod_questionnaire/dataformat_selector', $data); } -} \ No newline at end of file +} diff --git a/lang/en/questionnaire.php b/lang/en/questionnaire.php index e4e86c17..ab3c3f87 100644 --- a/lang/en/questionnaire.php +++ b/lang/en/questionnaire.php @@ -401,6 +401,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'; @@ -653,4 +654,4 @@ $string['yesno_help'] = 'Simple Yes/No question.'; $string['yourresponse'] = 'Your response'; $string['yourresponses'] = 'Your responses'; -$string['crontask'] = 'Questionnaire cleanup job'; \ No newline at end of file +$string['crontask'] = 'Questionnaire cleanup job'; diff --git a/module.js b/module.js index 28d7b628..429e32cd 100644 --- a/module.js +++ b/module.js @@ -241,4 +241,14 @@ M.mod_questionnaire.init_sendmessage = function(Y) { }); }, '#checkstarted'); -}; \ No newline at end of file +}; + +M.mod_questionnaire.init_printing = function(Y) { + var printbutton = Y.one('#print-button'); + if (printbutton) { + printbutton.on('click', function(e) { + e.preventDefault(); + window.print(); + }); + } +}; diff --git a/report.php b/report.php index cb413ca0..ebdcac74 100755 --- a/report.php +++ b/report.php @@ -117,6 +117,7 @@ $PAGE->set_context($context); if ($outputtarget == 'print') { $PAGE->set_pagelayout('popup'); + $PAGE->requires->js_init_call('M.mod_questionnaire.init_printing'); } // Tab setup. @@ -847,4 +848,4 @@ function questionnaire_report_start_pdf() { $pdf->SetFillColor(238, 238, 238); $pdf->AddPage('L'); return $pdf; -} \ No newline at end of file +} diff --git a/styles.css b/styles.css index 1e4c730e..a5fabfeb 100644 --- a/styles.css +++ b/styles.css @@ -174,6 +174,11 @@ td.selected { #page-mod-questionnaire-complete .notice .buttons form { display: inline; } +@media print { + #page-mod-questionnaire-report #print-button { + display: none; + } +} .floatprinticon { margin-top: -30px; @@ -387,4 +392,4 @@ td.selected { .qn-indent { margin-left: 20px; -} \ No newline at end of file +} 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 +