Skip to content

Commit

Permalink
Questionnaire: Print attempt view - add a 'Print' button
Browse files Browse the repository at this point in the history
  • Loading branch information
toanlam committed Jun 5, 2024
1 parent b06947c commit da17b27
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion templates/reportpage.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@
{{#feedbacknotes}}{{{.}}}{{/feedbacknotes}}
{{#responses}}{{{.}}}{{/responses}}
{{#bottomnavigationbar}}<div class="box respondentsnavbar">{{{.}}}</div>{{/bottomnavigationbar}}
{{#printparam}}
<button id="print-button" title="{{#str}}print, mod_questionnaire{{/str}}">
{{#str}}printbutton, mod_questionnaire{{/str}}
</button>
{{/printparam}}
</div>
</div>
</div>

0 comments on commit da17b27

Please sign in to comment.