weekly release 3.6dev
[moodle.git] / mod / assign / feedback / editpdf / yui / src / editor / js / editor.js
CommitLineData
5c386472
DW
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
ad3f8cd1
DP
15/* eslint-disable no-unused-vars */
16/* global SELECTOR, TOOLSELECTOR, AJAXBASE, COMMENTCOLOUR, ANNOTATIONCOLOUR, AJAXBASEPROGRESS, CLICKTIMEOUT */
5c386472
DW
17
18/**
19 * Provides an in browser PDF editor.
20 *
21 * @module moodle-assignfeedback_editpdf-editor
22 */
23
24/**
25 * EDITOR
26 * This is an in browser PDF editor.
27 *
1f777e5c
AN
28 * @namespace M.assignfeedback_editpdf
29 * @class editor
5c386472
DW
30 * @constructor
31 * @extends Y.Base
32 */
557f44d9 33var EDITOR = function() {
5c386472
DW
34 EDITOR.superclass.constructor.apply(this, arguments);
35};
36EDITOR.prototype = {
37
5c386472
DW
38 /**
39 * The dialogue used for all action menu displays.
1f777e5c 40 *
5c386472
DW
41 * @property type
42 * @type M.core.dialogue
43 * @protected
44 */
5bb4f444 45 dialogue: null,
5c386472 46
bb690849
DW
47 /**
48 * The panel used for all action menu displays.
49 *
50 * @property type
51 * @type Y.Node
52 * @protected
53 */
5bb4f444 54 panel: null,
bb690849 55
5c386472
DW
56 /**
57 * The number of pages in the pdf.
1f777e5c
AN
58 *
59 * @property pagecount
60 * @type Number
5c386472
DW
61 * @protected
62 */
5bb4f444 63 pagecount: 0,
5c386472
DW
64
65 /**
66 * The active page in the editor.
1f777e5c
AN
67 *
68 * @property currentpage
69 * @type Number
5c386472
DW
70 * @protected
71 */
5bb4f444 72 currentpage: 0,
5c386472
DW
73
74 /**
75 * A list of page objects. Each page has a list of comments and annotations.
1f777e5c
AN
76 *
77 * @property pages
5c386472
DW
78 * @type array
79 * @protected
80 */
5bb4f444 81 pages: [],
5c386472 82
f7a9f1dd
AN
83 /**
84 * The reported status of the document.
85 *
86 * @property documentstatus
87 * @type int
88 * @protected
89 */
90 documentstatus: 0,
91
5c386472
DW
92 /**
93 * The yui node for the loading icon.
1f777e5c
AN
94 *
95 * @property loadingicon
96 * @type Node
5c386472
DW
97 * @protected
98 */
5bb4f444 99 loadingicon: null,
5c386472
DW
100
101 /**
102 * Image object of the current page image.
1f777e5c
AN
103 *
104 * @property pageimage
5c386472
DW
105 * @type Image
106 * @protected
107 */
5bb4f444 108 pageimage: null,
5c386472
DW
109
110 /**
111 * YUI Graphic class for drawing shapes.
1f777e5c
AN
112 *
113 * @property graphic
114 * @type Graphic
5c386472
DW
115 * @protected
116 */
5bb4f444 117 graphic: null,
5c386472
DW
118
119 /**
120 * Info about the current edit operation.
1f777e5c 121 *
5c386472
DW
122 * @property currentedit
123 * @type M.assignfeedback_editpdf.edit
124 * @protected
125 */
5bb4f444 126 currentedit: new M.assignfeedback_editpdf.edit(),
5c386472
DW
127
128 /**
129 * Current drawable.
1f777e5c 130 *
5c386472 131 * @property currentdrawable
1f777e5c 132 * @type M.assignfeedback_editpdf.drawable|false
5c386472
DW
133 * @protected
134 */
5bb4f444 135 currentdrawable: false,
5c386472
DW
136
137 /**
138 * Current drawables.
1f777e5c 139 *
5c386472
DW
140 * @property drawables
141 * @type array(M.assignfeedback_editpdf.drawable)
142 * @protected
143 */
5bb4f444 144 drawables: [],
5c386472
DW
145
146 /**
147 * Current comment when the comment menu is open.
148 * @property currentcomment
149 * @type M.assignfeedback_editpdf.comment
150 * @protected
151 */
5bb4f444 152 currentcomment: null,
5c386472
DW
153
154 /**
155 * Current annotation when the select tool is used.
156 * @property currentannotation
157 * @type M.assignfeedback_editpdf.annotation
158 * @protected
159 */
5bb4f444 160 currentannotation: null,
5c386472 161
324debc3
JD
162 /**
163 * Track the previous annotation so we can remove selection highlights.
164 * @property lastannotation
165 * @type M.assignfeedback_editpdf.annotation
166 * @protected
167 */
168 lastannotation: null,
169
5c386472
DW
170 /**
171 * Last selected annotation tool
172 * @property lastannotationtool
173 * @type String
174 * @protected
175 */
7962b484 176 lastannotationtool: "pen",
5c386472
DW
177
178 /**
179 * The users comments quick list
180 * @property quicklist
181 * @type M.assignfeedback_editpdf.quickcommentlist
182 * @protected
183 */
5bb4f444 184 quicklist: null,
5c386472
DW
185
186 /**
187 * The search comments window.
188 * @property searchcommentswindow
189 * @type M.core.dialogue
190 * @protected
191 */
5bb4f444 192 searchcommentswindow: null,
5c386472
DW
193
194
195 /**
196 * The selected stamp picture.
197 * @property currentstamp
198 * @type String
199 * @protected
200 */
5bb4f444 201 currentstamp: null,
5c386472
DW
202
203 /**
204 * The stamps.
205 * @property stamps
206 * @type Array
207 * @protected
208 */
5bb4f444 209 stamps: [],
5c386472 210
60b87080
DS
211 /**
212 * Prevent new comments from appearing
213 * immediately after clicking off a current
214 * comment
215 * @property editingcomment
216 * @type Boolean
217 * @public
218 */
5bb4f444 219 editingcomment: false,
60b87080 220
23990a0a
TB
221 /**
222 * Should inactive comments be collapsed?
223 *
224 * @property collapsecomments
225 * @type Boolean
226 * @public
227 */
228 collapsecomments: true,
229
5c386472
DW
230 /**
231 * Called during the initialisation process of the object.
232 * @method initializer
233 */
5bb4f444 234 initializer: function() {
5c386472
DW
235 var link;
236
237 link = Y.one('#' + this.get('linkid'));
238
239 if (link) {
240 link.on('click', this.link_handler, this);
241 link.on('key', this.link_handler, 'down:13', this);
242
bb690849
DW
243 // We call the amd module to see if we can take control of the review panel.
244 require(['mod_assign/grading_review_panel'], function(ReviewPanelManager) {
245 var panelManager = new ReviewPanelManager();
246
247 var panel = panelManager.getReviewPanel('assignfeedback_editpdf');
248 if (panel) {
249 panel = Y.one(panel);
250 panel.empty();
251 link.ancestor('.fitem').hide();
252 this.open_in_panel(panel);
253 }
254 this.currentedit.start = false;
255 this.currentedit.end = false;
256 if (!this.get('readonly')) {
257 this.quicklist = new M.assignfeedback_editpdf.quickcommentlist(this);
258 }
259 }.bind(this));
260
5c386472
DW
261 }
262 },
263
264 /**
265 * Called to show/hide buttons and set the current colours/stamps.
266 * @method refresh_button_state
267 */
5bb4f444 268 refresh_button_state: function() {
166ac972 269 var button, currenttoolnode, imgurl, drawingregion, stampimgurl, drawingcanvas;
5c386472
DW
270
271 // Initalise the colour buttons.
da91de78 272 button = this.get_dialogue_element(SELECTOR.COMMENTCOLOURBUTTON);
5c386472
DW
273
274 imgurl = M.util.image_url('background_colour_' + this.currentedit.commentcolour, 'assignfeedback_editpdf');
275 button.one('img').setAttribute('src', imgurl);
276
277 if (this.currentedit.commentcolour === 'clear') {
278 button.one('img').setStyle('borderStyle', 'dashed');
279 } else {
280 button.one('img').setStyle('borderStyle', 'solid');
281 }
282
da91de78 283 button = this.get_dialogue_element(SELECTOR.ANNOTATIONCOLOURBUTTON);
5c386472
DW
284 imgurl = M.util.image_url('colour_' + this.currentedit.annotationcolour, 'assignfeedback_editpdf');
285 button.one('img').setAttribute('src', imgurl);
286
da91de78 287 currenttoolnode = this.get_dialogue_element(TOOLSELECTOR[this.currentedit.tool]);
5c386472
DW
288 currenttoolnode.addClass('assignfeedback_editpdf_selectedbutton');
289 currenttoolnode.setAttribute('aria-pressed', 'true');
ab4d78ea
DW
290 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
291 drawingregion.setAttribute('data-currenttool', this.currentedit.tool);
5c386472 292
da91de78 293 button = this.get_dialogue_element(SELECTOR.STAMPSBUTTON);
166ac972
TB
294 stampimgurl = this.get_stamp_image_url(this.currentedit.stamp);
295 button.one('img').setAttrs({'src': stampimgurl,
5c386472
DW
296 'height': '16',
297 'width': '16'});
166ac972
TB
298
299 drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS);
300 switch (this.currentedit.tool) {
301 case 'drag':
302 drawingcanvas.setStyle('cursor', 'move');
303 break;
304 case 'highlight':
305 drawingcanvas.setStyle('cursor', 'text');
306 break;
307 case 'select':
308 drawingcanvas.setStyle('cursor', 'default');
309 break;
310 case 'stamp':
311 drawingcanvas.setStyle('cursor', 'url(' + stampimgurl + '), crosshair');
312 break;
313 default:
314 drawingcanvas.setStyle('cursor', 'crosshair');
315 }
5c386472
DW
316 },
317
318 /**
319 * Called to get the bounds of the drawing region.
320 * @method get_canvas_bounds
321 */
5bb4f444 322 get_canvas_bounds: function() {
da91de78 323 var canvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS),
5c386472
DW
324 offsetcanvas = canvas.getXY(),
325 offsetleft = offsetcanvas[0],
326 offsettop = offsetcanvas[1],
327 width = parseInt(canvas.getStyle('width'), 10),
328 height = parseInt(canvas.getStyle('height'), 10);
329
330 return new M.assignfeedback_editpdf.rect(offsetleft, offsettop, width, height);
331 },
332
333 /**
334 * Called to translate from window coordinates to canvas coordinates.
335 * @method get_canvas_coordinates
336 * @param M.assignfeedback_editpdf.point point in window coordinats.
337 */
5bb4f444 338 get_canvas_coordinates: function(point) {
5c386472
DW
339 var bounds = this.get_canvas_bounds(),
340 newpoint = new M.assignfeedback_editpdf.point(point.x - bounds.x, point.y - bounds.y);
341
342 bounds.x = bounds.y = 0;
343
344 newpoint.clip(bounds);
345 return newpoint;
346 },
347
348 /**
349 * Called to translate from canvas coordinates to window coordinates.
350 * @method get_window_coordinates
351 * @param M.assignfeedback_editpdf.point point in window coordinats.
352 */
5bb4f444 353 get_window_coordinates: function(point) {
5c386472
DW
354 var bounds = this.get_canvas_bounds(),
355 newpoint = new M.assignfeedback_editpdf.point(point.x + bounds.x, point.y + bounds.y);
356
357 return newpoint;
358 },
359
bb690849
DW
360 /**
361 * Open the edit-pdf editor in the panel in the page instead of a popup.
362 * @method open_in_panel
363 */
5bb4f444 364 open_in_panel: function(panel) {
bb690849
DW
365 var drawingcanvas, drawingregion;
366
367 this.panel = panel;
368 panel.append(this.get('body'));
369 panel.addClass(CSS.DIALOGUE);
370
371 this.loadingicon = this.get_dialogue_element(SELECTOR.LOADINGICON);
372
373 drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS);
5bb4f444 374 this.graphic = new Y.Graphic({render: drawingcanvas});
bb690849
DW
375
376 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
377 drawingregion.on('scroll', this.move_canvas, this);
378
379 if (!this.get('readonly')) {
380 drawingcanvas.on('gesturemovestart', this.edit_start, null, this);
381 drawingcanvas.on('gesturemove', this.edit_move, null, this);
382 drawingcanvas.on('gesturemoveend', this.edit_end, null, this);
383
384 this.refresh_button_state();
385 }
386
f7a9f1dd 387 this.start_generation();
bb690849
DW
388 },
389
5c386472
DW
390 /**
391 * Called to open the pdf editing dialogue.
392 * @method link_handler
393 */
5bb4f444 394 link_handler: function(e) {
bc8b6dc6
DP
395 var drawingcanvas, drawingregion;
396 var resize = true;
5c386472
DW
397 e.preventDefault();
398
399 if (!this.dialogue) {
400 this.dialogue = new M.core.dialogue({
401 headerContent: this.get('header'),
402 bodyContent: this.get('body'),
403 footerContent: this.get('footer'),
aebc768f 404 modal: true,
5c386472 405 width: '840px',
6d87dceb
DW
406 visible: false,
407 draggable: true
5c386472
DW
408 });
409
5c386472
DW
410 // Add custom class for styling.
411 this.dialogue.get('boundingBox').addClass(CSS.DIALOGUE);
412
da91de78 413 this.loadingicon = this.get_dialogue_element(SELECTOR.LOADINGICON);
5c386472 414
da91de78 415 drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS);
5bb4f444 416 this.graphic = new Y.Graphic({render: drawingcanvas});
5c386472 417
da91de78 418 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
50c12f01
DS
419 drawingregion.on('scroll', this.move_canvas, this);
420
5c386472
DW
421 if (!this.get('readonly')) {
422 drawingcanvas.on('gesturemovestart', this.edit_start, null, this);
423 drawingcanvas.on('gesturemove', this.edit_move, null, this);
424 drawingcanvas.on('gesturemoveend', this.edit_end, null, this);
425
426 this.refresh_button_state();
427 }
d40ce26f 428
f7a9f1dd 429 this.start_generation();
50c12f01
DS
430 drawingcanvas.on('windowresize', this.resize, this);
431
432 resize = false;
5c386472 433 }
6d87dceb
DW
434 this.dialogue.centerDialogue();
435 this.dialogue.show();
50c12f01
DS
436
437 // Redraw when the dialogue is moved, to ensure the absolute elements are all positioned correctly.
438 this.dialogue.dd.on('drag:end', this.redraw, this);
439 if (resize) {
440 this.resize(); // When re-opening the dialog call redraw, to make sure the size + layout is correct.
441 }
5c386472
DW
442 },
443
444 /**
445 * Called to load the information and annotations for all pages.
f7a9f1dd
AN
446 *
447 * @method start_generation
5c386472 448 */
f7a9f1dd
AN
449 start_generation: function() {
450 this.poll_document_conversion_status();
451 },
5c386472 452
f7a9f1dd
AN
453 /**
454 * Poll the current document conversion status and start the next step
455 * in the process.
456 *
457 * @method poll_document_conversion_status
458 */
459 poll_document_conversion_status: function() {
460 if (this.get('destroyed')) {
461 return;
462 }
463
464 Y.io(AJAXBASE, {
5c386472
DW
465 method: 'get',
466 context: this,
467 sync: false,
5bb4f444
DP
468 data: {
469 sesskey: M.cfg.sesskey,
f7a9f1dd 470 action: 'pollconversions',
5bb4f444
DP
471 userid: this.get('userid'),
472 attemptnumber: this.get('attemptnumber'),
473 assignmentid: this.get('assignmentid'),
474 readonly: this.get('readonly') ? 1 : 0
5c386472
DW
475 },
476 on: {
477 success: function(tid, response) {
f7a9f1dd
AN
478 var data = this.handle_response_data(response),
479 poll = false;
480 if (data) {
481 this.documentstatus = data.status;
482 if (data.status === 0) {
483 // The combined document is still waiting for input to be ready.
484 poll = true;
485
486 } else if (data.status === 1) {
487 // The combine document is ready for conversion into a single PDF.
488 poll = true;
489
490 } else if (data.status === 2 || data.status === -1) {
491 // The combined PDF is ready.
492 // We now know the page count and can convert it to a set of images.
493 this.pagecount = data.pagecount;
494
495 if (data.pageready == data.pagecount) {
496 this.prepare_pages_for_display(data);
497 } else {
498 // Some pages are not ready yet.
499 // Note: We use a different polling process here which does not block.
500 this.update_page_load_progress();
501
502 // Fetch the images for the combined document.
503 this.start_document_to_image_conversion();
504 }
505 }
506
507 if (poll) {
508 // Check again in 1 second.
509 Y.later(1000, this, this.poll_document_conversion_status);
510 }
511 }
5c386472
DW
512 },
513 failure: function(tid, response) {
aa3e4bde 514 return new M.core.exception(response.responseText);
5c386472
DW
515 }
516 }
f7a9f1dd
AN
517 });
518 },
aa3e4bde 519
f7a9f1dd
AN
520 /**
521 * Spwan the PDF to Image conversion on the server.
522 *
523 * @method get_images_for_documents
524 */
525 start_document_to_image_conversion: function() {
526 if (this.get('destroyed')) {
527 return;
528 }
529 Y.io(AJAXBASE, {
530 method: 'get',
531 context: this,
532 sync: false,
533 data: {
534 sesskey: M.cfg.sesskey,
535 action: 'pollconversions',
536 userid: this.get('userid'),
537 attemptnumber: this.get('attemptnumber'),
538 assignmentid: this.get('assignmentid'),
539 readonly: this.get('readonly') ? 1 : 0
540 },
541 on: {
542 success: function(tid, response) {
543 var data = this.handle_response_data(response);
544 if (data) {
545 this.documentstatus = data.status;
546 if (data.status === 2) {
547 // The pages are ready. Add all of the annotations to them.
548 this.prepare_pages_for_display(data);
aa3e4bde 549 }
aa3e4bde 550 }
f7a9f1dd
AN
551 },
552 failure: function(tid, response) {
553 return new M.core.exception(response.responseText);
aa3e4bde 554 }
f7a9f1dd
AN
555 }
556 });
5c386472
DW
557 },
558
559 /**
560 * The info about all pages in the pdf has been returned.
f7a9f1dd 561 *
5c386472
DW
562 * @param string The ajax response as text.
563 * @protected
f7a9f1dd 564 * @method prepare_pages_for_display
5c386472 565 */
f7a9f1dd
AN
566 prepare_pages_for_display: function(data) {
567 var i, j, comment, error;
568 if (!data.pagecount) {
bb690849
DW
569 if (this.dialogue) {
570 this.dialogue.hide();
571 }
5c386472 572 // Display alert dialogue.
f7a9f1dd 573 error = new M.core.alert({message: M.util.get_string('cannotopenpdf', 'assignfeedback_editpdf')});
5c386472
DW
574 error.show();
575 return;
576 }
577
5c386472
DW
578 this.pages = data.pages;
579
580 for (i = 0; i < this.pages.length; i++) {
581 for (j = 0; j < this.pages[i].comments.length; j++) {
582 comment = this.pages[i].comments[j];
583 this.pages[i].comments[j] = new M.assignfeedback_editpdf.comment(this,
584 comment.gradeid,
585 comment.pageno,
586 comment.x,
587 comment.y,
588 comment.width,
589 comment.colour,
590 comment.rawtext);
591 }
592 for (j = 0; j < this.pages[i].annotations.length; j++) {
593 data = this.pages[i].annotations[j];
594 this.pages[i].annotations[j] = this.create_annotation(data.type, data);
595 }
596 }
597
598 // Update the ui.
8ae76e13
AN
599 if (this.quicklist) {
600 this.quicklist.load();
601 }
5c386472
DW
602 this.setup_navigation();
603 this.setup_toolbar();
604 this.change_page();
605 },
606
f7a9f1dd
AN
607 /**
608 * Fetch the page images.
609 *
610 * @method update_page_load_progress
611 */
612 update_page_load_progress: function() {
613 if (this.get('destroyed')) {
614 return;
615 }
616 var checkconversionstatus,
617 ajax_error_total = 0,
618 progressbar = this.get_dialogue_element(SELECTOR.PROGRESSBARCONTAINER + ' .bar');
619
620 if (!progressbar) {
621 return;
622 }
623
624 // If pages are not loaded, check PDF conversion status for the progress bar.
625 checkconversionstatus = {
626 method: 'get',
627 context: this,
628 sync: false,
629 data: {
630 sesskey: M.cfg.sesskey,
631 action: 'conversionstatus',
632 userid: this.get('userid'),
633 attemptnumber: this.get('attemptnumber'),
634 assignmentid: this.get('assignmentid')
635 },
636 on: {
637 success: function(tid, response) {
638 if (this.get('destroyed')) {
639 return;
640 }
641 ajax_error_total = 0;
642
643 var progress = 0;
644 var progressbar = this.get_dialogue_element(SELECTOR.PROGRESSBARCONTAINER + ' .bar');
645 if (progressbar) {
646 // Calculate progress.
647 progress = (response.response / this.pagecount) * 100;
648 progressbar.setStyle('width', progress + '%');
649 progressbar.ancestor(SELECTOR.PROGRESSBARCONTAINER).setAttribute('aria-valuenow', progress);
650
651 if (progress < 100) {
652 // Keep polling until all pages are generated.
653 M.util.js_pending('checkconversionstatus');
654 Y.later(1000, this, function() {
655 M.util.js_complete('checkconversionstatus');
656 Y.io(AJAXBASEPROGRESS, checkconversionstatus);
657 });
658 }
659 }
660 },
661 failure: function(tid, response) {
662 if (this.get('destroyed')) {
663 return;
664 }
665 ajax_error_total = ajax_error_total + 1;
666 // We only continue on error if the all pages were not generated,
667 // and if the ajax call did not produce 5 errors in the row.
668 if (this.pagecount === 0 && ajax_error_total < 5) {
669 M.util.js_pending('checkconversionstatus');
670 Y.later(1000, this, function() {
671 M.util.js_complete('checkconversionstatus');
672 Y.io(AJAXBASEPROGRESS, checkconversionstatus);
673 });
674 }
675 return new M.core.exception(response.responseText);
676 }
677 }
678 };
679 // We start the AJAX "generated page total number" call a second later to give a chance to
680 // the AJAX "combined pdf generation" call to clean the previous submission images.
681 M.util.js_pending('checkconversionstatus');
682 Y.later(1000, this, function() {
683 ajax_error_total = 0;
684 M.util.js_complete('checkconversionstatus');
685 Y.io(AJAXBASEPROGRESS, checkconversionstatus);
686 });
687 },
688
689 /**
690 * Handle response data.
691 *
692 * @method handle_response_data
693 * @param {object} response
694 * @return {object}
695 */
696 handle_response_data: function(response) {
697 if (this.get('destroyed')) {
698 return;
699 }
700 var data;
701 try {
702 data = Y.JSON.parse(response.responseText);
703 if (data.error) {
704 if (this.dialogue) {
705 this.dialogue.hide();
706 }
707
708 new M.core.alert({
709 message: M.util.get_string('cannotopenpdf', 'assignfeedback_editpdf'),
710 visible: true
711 });
712 } else {
713 return data;
714 }
715 } catch (e) {
716 if (this.dialogue) {
717 this.dialogue.hide();
718 }
719
720 new M.core.alert({
721 title: M.util.get_string('cannotopenpdf', 'assignfeedback_editpdf'),
722 visible: true
723 });
724 }
725
726 return;
727 },
728
5c386472
DW
729 /**
730 * Get the full pluginfile url for an image file - just given the filename.
731 *
732 * @public
733 * @method get_stamp_image_url
734 * @param string filename
735 */
5bb4f444 736 get_stamp_image_url: function(filename) {
5c386472
DW
737 var urls = this.get('stampfiles'),
738 fullurl = '';
739
740 Y.Array.each(urls, function(url) {
741 if (url.indexOf(filename) > 0) {
742 fullurl = url;
743 }
744 }, this);
745
746 return fullurl;
747 },
748
749 /**
750 * Attach listeners and enable the color picker buttons.
751 * @protected
752 * @method setup_toolbar
753 */
5bb4f444 754 setup_toolbar: function() {
5c386472
DW
755 var toolnode,
756 commentcolourbutton,
757 annotationcolourbutton,
758 searchcommentsbutton,
23990a0a 759 expcolcommentsbutton,
5c386472
DW
760 currentstampbutton,
761 stampfiles,
762 picker,
763 filename;
764
da91de78 765 searchcommentsbutton = this.get_dialogue_element(SELECTOR.SEARCHCOMMENTSBUTTON);
5c386472
DW
766 searchcommentsbutton.on('click', this.open_search_comments, this);
767 searchcommentsbutton.on('key', this.open_search_comments, 'down:13', this);
768
23990a0a
TB
769 expcolcommentsbutton = this.get_dialogue_element(SELECTOR.EXPCOLCOMMENTSBUTTON);
770 expcolcommentsbutton.on('click', this.expandCollapseComments, this);
771 expcolcommentsbutton.on('key', this.expandCollapseComments, 'down:13', this);
772
5c386472
DW
773 if (this.get('readonly')) {
774 return;
775 }
776 // Setup the tool buttons.
777 Y.each(TOOLSELECTOR, function(selector, tool) {
da91de78 778 toolnode = this.get_dialogue_element(selector);
5c386472
DW
779 toolnode.on('click', this.handle_tool_button, this, tool);
780 toolnode.on('key', this.handle_tool_button, 'down:13', this, tool);
781 toolnode.setAttribute('aria-pressed', 'false');
782 }, this);
783
784 // Set the default tool.
785
da91de78 786 commentcolourbutton = this.get_dialogue_element(SELECTOR.COMMENTCOLOURBUTTON);
5c386472
DW
787 picker = new M.assignfeedback_editpdf.colourpicker({
788 buttonNode: commentcolourbutton,
789 colours: COMMENTCOLOUR,
790 iconprefix: 'background_colour_',
5bb4f444 791 callback: function(e) {
5c386472
DW
792 var colour = e.target.getAttribute('data-colour');
793 if (!colour) {
794 colour = e.target.ancestor().getAttribute('data-colour');
795 }
796 this.currentedit.commentcolour = colour;
797 this.handle_tool_button(e, "comment");
798 },
799 context: this
800 });
801
da91de78 802 annotationcolourbutton = this.get_dialogue_element(SELECTOR.ANNOTATIONCOLOURBUTTON);
5c386472
DW
803 picker = new M.assignfeedback_editpdf.colourpicker({
804 buttonNode: annotationcolourbutton,
805 iconprefix: 'colour_',
806 colours: ANNOTATIONCOLOUR,
5bb4f444 807 callback: function(e) {
5c386472
DW
808 var colour = e.target.getAttribute('data-colour');
809 if (!colour) {
810 colour = e.target.ancestor().getAttribute('data-colour');
811 }
812 this.currentedit.annotationcolour = colour;
813 if (this.lastannotationtool) {
814 this.handle_tool_button(e, this.lastannotationtool);
815 } else {
816 this.handle_tool_button(e, "pen");
817 }
818 },
819 context: this
820 });
821
822 stampfiles = this.get('stampfiles');
823 if (stampfiles.length <= 0) {
da91de78 824 this.get_dialogue_element(TOOLSELECTOR.stamp).ancestor().hide();
5c386472
DW
825 } else {
826 filename = stampfiles[0].substr(stampfiles[0].lastIndexOf('/') + 1);
827 this.currentedit.stamp = filename;
da91de78 828 currentstampbutton = this.get_dialogue_element(SELECTOR.STAMPSBUTTON);
5c386472
DW
829
830 picker = new M.assignfeedback_editpdf.stamppicker({
831 buttonNode: currentstampbutton,
832 stamps: stampfiles,
833 callback: function(e) {
834 var stamp = e.target.getAttribute('data-stamp'),
835 filename;
836
837 if (!stamp) {
838 stamp = e.target.ancestor().getAttribute('data-stamp');
839 }
840 filename = stamp.substr(stamp.lastIndexOf('/'));
841 this.currentedit.stamp = filename;
673c4ffe 842 this.handle_tool_button(e, "stamp");
5c386472
DW
843 },
844 context: this
845 });
846 this.refresh_button_state();
847 }
848 },
849
850 /**
851 * Change the current tool.
852 * @protected
853 * @method handle_tool_button
854 */
5bb4f444 855 handle_tool_button: function(e, tool) {
5c386472
DW
856 var currenttoolnode;
857
858 e.preventDefault();
859
860 // Change style of the pressed button.
da91de78 861 currenttoolnode = this.get_dialogue_element(TOOLSELECTOR[this.currentedit.tool]);
5c386472
DW
862 currenttoolnode.removeClass('assignfeedback_editpdf_selectedbutton');
863 currenttoolnode.setAttribute('aria-pressed', 'false');
864 this.currentedit.tool = tool;
ab4d78ea 865
55907a73 866 if (tool !== "comment" && tool !== "select" && tool !== "drag" && tool !== "stamp") {
5c386472
DW
867 this.lastannotationtool = tool;
868 }
869 this.refresh_button_state();
870 },
871
872 /**
873 * JSON encode the current page data - stripping out drawable references which cannot be encoded.
874 * @protected
875 * @method stringify_current_page
876 * @return string
877 */
5bb4f444 878 stringify_current_page: function() {
5c386472
DW
879 var comments = [],
880 annotations = [],
881 page,
882 i = 0;
883
884 for (i = 0; i < this.pages[this.currentpage].comments.length; i++) {
885 comments[i] = this.pages[this.currentpage].comments[i].clean();
886 }
887 for (i = 0; i < this.pages[this.currentpage].annotations.length; i++) {
888 annotations[i] = this.pages[this.currentpage].annotations[i].clean();
889 }
890
5bb4f444 891 page = {comments: comments, annotations: annotations};
5c386472
DW
892
893 return Y.JSON.stringify(page);
894 },
895
896 /**
897 * Generate a drawable from the current in progress edit.
898 * @protected
899 * @method get_current_drawable
900 */
5bb4f444 901 get_current_drawable: function() {
5c386472
DW
902 var comment,
903 annotation,
904 drawable = false;
905
906 if (!this.currentedit.start || !this.currentedit.end) {
907 return false;
908 }
909
910 if (this.currentedit.tool === 'comment') {
911 comment = new M.assignfeedback_editpdf.comment(this);
912 drawable = comment.draw_current_edit(this.currentedit);
913 } else {
914 annotation = this.create_annotation(this.currentedit.tool, {});
915 if (annotation) {
916 drawable = annotation.draw_current_edit(this.currentedit);
917 }
918 }
919
920 return drawable;
921 },
922
da91de78
BL
923 /**
924 * Find an element within the dialogue.
925 * @protected
926 * @method get_dialogue_element
927 */
5bb4f444 928 get_dialogue_element: function(selector) {
bb690849
DW
929 if (this.panel) {
930 return this.panel.one(selector);
931 } else {
932 return this.dialogue.get('boundingBox').one(selector);
933 }
da91de78 934 },
5c386472
DW
935
936 /**
937 * Redraw the active edit.
938 * @protected
939 * @method redraw_active_edit
940 */
5bb4f444 941 redraw_current_edit: function() {
5c386472
DW
942 if (this.currentdrawable) {
943 this.currentdrawable.erase();
944 }
945 this.currentdrawable = this.get_current_drawable();
946 },
947
948 /**
949 * Event handler for mousedown or touchstart.
950 * @protected
951 * @param Event
952 * @method edit_start
953 */
5bb4f444 954 edit_start: function(e) {
da91de78 955 var canvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS),
5c386472
DW
956 offset = canvas.getXY(),
957 scrolltop = canvas.get('docScrollY'),
958 scrollleft = canvas.get('docScrollX'),
5bb4f444
DP
959 point = {x: e.clientX - offset[0] + scrollleft,
960 y: e.clientY - offset[1] + scrolltop},
324debc3 961 selected = false;
5c386472
DW
962
963 // Ignore right mouse click.
964 if (e.button === 3) {
965 return;
966 }
967
968 if (this.currentedit.starttime) {
969 return;
970 }
971
60b87080
DS
972 if (this.editingcomment) {
973 return;
974 }
975
5c386472
DW
976 this.currentedit.starttime = new Date().getTime();
977 this.currentedit.start = point;
5bb4f444 978 this.currentedit.end = {x: point.x, y: point.y};
5c386472
DW
979
980 if (this.currentedit.tool === 'select') {
557f44d9
AN
981 var x = this.currentedit.end.x,
982 y = this.currentedit.end.y,
983 annotations = this.pages[this.currentpage].annotations;
5c386472
DW
984 // Find the first annotation whose bounds encompass the click.
985 Y.each(annotations, function(annotation) {
986 if (((x - annotation.x) * (x - annotation.endx)) <= 0 &&
987 ((y - annotation.y) * (y - annotation.endy)) <= 0) {
988 selected = annotation;
989 }
990 });
991
992 if (selected) {
324debc3 993 this.lastannotation = this.currentannotation;
5c386472 994 this.currentannotation = selected;
324debc3 995 if (this.lastannotation && this.lastannotation !== selected) {
5c386472 996 // Redraw the last selected annotation to remove the highlight.
324debc3
JD
997 if (this.lastannotation.drawable) {
998 this.lastannotation.drawable.erase();
999 this.drawables.push(this.lastannotation.draw());
5c386472
DW
1000 }
1001 }
1002 // Redraw the newly selected annotation to show the highlight.
1003 if (this.currentannotation.drawable) {
1004 this.currentannotation.drawable.erase();
1005 }
1006 this.drawables.push(this.currentannotation.draw());
324debc3
JD
1007 } else {
1008 this.lastannotation = this.currentannotation;
1009 this.currentannotation = null;
1010
1011 // Redraw the last selected annotation to remove the highlight.
1012 if (this.lastannotation && this.lastannotation.drawable) {
1013 this.lastannotation.drawable.erase();
1014 this.drawables.push(this.lastannotation.draw());
1015 }
5c386472
DW
1016 }
1017 }
1018 if (this.currentannotation) {
1019 // Used to calculate drag offset.
5bb4f444
DP
1020 this.currentedit.annotationstart = {x: this.currentannotation.x,
1021 y: this.currentannotation.y};
5c386472
DW
1022 }
1023 },
1024
1025 /**
1026 * Event handler for mousemove.
1027 * @protected
1028 * @param Event
1029 * @method edit_move
1030 */
5bb4f444 1031 edit_move: function(e) {
ce091776 1032 e.preventDefault();
5c386472 1033 var bounds = this.get_canvas_bounds(),
da91de78 1034 canvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS),
55907a73 1035 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION),
5c386472
DW
1036 clientpoint = new M.assignfeedback_editpdf.point(e.clientX + canvas.get('docScrollX'),
1037 e.clientY + canvas.get('docScrollY')),
55907a73
DW
1038 point = this.get_canvas_coordinates(clientpoint),
1039 diffX,
1040 diffY;
5c386472
DW
1041
1042 // Ignore events out of the canvas area.
1043 if (point.x < 0 || point.x > bounds.width || point.y < 0 || point.y > bounds.height) {
1044 return;
1045 }
1046
1047 if (this.currentedit.tool === 'pen') {
1048 this.currentedit.path.push(point);
1049 }
1050
1051 if (this.currentedit.tool === 'select') {
1052 if (this.currentannotation && this.currentedit) {
5bb4f444 1053 this.currentannotation.move(this.currentedit.annotationstart.x + point.x - this.currentedit.start.x,
5c386472
DW
1054 this.currentedit.annotationstart.y + point.y - this.currentedit.start.y);
1055 }
55907a73
DW
1056 } else if (this.currentedit.tool === 'drag') {
1057 diffX = point.x - this.currentedit.start.x;
1058 diffY = point.y - this.currentedit.start.y;
1059
1060 drawingregion.getDOMNode().scrollLeft -= diffX;
1061 drawingregion.getDOMNode().scrollTop -= diffY;
1062
5c386472
DW
1063 } else {
1064 if (this.currentedit.start) {
1065 this.currentedit.end = point;
1066 this.redraw_current_edit();
1067 }
1068 }
1069 },
1070
1071 /**
1072 * Event handler for mouseup or touchend.
1073 * @protected
1074 * @param Event
1075 * @method edit_end
1076 */
5bb4f444 1077 edit_end: function() {
5c386472
DW
1078 var duration,
1079 comment,
1080 annotation;
1081
1082 duration = new Date().getTime() - this.currentedit.start;
1083
1084 if (duration < CLICKTIMEOUT || this.currentedit.start === false) {
1085 return;
1086 }
1087
1088 if (this.currentedit.tool === 'comment') {
1089 if (this.currentdrawable) {
1090 this.currentdrawable.erase();
1091 }
1092 this.currentdrawable = false;
1093 comment = new M.assignfeedback_editpdf.comment(this);
baf881b8
RT
1094 if (comment.init_from_edit(this.currentedit)) {
1095 this.pages[this.currentpage].comments.push(comment);
1096 this.drawables.push(comment.draw(true));
1097 this.editingcomment = true;
1098 }
5c386472
DW
1099 } else {
1100 annotation = this.create_annotation(this.currentedit.tool, {});
1101 if (annotation) {
1102 if (this.currentdrawable) {
1103 this.currentdrawable.erase();
1104 }
1105 this.currentdrawable = false;
baf881b8
RT
1106 if (annotation.init_from_edit(this.currentedit)) {
1107 this.pages[this.currentpage].annotations.push(annotation);
1108 this.drawables.push(annotation.draw());
1109 }
5c386472
DW
1110 }
1111 }
1112
5c386472
DW
1113 // Save the changes.
1114 this.save_current_page();
1115
1116 // Reset the current edit.
1117 this.currentedit.starttime = 0;
1118 this.currentedit.start = false;
1119 this.currentedit.end = false;
1120 this.currentedit.path = [];
1121 },
1122
452beca9
GF
1123 /**
1124 * Resize the dialogue window when the browser is resized.
1125 * @public
1126 * @method resize
1127 */
5bb4f444 1128 resize: function() {
50c12f01
DS
1129 var drawingregion, drawregionheight;
1130
bb690849
DW
1131 if (this.dialogue) {
1132 if (!this.dialogue.get('visible')) {
1133 return;
1134 }
1135 this.dialogue.centerDialogue();
50c12f01 1136 }
50c12f01
DS
1137
1138 // Make sure the dialogue box is not bigger than the max height of the viewport.
1139 drawregionheight = Y.one('body').get('winHeight') - 120; // Space for toolbar + titlebar.
1140 if (drawregionheight < 100) {
1141 drawregionheight = 100;
1142 }
da91de78 1143 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
bb690849 1144 if (this.dialogue) {
5bb4f444 1145 drawingregion.setStyle('maxHeight', drawregionheight + 'px');
bb690849 1146 }
50c12f01 1147 this.redraw();
452beca9
GF
1148 return true;
1149 },
1150
5c386472
DW
1151 /**
1152 * Factory method for creating annotations of the correct subclass.
1153 * @public
1154 * @method create_annotation
1155 */
5bb4f444 1156 create_annotation: function(type, data) {
5c386472
DW
1157 data.type = type;
1158 data.editor = this;
1159 if (type === "line") {
1160 return new M.assignfeedback_editpdf.annotationline(data);
1161 } else if (type === "rectangle") {
1162 return new M.assignfeedback_editpdf.annotationrectangle(data);
1163 } else if (type === "oval") {
1164 return new M.assignfeedback_editpdf.annotationoval(data);
1165 } else if (type === "pen") {
1166 return new M.assignfeedback_editpdf.annotationpen(data);
1167 } else if (type === "highlight") {
1168 return new M.assignfeedback_editpdf.annotationhighlight(data);
1169 } else if (type === "stamp") {
1170 return new M.assignfeedback_editpdf.annotationstamp(data);
1171 }
1172 return false;
1173 },
1174
1175 /**
1176 * Save all the annotations and comments for the current page.
1177 * @protected
1178 * @method save_current_page
1179 */
5bb4f444 1180 save_current_page: function() {
f7a9f1dd
AN
1181 if (this.get('destroyed')) {
1182 return;
1183 }
5c386472
DW
1184 var ajaxurl = AJAXBASE,
1185 config;
1186
1187 config = {
1188 method: 'post',
1189 context: this,
1190 sync: false,
5bb4f444
DP
1191 data: {
1192 'sesskey': M.cfg.sesskey,
1193 'action': 'savepage',
1194 'index': this.currentpage,
1195 'userid': this.get('userid'),
1196 'attemptnumber': this.get('attemptnumber'),
1197 'assignmentid': this.get('assignmentid'),
1198 'page': this.stringify_current_page()
5c386472
DW
1199 },
1200 on: {
1201 success: function(tid, response) {
1202 var jsondata;
1203 try {
1204 jsondata = Y.JSON.parse(response.responseText);
1205 if (jsondata.error) {
1206 return new M.core.ajaxException(jsondata);
1207 }
bb690849
DW
1208 Y.one(SELECTOR.UNSAVEDCHANGESINPUT).set('value', 'true');
1209 Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('opacity', 1);
1210 Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('display', 'inline-block');
1211 Y.one(SELECTOR.UNSAVEDCHANGESDIV).transition({
1212 duration: 1,
1213 delay: 2,
1214 opacity: 0
1215 }, function() {
1216 Y.one(SELECTOR.UNSAVEDCHANGESDIV).setStyle('display', 'none');
1217 });
5c386472
DW
1218 } catch (e) {
1219 return new M.core.exception(e);
1220 }
1221 },
1222 failure: function(tid, response) {
aa3e4bde 1223 return new M.core.exception(response.responseText);
5c386472
DW
1224 }
1225 }
1226 };
1227
1228 Y.io(ajaxurl, config);
5c386472
DW
1229 },
1230
1231 /**
1232 * Event handler to open the comment search interface.
1233 *
1234 * @param Event e
1235 * @protected
1236 * @method open_search_comments
1237 */
5bb4f444 1238 open_search_comments: function(e) {
5c386472
DW
1239 if (!this.searchcommentswindow) {
1240 this.searchcommentswindow = new M.assignfeedback_editpdf.commentsearch({
5bb4f444 1241 editor: this
5c386472
DW
1242 });
1243 }
1244
1245 this.searchcommentswindow.show();
1246 e.preventDefault();
1247 },
1248
23990a0a
TB
1249 /**
1250 * Toggle function to expand/collapse all comments on page.
1251 *
1252 * @protected
1253 * @method expandCollapseComments
1254 */
1255 expandCollapseComments: function() {
60e9f908
TB
1256 var comments = Y.all('.commentdrawable');
1257
23990a0a
TB
1258 if (this.collapsecomments) {
1259 this.collapsecomments = false;
60e9f908 1260 comments.removeClass('commentcollapsed');
23990a0a
TB
1261 } else {
1262 this.collapsecomments = true;
60e9f908 1263 comments.addClass('commentcollapsed');
23990a0a 1264 }
23990a0a
TB
1265 },
1266
5c386472
DW
1267 /**
1268 * Redraw all the comments and annotations.
1269 * @protected
1270 * @method redraw
1271 */
5bb4f444 1272 redraw: function() {
5c386472
DW
1273 var i,
1274 page;
1275
1276 page = this.pages[this.currentpage];
50c12f01
DS
1277 if (page === undefined) {
1278 return; // Can happen if a redraw is triggered by an event, before the page has been selected.
1279 }
5c386472
DW
1280 while (this.drawables.length > 0) {
1281 this.drawables.pop().erase();
1282 }
1283
1284 for (i = 0; i < page.annotations.length; i++) {
1285 this.drawables.push(page.annotations[i].draw());
1286 }
1287 for (i = 0; i < page.comments.length; i++) {
1288 this.drawables.push(page.comments[i].draw(false));
1289 }
1290 },
1291
1292 /**
1293 * Load the image for this pdf page and remove the loading icon (if there).
1294 * @protected
1295 * @method change_page
1296 */
5bb4f444 1297 change_page: function() {
da91de78 1298 var drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS),
5c386472
DW
1299 page,
1300 previousbutton,
1301 nextbutton;
1302
da91de78
BL
1303 previousbutton = this.get_dialogue_element(SELECTOR.PREVIOUSBUTTON);
1304 nextbutton = this.get_dialogue_element(SELECTOR.NEXTBUTTON);
5c386472
DW
1305
1306 if (this.currentpage > 0) {
1307 previousbutton.removeAttribute('disabled');
1308 } else {
1309 previousbutton.setAttribute('disabled', 'true');
1310 }
1311 if (this.currentpage < (this.pagecount - 1)) {
1312 nextbutton.removeAttribute('disabled');
1313 } else {
1314 nextbutton.setAttribute('disabled', 'true');
1315 }
1316
1317 page = this.pages[this.currentpage];
1318 this.loadingicon.hide();
1319 drawingcanvas.setStyle('backgroundImage', 'url("' + page.url + '")');
50c12f01
DS
1320 drawingcanvas.setStyle('width', page.width + 'px');
1321 drawingcanvas.setStyle('height', page.height + 'px');
5c386472 1322
ea6d8674 1323 // Update page select.
bb2281d5 1324 this.get_dialogue_element(SELECTOR.PAGESELECT).set('selectedIndex', this.currentpage);
ea6d8674 1325
50c12f01 1326 this.resize(); // Internally will call 'redraw', after checking the dialogue size.
5c386472
DW
1327 },
1328
1329 /**
1330 * Now we know how many pages there are,
1331 * we can enable the navigation controls.
1332 * @protected
1333 * @method setup_navigation
1334 */
5bb4f444 1335 setup_navigation: function() {
5c386472
DW
1336 var pageselect,
1337 i,
0d5a260e 1338 strinfo,
5c386472
DW
1339 option,
1340 previousbutton,
1341 nextbutton;
1342
da91de78 1343 pageselect = this.get_dialogue_element(SELECTOR.PAGESELECT);
5c386472 1344
557f44d9 1345 var options = pageselect.all('option');
5c386472
DW
1346 if (options.size() <= 1) {
1347 for (i = 0; i < this.pages.length; i++) {
1348 option = Y.Node.create('<option/>');
1349 option.setAttribute('value', i);
5bb4f444 1350 strinfo = {page: i + 1, total: this.pages.length};
0d5a260e 1351 option.setHTML(M.util.get_string('pagexofy', 'assignfeedback_editpdf', strinfo));
5c386472
DW
1352 pageselect.append(option);
1353 }
1354 }
1355 pageselect.removeAttribute('disabled');
1356 pageselect.on('change', function() {
1357 this.currentpage = pageselect.get('value');
1358 this.change_page();
1359 }, this);
1360
da91de78
BL
1361 previousbutton = this.get_dialogue_element(SELECTOR.PREVIOUSBUTTON);
1362 nextbutton = this.get_dialogue_element(SELECTOR.NEXTBUTTON);
5c386472
DW
1363
1364 previousbutton.on('click', this.previous_page, this);
1365 previousbutton.on('key', this.previous_page, 'down:13', this);
1366 nextbutton.on('click', this.next_page, this);
1367 nextbutton.on('key', this.next_page, 'down:13', this);
1368 },
1369
1370 /**
1371 * Navigate to the previous page.
1372 * @protected
1373 * @method previous_page
1374 */
5bb4f444 1375 previous_page: function(e) {
114913e3 1376 e.preventDefault();
05aa787b 1377 this.currentpage--;
5c386472
DW
1378 if (this.currentpage < 0) {
1379 this.currentpage = 0;
1380 }
1381 this.change_page();
1382 },
1383
1384 /**
1385 * Navigate to the next page.
1386 * @protected
1387 * @method next_page
1388 */
5bb4f444 1389 next_page: function(e) {
114913e3 1390 e.preventDefault();
05aa787b 1391 this.currentpage++;
5c386472
DW
1392 if (this.currentpage >= this.pages.length) {
1393 this.currentpage = this.pages.length - 1;
1394 }
1395 this.change_page();
50c12f01
DS
1396 },
1397
1398 /**
1399 * Update any absolutely positioned nodes, within each drawable, when the drawing canvas is scrolled
1400 * @protected
1401 * @method move_canvas
1402 */
1403 move_canvas: function() {
1404 var drawingregion, x, y, i;
5c386472 1405
da91de78 1406 drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
50c12f01
DS
1407 x = parseInt(drawingregion.get('scrollLeft'), 10);
1408 y = parseInt(drawingregion.get('scrollTop'), 10);
5c386472 1409
50c12f01
DS
1410 for (i = 0; i < this.drawables.length; i++) {
1411 this.drawables[i].scroll_update(x, y);
1412 }
1413 }
5c386472
DW
1414
1415};
1416
1417Y.extend(EDITOR, Y.Base, EDITOR.prototype, {
5bb4f444
DP
1418 NAME: 'moodle-assignfeedback_editpdf-editor',
1419 ATTRS: {
1420 userid: {
1421 validator: Y.Lang.isInteger,
1422 value: 0
5c386472 1423 },
5bb4f444
DP
1424 assignmentid: {
1425 validator: Y.Lang.isInteger,
1426 value: 0
5c386472 1427 },
5bb4f444
DP
1428 attemptnumber: {
1429 validator: Y.Lang.isInteger,
1430 value: 0
5c386472 1431 },
5bb4f444
DP
1432 header: {
1433 validator: Y.Lang.isString,
1434 value: ''
5c386472 1435 },
5bb4f444
DP
1436 body: {
1437 validator: Y.Lang.isString,
1438 value: ''
5c386472 1439 },
5bb4f444
DP
1440 footer: {
1441 validator: Y.Lang.isString,
1442 value: ''
5c386472 1443 },
5bb4f444
DP
1444 linkid: {
1445 validator: Y.Lang.isString,
1446 value: ''
5c386472 1447 },
5bb4f444
DP
1448 deletelinkid: {
1449 validator: Y.Lang.isString,
1450 value: ''
5c386472 1451 },
5bb4f444
DP
1452 readonly: {
1453 validator: Y.Lang.isBoolean,
1454 value: true
5c386472 1455 },
5bb4f444
DP
1456 stampfiles: {
1457 validator: Y.Lang.isArray,
1458 value: ''
5c386472
DW
1459 }
1460 }
1461});
1462
5c386472 1463M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
5c386472
DW
1464M.assignfeedback_editpdf.editor = M.assignfeedback_editpdf.editor || {};
1465
1466/**
1467 * Init function - will create a new instance every time.
1f777e5c 1468 * @method editor.init
5c386472
DW
1469 * @static
1470 * @param {Object} params
1471 */
1472M.assignfeedback_editpdf.editor.init = M.assignfeedback_editpdf.editor.init || function(params) {
f7a9f1dd
AN
1473 if (typeof M.assignfeedback_editpdf.instance !== 'undefined') {
1474 M.assignfeedback_editpdf.instance.destroy();
1475 }
1476
5bb4f444 1477 M.assignfeedback_editpdf.instance = new EDITOR(params);
bb690849 1478 return M.assignfeedback_editpdf.instance;
5c386472 1479};