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
 * Manage the timeline view for the timeline block.
18
 *
19
 * @copyright  2018 Ryan Wyllie <ryan@moodle.com>
20
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
22
 
23
define(
24
[
25
    'jquery',
26
    'block_timeline/view_dates',
27
    'block_timeline/view_courses',
28
],
29
function(
30
    $,
31
    ViewDates,
32
    ViewCourses
33
) {
34
 
35
    var SELECTORS = {
36
        TIMELINE_DATES_VIEW: '[data-region="view-dates"]',
37
        TIMELINE_COURSES_VIEW: '[data-region="view-courses"]',
38
    };
39
 
40
    /**
41
     * Intialise the timeline dates and courses views on page load.
42
     * This function should only be called once per page load because
43
     * it can cause event listeners to be added to the page.
44
     *
45
     * @param {object} root The root element for the timeline view.
46
     */
47
    var init = function(root) {
48
        root = $(root);
49
        var datesViewRoot = root.find(SELECTORS.TIMELINE_DATES_VIEW);
50
        var coursesViewRoot = root.find(SELECTORS.TIMELINE_COURSES_VIEW);
51
 
52
        ViewDates.init(datesViewRoot);
53
        ViewCourses.init(coursesViewRoot);
54
    };
55
 
56
    /**
57
     * Reset the timeline dates and courses views to their original
58
     * state on first page load.
59
     *
60
     * This is called when configuration has changed for the event lists
61
     * to cause them to reload their data.
62
     *
63
     * @param {object} root The root element for the timeline view.
64
     */
65
    var reset = function(root) {
66
        var datesViewRoot = root.find(SELECTORS.TIMELINE_DATES_VIEW);
67
        var coursesViewRoot = root.find(SELECTORS.TIMELINE_COURSES_VIEW);
68
        ViewDates.reset(datesViewRoot);
69
        ViewCourses.reset(coursesViewRoot);
70
    };
71
 
72
    /**
73
     * Tell the timeline dates or courses view that it has been displayed.
74
     *
75
     * This is called each time one of the views is displayed and is used to
76
     * lazy load the data within it on first load.
77
     *
78
     * @param {object} root The root element for the timeline view.
79
     */
80
    var shown = function(root) {
81
        var datesViewRoot = root.find(SELECTORS.TIMELINE_DATES_VIEW);
82
        var coursesViewRoot = root.find(SELECTORS.TIMELINE_COURSES_VIEW);
83
 
84
        if (datesViewRoot.hasClass('active')) {
85
            ViewDates.shown(datesViewRoot);
86
        } else {
87
            ViewCourses.shown(coursesViewRoot);
88
        }
89
    };
90
 
91
    return {
92
        init: init,
93
        reset: reset,
94
        shown: shown,
95
    };
96
});