Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('moodle-core-maintenancemodetimer', function (Y, NAME) {
2
 
3
/**
4
 * Maintenance mode timer display.
5
 *
6
 * @module moodle-core-maintenancemodetimer
7
 */
8
var MAINTENANCEMODETIMER = function() {
9
        MAINTENANCEMODETIMER.superclass.constructor.apply(this, arguments);
10
    };
11
 
12
Y.extend(MAINTENANCEMODETIMER, Y.Base, {
13
    timeleftinsec: 0,
14
    maintenancenode: Y.one('.box.maintenancewarning'),
15
 
16
    /**
17
     * Initialise timer if maintenancemode set.
18
     *
19
     * @method initializer
20
     * @param config {Array} array with timeleftinsec set.
21
     */
22
    initializer: function(config) {
23
        if (this.maintenancenode) {
24
            this.timeleftinsec = config.timeleftinsec;
25
            this.maintenancenode.setAttribute('aria-live', 'polite');
26
            Y.later(1000, this, 'updatetimer', null, true);
27
        }
28
    },
29
 
30
    /**
31
     * Decrement time left and update display text.
32
     *
33
     * @method updatetimer
34
     */
35
    updatetimer: function() {
36
        this.timeleftinsec -= 1;
37
        if (this.timeleftinsec <= 0) {
38
            this.maintenancenode.set('text', M.util.get_string('sitemaintenance', 'admin'));
39
        } else {
40
            var a = {};
41
            a.sec = this.timeleftinsec % 60;
42
            a.min = Math.floor(this.timeleftinsec / 60) % 60;
43
            a.hour = Math.floor(this.timeleftinsec / 3600);
44
            if (a.hour > 0) {
45
                this.maintenancenode.set('text', M.util.get_string('maintenancemodeisscheduledlong', 'admin', a));
46
            } else {
47
                this.maintenancenode.set('text', M.util.get_string('maintenancemodeisscheduled', 'admin', a));
48
            }
49
        }
50
        // Set error class to highlight the importance.
51
        if (this.timeleftinsec < 30) {
52
            this.maintenancenode.addClass('alert-error')
53
                    .addClass('alert-danger')
54
                    .removeClass('alert-warning');
55
        } else {
56
            this.maintenancenode.addClass('alert-warning')
57
                    .removeClass('alert-error')
58
                    .removeClass('alert-danger');
59
        }
60
    }
61
});
62
 
63
M.core = M.core || {};
64
M.core.maintenancemodetimer = M.core.maintenancemodetimer || function(config) {
65
    return new MAINTENANCEMODETIMER(config);
66
};
67
 
68
 
69
}, '@VERSION@', {"requires": ["base", "node"]});