Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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/>.
15
 
16
/**
17
 * Provides an in browser PDF editor.
18
 *
19
 * @module moodle-assignfeedback_editpdf-editor
20
 */
21
 
22
/**
23
 * Class representing a stamp.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @class annotationstamp
27
 * @extends M.assignfeedback_editpdf.annotation
28
 */
29
var ANNOTATIONSTAMP = function(config) {
30
    ANNOTATIONSTAMP.superclass.constructor.apply(this, [config]);
31
};
32
 
33
ANNOTATIONSTAMP.NAME = "annotationstamp";
34
ANNOTATIONSTAMP.ATTRS = {};
35
 
36
Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
37
    /**
38
     * Draw a stamp annotation
39
     * @protected
40
     * @method draw
41
     * @return M.assignfeedback_editpdf.drawable
42
     */
43
    draw: function() {
44
        var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
45
            drawingcanvas = this.editor.get_dialogue_element(SELECTOR.DRAWINGCANVAS),
46
            node,
47
            position;
48
 
49
        position = this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(this.x, this.y));
50
        node = Y.Node.create('<div/>');
51
        node.addClass('annotation');
52
        node.addClass('stamp');
53
        node.setStyles({
54
            'position': 'absolute',
55
            'display': 'inline-block',
56
            'backgroundImage': 'url(' + this.editor.get_stamp_image_url(this.path) + ')',
57
            'width': (this.endx - this.x),
58
            'height': (this.endy - this.y),
59
            'backgroundSize': '100% 100%'
60
        });
61
 
62
        drawingcanvas.append(node);
63
        node.setX(position.x);
64
        node.setY(position.y);
65
        drawable.store_position(node, position.x, position.y);
66
 
67
        // Bind events only when editing.
68
        if (!this.editor.get('readonly')) {
69
            // Pass through the event handlers on the div.
70
            node.on('gesturemovestart', this.editor.edit_start, null, this.editor);
71
            node.on('gesturemove', this.editor.edit_move, null, this.editor);
72
            node.on('gesturemoveend', this.editor.edit_end, null, this.editor);
73
        }
74
 
75
        drawable.nodes.push(node);
76
 
77
        this.drawable = drawable;
78
        return ANNOTATIONSTAMP.superclass.draw.apply(this);
79
    },
80
 
81
    /**
82
     * Draw the in progress edit.
83
     *
84
     * @public
85
     * @method draw_current_edit
86
     * @param M.assignfeedback_editpdf.edit edit
87
     */
88
    draw_current_edit: function(edit) {
89
        var bounds = new M.assignfeedback_editpdf.rect(),
90
            drawable = new M.assignfeedback_editpdf.drawable(this.editor),
91
            drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION),
92
            node,
93
            position;
94
 
95
        bounds.bound([edit.start, edit.end]);
96
        position = this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(bounds.x, bounds.y));
97
 
98
        node = Y.Node.create('<div/>');
99
        node.addClass('annotation');
100
        node.addClass('stamp');
101
        node.setStyles({
102
            'position': 'absolute',
103
            'display': 'inline-block',
104
            'backgroundImage': 'url(' + this.editor.get_stamp_image_url(edit.stamp) + ')',
105
            'width': bounds.width,
106
            'height': bounds.height,
107
            'backgroundSize': '100% 100%'
108
        });
109
 
110
        drawingregion.append(node);
111
        node.setX(position.x);
112
        node.setY(position.y);
113
        drawable.store_position(node, position.x, position.y);
114
 
115
        drawable.nodes.push(node);
116
 
117
        return drawable;
118
    },
119
 
120
    /**
121
     * Promote the current edit to a real annotation.
122
     *
123
     * @public
124
     * @method init_from_edit
125
     * @param M.assignfeedback_editpdf.edit edit
126
     * @return bool if width/height is more than min. required.
127
     */
128
    init_from_edit: function(edit) {
129
        var bounds = new M.assignfeedback_editpdf.rect();
130
        bounds.bound([edit.start, edit.end]);
131
 
132
        if (bounds.width < 40) {
133
            bounds.width = 40;
134
        }
135
        if (bounds.height < 40) {
136
            bounds.height = 40;
137
        }
138
        this.gradeid = this.editor.get('gradeid');
139
        this.pageno = this.editor.currentpage;
140
        this.x = bounds.x;
141
        this.y = bounds.y;
142
        this.endx = bounds.x + bounds.width;
143
        this.endy = bounds.y + bounds.height;
144
        this.colour = edit.annotationcolour;
145
        this.path = edit.stamp;
146
 
147
        // Min width and height is always more than 40px.
148
        return true;
149
    },
150
 
151
    /**
152
     * Move an annotation to a new location.
153
     * @public
154
     * @param int newx
155
     * @param int newy
156
     * @method move_annotation
157
     */
158
    move: function(newx, newy) {
159
        var diffx = newx - this.x,
160
            diffy = newy - this.y;
161
 
162
        this.x += diffx;
163
        this.y += diffy;
164
        this.endx += diffx;
165
        this.endy += diffy;
166
 
167
        if (this.drawable) {
168
            this.drawable.erase();
169
        }
170
        this.editor.drawables.push(this.draw());
171
    }
172
 
173
});
174
 
175
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
176
M.assignfeedback_editpdf.annotationstamp = ANNOTATIONSTAMP;