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
 * This module is the highest level module for the calendar. It is
18
 * responsible for initialising all of the components required for
19
 * the calendar to run. It also coordinates the interaction between
20
 * components by listening for and responding to different events
21
 * triggered within the calendar UI.
22
 *
23
 * @module     mod_forum/posts_list
24
 * @copyright  2019 Peter Dias
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
define([
28
    'jquery',
29
    'core/templates',
30
    'core/notification',
31
    'core/pending',
32
    'mod_forum/selectors',
33
    'mod_forum/inpage_reply',
34
    'core_form/changechecker',
35
], function(
36
    $,
37
    Templates,
38
    Notification,
39
    Pending,
40
    Selectors,
41
    InPageReply,
42
    FormChangeChecker
43
) {
44
 
45
    var registerEventListeners = function(root, throttlingwarningmsg) {
46
        root.on('click', Selectors.post.inpageReplyLink, function(e) {
47
            e.preventDefault();
48
            // After adding a reply a url hash is being generated that scrolls (points) to the newly added reply.
49
            // The hash being present causes this scrolling behavior to the particular reply to persists even when
50
            // another, non-related in-page replay link is being clicked which ultimately causes a bad user experience.
51
            // A particular solution for this problem would be changing the browser's history state when a url hash is
52
            // present.
53
            if (window.location.hash) {
54
                // Remove the fragment identifier from the url.
55
                var url = window.location.href.split('#')[0];
56
                history.pushState({}, document.title, url);
57
            }
58
            var pending = new Pending('inpage-reply');
59
            var currentTarget = $(e.currentTarget).parents(Selectors.post.forumCoreContent);
60
            var currentSubject = currentTarget.find(Selectors.post.forumSubject);
61
            var currentRoot = $(e.currentTarget).parents(Selectors.post.forumContent);
62
            var context = {
63
                postid: $(currentRoot).data('post-id'),
64
                "reply_url": $(e.currentTarget).attr('href'),
65
                sesskey: M.cfg.sesskey,
66
                parentsubject: currentSubject.data('replySubject'),
67
                canreplyprivately: $(e.currentTarget).data('can-reply-privately'),
68
                postformat: InPageReply.CONTENT_FORMATS.MOODLE,
69
                throttlingwarningmsg: throttlingwarningmsg
70
            };
71
 
72
            if (!currentRoot.find(Selectors.post.inpageReplyContent).length) {
73
                Templates.render('mod_forum/inpage_reply', context)
74
                    .then(function(html, js) {
75
                        return Templates.appendNodeContents(currentTarget, html, js);
76
                    })
77
                    .then(function() {
78
                        return currentRoot.find(Selectors.post.inpageReplyContent)
79
                            .slideToggle(300, pending.resolve).find('textarea').focus();
80
                    })
81
                    .then(function() {
82
                        FormChangeChecker.watchFormById(`inpage-reply-${context.postid}`);
83
                        return;
84
                    })
85
                    .catch(Notification.exception);
86
            } else {
87
                var form = currentRoot.find(Selectors.post.inpageReplyContent);
88
                form.slideToggle(300, pending.resolve);
89
                if (form.is(':visible')) {
90
                    form.find('textarea').focus();
91
                }
92
            }
93
        });
94
    };
95
 
96
    return {
97
        init: function(root, throttlingwarningmsg) {
98
            registerEventListeners(root, throttlingwarningmsg);
99
            InPageReply.init(root);
100
        }
101
    };
102
});