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
 * Javascript controller for the "Review" panel at the left of the page.
18
 *
19
 * @module     mod_assign/grading_review_panel
20
 * @copyright  2016 Damyon Wiese <damyon@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @since      3.1
23
 */
24
define(['jquery', 'mod_assign/grading_events'], function($, GradingEvents) {
25
 
26
    /**
27
     * GradingReviewPanel class.
28
     *
29
     * @class mod_assign/grading_review_panel
30
     */
31
    var GradingReviewPanel = function() {
32
        this._region = $('[data-region="review-panel-content"]');
33
        this.registerEventListeners();
34
    };
35
 
36
    /** @property {JQuery} JQuery node for the page region containing the user navigation. */
37
    GradingReviewPanel.prototype._region = null;
38
 
39
    /**
40
     * It is first come first served to get ownership of the grading review panel.
41
     * There can be only one.
42
     *
43
     * @public
44
     * @method getReviewPanel
45
     * @param {String} pluginname - the first plugin to ask for the panel gets it.
46
     * @return {DOMNode} or false
47
     */
48
    GradingReviewPanel.prototype.getReviewPanel = function(pluginname) {
49
        var owner = this._region.data('panel-owner');
50
        if (typeof owner == "undefined") {
51
            this._region.data('review-panel-plugin', pluginname);
52
        }
53
        if (this._region.data('review-panel-plugin') == pluginname) {
54
            return this._region[0];
55
        }
56
        return false;
57
    };
58
 
59
    /**
60
     * Get the toggle review panel button.
61
     *
62
     * @method getTogglePanelButton
63
     * @return {jQuery}
64
     */
65
    GradingReviewPanel.prototype.getTogglePanelButton = function() {
66
        return this.getPanelElement().find('[data-region="review-panel-toggle"]');
67
    };
68
 
69
    /**
70
     * Get the review panel element.
71
     *
72
     * @method getPanelElement
73
     * @return {jQuery}
74
     */
75
    GradingReviewPanel.prototype.getPanelElement = function() {
76
        return $('[data-region="review-panel"]');
77
    };
78
 
79
    /**
80
     * Get the review panel content element.
81
     *
82
     * @method getPanelContentElement
83
     * @return {jQuery}
84
     */
85
    GradingReviewPanel.prototype.getPanelContentElement = function() {
86
        return $('[data-region="review-panel-content"]');
87
    };
88
 
89
    /**
90
     * Show/Hide the review panel.
91
     *
92
     * @method togglePanel
93
     */
94
    GradingReviewPanel.prototype.togglePanel = function() {
95
        if (this.getPanelElement().hasClass('collapsed')) {
96
            $(document).trigger(GradingEvents.EXPAND_REVIEW_PANEL);
97
        } else {
98
            $(document).trigger(GradingEvents.COLLAPSE_REVIEW_PANEL);
99
        }
100
    };
101
 
102
    /**
103
     * Hide the review panel.
104
     *
105
     * @method collapsePanel
106
     */
107
    GradingReviewPanel.prototype.collapsePanel = function() {
108
        this.getPanelElement().addClass('collapsed').removeClass('grade-panel-collapsed');
109
        this.getPanelContentElement().attr('aria-hidden', true);
110
    };
111
 
112
    /**
113
     * Show the review panel.
114
     *
115
     * @method expandPanel
116
     */
117
    GradingReviewPanel.prototype.expandPanel = function() {
118
        this.getPanelElement().removeClass('collapsed');
119
        this.getPanelContentElement().removeAttr('aria-hidden');
120
    };
121
 
122
    /**
123
     * Register event listeners for the review panel.
124
     *
125
     * @method registerEventListeners
126
     */
127
    GradingReviewPanel.prototype.registerEventListeners = function() {
128
        var toggleReviewPanelButton = this.getTogglePanelButton();
129
        toggleReviewPanelButton.click(function(e) {
130
            this.togglePanel();
131
            e.preventDefault();
132
        }.bind(this));
133
 
134
        toggleReviewPanelButton.keydown(function(e) {
135
            if (!e.metaKey && !e.shiftKey && !e.altKey && !e.ctrlKey) {
136
                if (e.keyCode === 13 || e.keyCode === 32) {
137
                    this.togglePanel();
138
                    e.preventDefault();
139
                }
140
            }
141
        }.bind(this));
142
 
143
        var docElement = $(document);
144
        docElement.on(GradingEvents.COLLAPSE_REVIEW_PANEL, function() {
145
            this.collapsePanel();
146
        }.bind(this));
147
 
148
        // Need special styling when grade panel is collapsed.
149
        docElement.on(GradingEvents.COLLAPSE_GRADE_PANEL, function() {
150
            this.expandPanel();
151
            this.getPanelElement().addClass('grade-panel-collapsed');
152
        }.bind(this));
153
 
154
        docElement.on(GradingEvents.EXPAND_REVIEW_PANEL, function() {
155
            this.expandPanel();
156
        }.bind(this));
157
 
158
        docElement.on(GradingEvents.EXPAND_GRADE_PANEL, function() {
159
            this.getPanelElement().removeClass('grade-panel-collapsed');
160
        }.bind(this));
161
    };
162
 
163
    return GradingReviewPanel;
164
});