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/pin_toggle
24
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
define([
28
    'jquery',
29
    'core/ajax',
30
    'core/str',
31
    'core/templates',
32
    'core/notification',
33
    'mod_forum/repository',
34
    'mod_forum/selectors',
35
    'core/str',
36
], function(
37
    $,
38
    Ajax,
39
    Str,
40
    Templates,
41
    Notification,
42
    Repository,
43
    Selectors,
44
    String
45
) {
46
 
47
    /**
48
     * Registery event listeners for the pin toggle.
49
     *
50
     * @param {object} root The calendar root element
51
     * @param {boolean} preventDefault Should the default action of the event be prevented
52
     * @param {function} callback Success callback
53
     */
54
    var registerEventListeners = function(root, preventDefault, callback) {
55
        root.on('click', Selectors.pin.toggle, function(e) {
56
            var toggleElement = $(this);
57
            var forumid = toggleElement.data('forumid');
58
            var discussionid = toggleElement.data('discussionid');
59
            var pinstate = toggleElement.data('targetstate');
60
            Repository.setPinDiscussionState(forumid, discussionid, pinstate)
61
                .then(function(context) {
62
                    return callback(toggleElement, context);
63
                })
64
                .then(function() {
65
                    return String.get_string("pinupdated", "forum")
66
                        .done(function(s) {
67
                            return Notification.addNotification({
68
                                message: s,
69
                                type: "info"
70
                            });
71
                        });
72
                })
73
                .fail(Notification.exception);
74
 
75
            if (preventDefault) {
76
                e.preventDefault();
77
            }
78
        });
79
    };
80
 
81
    return {
82
        init: registerEventListeners
83
    };
84
});