2
// This file is part of Moodle - http://moodle.org/
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18
* This file contains the definition for the library class for edit PDF renderer.
20
* @package assignfeedback_editpdf
21
* @copyright 2012 Davo Smith
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
defined('MOODLE_INTERNAL') || die();
28
* A custom renderer class that extends the plugin_renderer_base and is used by the editpdf feedback plugin.
30
* @package assignfeedback_editpdf
31
* @copyright 2013 Davo Smith
32
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
class assignfeedback_editpdf_renderer extends plugin_renderer_base {
37
* Return the PDF button shortcut.
39
* @param string $name the name of a specific button.
40
* @return string the specific shortcut.
42
private function get_shortcut($name) {
44
$shortcuts = array('navigate-previous-button' => 'j',
45
'navigate-page-select' => 'k',
46
'navigate-next-button' => 'l',
47
'searchcomments' => 'h',
49
'commentcolour' => 'x',
56
'annotationcolour' => 'r',
58
'currentstamp' => 'm');
61
// Return the shortcut.
62
return $shortcuts[$name];
66
* Render a single colour button.
68
* @param string $icon - The key for the icon
69
* @param string $tool - The key for the lang string.
70
* @param string $accesskey Optional - The access key for the button.
71
* @param bool $disabled Optional - Is this button disabled.
74
private function render_toolbar_button($icon, $tool, $accesskey = null, $disabled=false) {
76
// Build button alt text.
77
$alttext = new stdClass();
78
$alttext->tool = $tool;
79
if (!empty($accesskey)) {
80
$alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
82
$alttext->shortcut = '';
84
$iconalt = get_string('toolbarbutton', 'assignfeedback_editpdf', $alttext);
86
$iconhtml = $this->pix_icon($icon, $iconalt, 'assignfeedback_editpdf');
87
$iconparams = array('data-tool'=>$tool, 'class'=>$tool . 'button');
89
$iconparams['disabled'] = 'true';
91
if (!empty($accesskey)) {
92
$iconparams['accesskey'] = $accesskey;
95
return html_writer::tag('button', $iconhtml, $iconparams);
99
* Render the editpdf widget in the grading form.
101
* @param assignfeedback_editpdf_widget $widget - Renderable widget containing assignment, user and attempt number.
104
public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widget $widget) {
109
$html .= html_writer::div(get_string('jsrequired', 'assignfeedback_editpdf'), 'hiddenifjs');
110
$linkid = html_writer::random_id();
111
if ($widget->readonly) {
112
$launcheditorlink = html_writer::tag('a',
113
get_string('viewfeedbackonline', 'assignfeedback_editpdf'),
114
array('id'=>$linkid, 'class'=>'btn', 'href'=>'#'));
116
$launcheditorlink = html_writer::tag('a',
117
get_string('launcheditor', 'assignfeedback_editpdf'),
118
array('id'=>$linkid, 'class'=>'btn', 'href'=>'#'));
120
$links = $launcheditorlink;
122
$links .= html_writer::tag('div',
123
get_string('unsavedchanges', 'assignfeedback_editpdf'),
124
array('class'=>'assignfeedback_editpdf_unsavedchanges warning'));
126
$html .= html_writer::div($links, 'visibleifjs');
127
$header = get_string('pluginname', 'assignfeedback_editpdf');
129
// Create the page navigation.
133
// Pick the correct arrow icons for right to left mode.
134
if (right_to_left()) {
135
$nav_prev = 'nav_next';
136
$nav_next = 'nav_prev';
138
$nav_prev = 'nav_prev';
139
$nav_next = 'nav_next';
142
$iconalt = get_string('navigateprevious', 'assignfeedback_editpdf');
143
$iconhtml = $this->pix_icon($nav_prev, $iconalt, 'assignfeedback_editpdf');
144
$navigation1 .= html_writer::tag('button', $iconhtml, array('disabled'=>'true',
145
'class'=>'navigate-previous-button', 'accesskey' => $this->get_shortcut('navigate-previous-button')));
146
$navigation1 .= html_writer::tag('select', null, array('disabled'=>'true',
147
'aria-label' => get_string('gotopage', 'assignfeedback_editpdf'), 'class'=>'navigate-page-select',
148
'accesskey' => $this->get_shortcut('navigate-page-select')));
149
$iconalt = get_string('navigatenext', 'assignfeedback_editpdf');
150
$iconhtml = $this->pix_icon($nav_next, $iconalt, 'assignfeedback_editpdf');
151
$navigation1 .= html_writer::tag('button', $iconhtml, array('disabled'=>'true',
152
'class'=>'navigate-next-button', 'accesskey' => $this->get_shortcut('navigate-next-button')));
154
$navigation1 = html_writer::div($navigation1, 'navigation', array('role'=>'navigation'));
156
$navigation2 .= $this->render_toolbar_button('comment_search', 'searchcomments', $this->get_shortcut('searchcomments'));
157
$navigation2 = html_writer::div($navigation2, 'navigation-search', array('role'=>'navigation'));
163
$clearfix = html_writer::div('', 'clearfix');
164
if (!$widget->readonly) {
167
$toolbar1 .= $this->render_toolbar_button('comment', 'comment', $this->get_shortcut('comment'));
168
$toolbar1 .= $this->render_toolbar_button('background_colour_clear', 'commentcolour', $this->get_shortcut('commentcolour'));
169
$toolbar1 = html_writer::div($toolbar1, 'toolbar', array('role'=>'toolbar'));
172
$toolbar2 .= $this->render_toolbar_button('select', 'select', $this->get_shortcut('select'));
173
$toolbar2 = html_writer::div($toolbar2, 'toolbar', array('role'=>'toolbar'));
176
$toolbar3 = $this->render_toolbar_button('pen', 'pen', $this->get_shortcut('pen'));
177
$toolbar3 .= $this->render_toolbar_button('line', 'line', $this->get_shortcut('line'));
178
$toolbar3 .= $this->render_toolbar_button('rectangle', 'rectangle', $this->get_shortcut('rectangle'));
179
$toolbar3 .= $this->render_toolbar_button('oval', 'oval', $this->get_shortcut('oval'));
180
$toolbar3 .= $this->render_toolbar_button('highlight', 'highlight', $this->get_shortcut('highlight'));
181
$toolbar3 .= $this->render_toolbar_button('background_colour_clear', 'annotationcolour', $this->get_shortcut('annotationcolour'));
182
$toolbar3 = html_writer::div($toolbar3, 'toolbar', array('role'=>'toolbar'));
185
$toolbar4 .= $this->render_toolbar_button('stamp', 'stamp', 'n');
186
$toolbar4 .= $this->render_toolbar_button('background_colour_clear', 'currentstamp', $this->get_shortcut('currentstamp'));
187
$toolbar4 = html_writer::div($toolbar4, 'toolbar', array('role'=>'toolbar'));
190
// Toobars written in reverse order because they are floated right.
191
$pageheader = html_writer::div($navigation1 .
201
// Loading progress bar.
202
$progressbar = html_writer::div('', 'bar', array('style' => 'width: 0%'));
203
$progressbar = html_writer::div($progressbar, 'progress progress-info progress-striped active',
204
array('title' => get_string('loadingeditor', 'assignfeedback_editpdf'),
205
'role'=> 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0,
206
'aria-valuemax' => 100));
207
$progressbarlabel = html_writer::div(get_string('generatingpdf', 'assignfeedback_editpdf'),
209
$loading = html_writer::div($progressbar . $progressbarlabel, 'loading');
211
$canvas = html_writer::div($loading, 'drawingcanvas');
212
$body .= html_writer::div($canvas, 'drawingregion');
218
$editorparams = array(array('header'=>$header,
222
'assignmentid'=>$widget->assignment,
223
'userid'=>$widget->userid,
224
'attemptnumber'=>$widget->attemptnumber,
225
'stampfiles'=>$widget->stampfiles,
226
'readonly'=>$widget->readonly,
227
'pagetotal'=>$widget->pagetotal));
229
$this->page->requires->yui_module('moodle-assignfeedback_editpdf-editor',
230
'M.assignfeedback_editpdf.editor.init',
233
$this->page->requires->strings_for_js(array(
248
'commentcontextmenu',
254
), 'assignfeedback_editpdf');