MDL-42023 assign: Edit PDF plugin - Jerome's contributions
[moodle.git] / mod / assign / feedback / editpdf / yui / src / editor / js / annotationline.js
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/>.
16 /**
17  * Class representing a line.
18  *
19  * @namespace M.assignfeedback_editpdf
20  * @class annotationline
21  * @extends annotation
22  * @module moodle-assignfeedback_editpdf-editor
23  */
24 ANNOTATIONLINE = function(config) {
25     ANNOTATIONLINE.superclass.constructor.apply(this, [config]);
26 };
28 ANNOTATIONLINE.NAME = "annotationline";
29 ANNOTATIONLINE.ATTRS = {};
31 Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
32     /**
33      * Draw a line annotation
34      * @protected
35      * @method draw
36      * @return M.assignfeedback_editpdf.drawable
37      */
38     draw : function() {
39         var drawable,
40             shape;
42         drawable = new M.assignfeedback_editpdf.drawable(this.editor);
44         shape = this.editor.graphic.addShape({
45         type: Y.Path,
46             fill: false,
47             stroke: {
48                 weight: STROKEWEIGHT,
49                 color: ANNOTATIONCOLOUR[this.colour]
50             }
51         });
53         shape.moveTo(this.x, this.y);
54         shape.lineTo(this.endx, this.endy);
55         shape.end();
56         drawable.shapes.push(shape);
57         this.drawable = drawable;
59         return ANNOTATIONLINE.superclass.draw.apply(this);
60     },
62     /**
63      * Draw the in progress edit.
64      *
65      * @public
66      * @method draw_current_edit
67      * @param M.assignfeedback_editpdf.edit edit
68      */
69     draw_current_edit : function(edit) {
70         var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
71             shape;
73         shape = this.editor.graphic.addShape({
74            type: Y.Path,
75             fill: false,
76             stroke: {
77                 weight: STROKEWEIGHT,
78                 color: ANNOTATIONCOLOUR[edit.annotationcolour]
79             }
80         });
82         shape.moveTo(edit.start.x, edit.start.y);
83         shape.lineTo(edit.end.x, edit.end.y);
84         shape.end();
86         drawable.shapes.push(shape);
88         return drawable;
89     },
91     /**
92      * Promote the current edit to a real annotation.
93      *
94      * @public
95      * @method init_from_edit
96      * @param M.assignfeedback_editpdf.edit edit
97      */
98     init_from_edit : function(edit) {
99         this.gradeid = this.editor.get('gradeid');
100         this.pageno = this.editor.currentpage;
101         this.x = edit.start.x;
102         this.y = edit.start.y;
103         this.endx = edit.end.x;
104         this.endy = edit.end.y;
105         this.colour = edit.annotationcolour;
106         this.path = '';
107     }
109 });
111 M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
112 M.assignfeedback_editpdf.annotationline = ANNOTATIONLINE;