Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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