Skip to content

Commit 4d81469

Browse files
toanlamttai.letan
authored andcommitted
Questionnaire: Print attempt view - add a 'Print' button (#588)
Co-authored-by: tai.letan <[email protected]>
1 parent 666310d commit 4d81469

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

classes/output/renderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function render_completepage($page) {
5454
*/
5555
public function render_reportpage($page) {
5656
$data = $page->export_for_template($this);
57+
$printparam = optional_param('target', '', PARAM_TEXT);
58+
59+
$data->printparam = $printparam == 'print';
60+
5761
return $this->render_from_template('mod_questionnaire/reportpage', $data);
5862
}
5963

lang/en/questionnaire.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@
421421
$string['previous'] = 'Previous';
422422
$string['previouspage'] = 'Previous Page';
423423
$string['print'] = 'Print this Response';
424+
$string['printbutton'] = 'Print';
424425
$string['printblank'] = 'Print Blank';
425426
$string['printblanktooltip'] = 'Opens printer-friendly window with blank Questionnaire';
426427
$string['printstrictdateformatting'] = 'Enter the date';

module.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ M.mod_questionnaire.init_sendmessage = function(Y) {
268268
}, '#checkstarted');
269269

270270
};
271+
272+
M.mod_questionnaire.init_printing = function(Y) {
273+
var printbutton = Y.one('#print-button');
274+
if (printbutton) {
275+
printbutton.on('click', function(e) {
276+
e.preventDefault();
277+
window.print();
278+
});
279+
}
280+
};
271281
M.mod_questionnaire.init_slider = function() {
272282
const allRanges = document.querySelectorAll(".question-slider");
273283
allRanges.forEach(wrap => {

report.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
$PAGE->set_context($context);
127127
if ($outputtarget == 'print') {
128128
$PAGE->set_pagelayout('popup');
129+
$PAGE->requires->js_init_call('M.mod_questionnaire.init_printing');
129130
}
130131

131132
// Tab setup.

styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ td.selected {
191191
display: inline;
192192
}
193193

194+
@media print {
195+
#page-mod-questionnaire-report #print-button {
196+
display: none;
197+
}
198+
}
199+
194200
#page-mod-questionnaire-complete .notice .buttons input {
195201
margin-bottom: 10px;
196202
}

templates/reportpage.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
{{#feedbacknotes}}{{{.}}}{{/feedbacknotes}}
8383
{{#responses}}{{{.}}}{{/responses}}
8484
{{#bottomnavigationbar}}<div class="box respondentsnavbar">{{{.}}}</div>{{/bottomnavigationbar}}
85+
{{#printparam}}
86+
<button id="print-button" title="{{#str}}print, mod_questionnaire{{/str}}">
87+
{{#str}}printbutton, mod_questionnaire{{/str}}
88+
</button>
89+
{{/printparam}}
8590
</div>
8691
</div>
8792
{{#js}}
@@ -90,4 +95,4 @@
9095
TableSort.init();
9196
});
9297
});
93-
{{/js}}
98+
{{/js}}

0 commit comments

Comments
 (0)