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 users list of quick comments.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @class quickcommentlist
27
 */
28
var QUICKCOMMENTLIST = function(editor) {
29
 
30
    /**
31
     * Reference to M.assignfeedback_editpdf.editor.
32
     * @property editor
33
     * @type M.assignfeedback_editpdf.editor
34
     * @public
35
     */
36
    this.editor = editor;
37
 
38
    /**
39
     * Array of Comments
40
     * @property shapes
41
     * @type M.assignfeedback_editpdf.quickcomment[]
42
     * @public
43
     */
44
    this.comments = [];
45
 
46
    /**
47
     * Add a comment to the users quicklist.
48
     *
49
     * @protected
50
     * @method add
51
     */
52
    this.add = function(comment) {
53
        var ajaxurl = AJAXBASE,
54
            config;
55
 
56
        // Do not save empty comments.
57
        if (comment.rawtext === '') {
58
            return;
59
        }
60
 
61
        config = {
62
            method: 'post',
63
            context: this,
64
            sync: false,
65
            data: {
66
                'sesskey': M.cfg.sesskey,
67
                'action': 'addtoquicklist',
68
                'userid': this.editor.get('userid'),
69
                'commenttext': comment.rawtext,
70
                'width': comment.width,
71
                'colour': comment.colour,
72
                'attemptnumber': this.editor.get('attemptnumber'),
73
                'assignmentid': this.editor.get('assignmentid')
74
            },
75
            on: {
76
                success: function(tid, response) {
77
                    var jsondata, quickcomment;
78
                    try {
79
                        jsondata = Y.JSON.parse(response.responseText);
80
                        if (jsondata.error) {
81
                            return new M.core.ajaxException(jsondata);
82
                        } else {
83
                            quickcomment = new M.assignfeedback_editpdf.quickcomment(jsondata.id,
84
                                                                                     jsondata.rawtext,
85
                                                                                     jsondata.width,
86
                                                                                     jsondata.colour);
87
                            this.comments.push(quickcomment);
88
                            this.comments.sort(function(a, b) {
89
                                return a.rawtext.localeCompare(b.rawtext);
90
                            });
91
                        }
92
                    } catch (e) {
93
                        return new M.core.exception(e);
94
                    }
95
                },
96
                failure: function(tid, response) {
97
                    return M.core.exception(response.responseText);
98
                }
99
            }
100
        };
101
 
102
        Y.io(ajaxurl, config);
103
    };
104
 
105
    /**
106
     * Remove a comment from the users quicklist.
107
     *
108
     * @public
109
     * @method remove
110
     */
111
    this.remove = function(comment) {
112
        var ajaxurl = AJAXBASE,
113
            config;
114
 
115
        // Should not happen.
116
        if (!comment) {
117
            return;
118
        }
119
 
120
        config = {
121
            method: 'post',
122
            context: this,
123
            sync: false,
124
            data: {
125
                'sesskey': M.cfg.sesskey,
126
                'action': 'removefromquicklist',
127
                'userid': this.editor.get('userid'),
128
                'commentid': comment.id,
129
                'attemptnumber': this.editor.get('attemptnumber'),
130
                'assignmentid': this.editor.get('assignmentid')
131
            },
132
            on: {
133
                success: function() {
134
                    var i;
135
 
136
                    // Find and remove the comment from the quicklist.
137
                    i = this.comments.indexOf(comment);
138
                    if (i >= 0) {
139
                        this.comments.splice(i, 1);
140
                    }
141
                },
142
                failure: function(tid, response) {
143
                    return M.core.exception(response.responseText);
144
                }
145
            }
146
        };
147
 
148
        Y.io(ajaxurl, config);
149
    };
150
 
151
    /**
152
     * Load the users quick comments list.
153
     *
154
     * @protected
155
     * @method load_quicklist
156
     */
157
    this.load = function() {
158
        var ajaxurl = AJAXBASE,
159
            config;
160
 
161
        config = {
162
            method: 'get',
163
            context: this,
164
            sync: false,
165
            data: {
166
                'sesskey': M.cfg.sesskey,
167
                'action': 'loadquicklist',
168
                'userid': this.editor.get('userid'),
169
                'attemptnumber': this.editor.get('attemptnumber'),
170
                'assignmentid': this.editor.get('assignmentid')
171
            },
172
            on: {
173
                success: function(tid, response) {
174
                    var jsondata;
175
                    try {
176
                        jsondata = Y.JSON.parse(response.responseText);
177
                        if (jsondata.error) {
178
                            return new M.core.ajaxException(jsondata);
179
                        } else {
180
                            Y.each(jsondata, function(comment) {
181
                                var quickcomment = new M.assignfeedback_editpdf.quickcomment(comment.id,
182
                                                                                             comment.rawtext,
183
                                                                                             comment.width,
184
                                                                                             comment.colour);
185
                                this.comments.push(quickcomment);
186
                            }, this);
187
 
188
                            this.comments.sort(function(a, b) {
189
                                return a.rawtext.localeCompare(b.rawtext);
190
                            });
191
                        }
192
                    } catch (e) {
193
                        return new M.core.exception(e);
194
                    }
195
                },
196
                failure: function(tid, response) {
197
                    return M.core.exception(response.responseText);
198
                }
199
            }
200
        };
201
 
202
        Y.io(ajaxurl, config);
203
    };
204
};
205
 
206
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
207
M.assignfeedback_editpdf.quickcommentlist = QUICKCOMMENTLIST;