Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/* eslint-disable no-unused-vars */
2
var COMMENTSEARCHNAME = "commentsearch",
3
    COMMENTSEARCH;
4
 
5
/**
6
 * Provides an in browser PDF editor.
7
 *
8
 * @module moodle-assignfeedback_editpdf-editor
9
 */
10
 
11
/**
12
 * This is a searchable dialogue of comments.
13
 *
14
 * @namespace M.assignfeedback_editpdf
15
 * @class commentsearch
16
 * @constructor
17
 * @extends M.core.dialogue
18
 */
19
COMMENTSEARCH = function(config) {
20
    config.draggable = false;
21
    config.centered = true;
22
    config.width = '400px';
23
    config.visible = false;
24
    config.headerContent = M.util.get_string('searchcomments', 'assignfeedback_editpdf');
25
    config.footerContent = '';
26
    COMMENTSEARCH.superclass.constructor.apply(this, [config]);
27
};
28
 
29
Y.extend(COMMENTSEARCH, M.core.dialogue, {
30
    /**
31
     * Initialise the menu.
32
     *
33
     * @method initializer
34
     * @return void
35
     */
36
    initializer: function() {
37
        var editor,
38
            container,
39
            placeholder,
40
            commentfilter,
41
            commentlist,
42
            bb;
43
 
44
        bb = this.get('boundingBox');
45
        bb.addClass('assignfeedback_editpdf_commentsearch');
46
 
47
        editor = this.get('editor');
48
        container = Y.Node.create('<div/>');
49
 
50
        placeholder = M.util.get_string('filter', 'assignfeedback_editpdf');
51
        commentfilter = Y.Node.create('<input type="text" size="20" placeholder="' + placeholder + '"/>');
52
        container.append(commentfilter);
53
        commentlist = Y.Node.create('<ul role="menu" class="assignfeedback_editpdf_search"/>');
54
        container.append(commentlist);
55
 
56
        commentfilter.on('keyup', this.filter_search_comments, this);
57
        commentlist.delegate('click', this.focus_on_comment, 'a', this);
58
        commentlist.delegate('key', this.focus_on_comment, 'enter,space', 'a', this);
59
 
60
        // Set the body content.
61
        this.set('bodyContent', container);
62
    },
63
 
64
    /**
65
     * Event handler to filter the list of comments.
66
     *
67
     * @protected
68
     * @method filter_search_comments
69
     */
70
    filter_search_comments: function() {
71
        var filternode,
72
            commentslist,
73
            filtertext,
74
            dialogueid;
75
 
76
        dialogueid = this.get('id');
77
        filternode = Y.one('#' + dialogueid + SELECTOR.SEARCHFILTER);
78
        commentslist = Y.one('#' + dialogueid + SELECTOR.SEARCHCOMMENTSLIST);
79
 
80
        filtertext = filternode.get('value');
81
 
82
        commentslist.all('li').each(function(node) {
83
            if (node.get('text').indexOf(filtertext) !== -1) {
84
                node.show();
85
            } else {
86
                node.hide();
87
            }
88
        });
89
    },
90
 
91
    /**
92
     * Event handler to focus on a selected comment.
93
     *
94
     * @param Event e
95
     * @protected
96
     * @method focus_on_comment
97
     */
98
    focus_on_comment: function(e) {
99
        e.preventDefault();
100
        var target = e.target.ancestor('li'),
101
            comment = target.getData('comment'),
102
            editor = this.get('editor');
103
 
104
        this.hide();
105
 
106
        comment.pageno = comment.clean().pageno;
107
        if (comment.pageno !== editor.currentpage) {
108
            // Comment is on a different page.
109
            editor.currentpage = comment.pageno;
110
            editor.change_page();
111
        }
112
 
113
        comment.node = comment.drawable.nodes[0].one('textarea');
114
        comment.node.ancestor('div').removeClass('commentcollapsed');
115
        comment.node.focus();
116
    },
117
 
118
    /**
119
     * Show the menu.
120
     *
121
     * @method show
122
     * @return void
123
     */
124
    show: function() {
125
        var commentlist = this.get('boundingBox').one('ul'),
126
            editor = this.get('editor');
127
 
128
        commentlist.all('li').remove(true);
129
 
130
        // Rebuild the latest list of comments.
131
        Y.each(editor.pages, function(page) {
132
            Y.each(page.comments, function(comment) {
133
                var commentnode = Y.Node.create('<li><a href="#" tabindex="-1"><pre>' + comment.rawtext + '</pre></a></li>');
134
                commentlist.append(commentnode);
135
                commentnode.setData('comment', comment);
136
            }, this);
137
        }, this);
138
 
139
        this.centerDialogue();
140
        COMMENTSEARCH.superclass.show.call(this);
141
    }
142
}, {
143
    NAME: COMMENTSEARCHNAME,
144
    ATTRS: {
145
        /**
146
         * The editor this search window is attached to.
147
         *
148
         * @attribute editor
149
         * @type M.assignfeedback_editpdf.editor
150
         * @default null
151
         */
152
        editor: {
153
            value: null
154
        }
155
 
156
    }
157
});
158
 
159
Y.Base.modifyAttrs(COMMENTSEARCH, {
160
    /**
161
     * Whether the widget should be modal or not.
162
     *
163
     * Moodle override: We override this for commentsearch to force it always true.
164
     *
165
     * @attribute Modal
166
     * @type Boolean
167
     * @default true
168
     */
169
    modal: {
170
        getter: function() {
171
            return true;
172
        }
173
    }
174
});
175
 
176
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
177
M.assignfeedback_editpdf.commentsearch = COMMENTSEARCH;