Commit | Line | Data |
---|---|---|
f487a8f8 RT |
1 | YUI.add('moodle-core-maintenancemode', 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(MAINTENANCEMODE, Y.Base, { | |
13 | timeleftinsec: 0, | |
14 | maintenancenode: Y.one('.box.maintenancewarning'), | |
15 | ||
16 | /** | |
17 | * Initialise timer if maintenancemode set. | |
18 | * | |
19 | * @param config {Array} array with timeleftinsec set. | |
20 | */ | |
21 | initializer: function(config) { | |
22 | if (this.maintenancenode) { | |
23 | this.timeleftinsec = config.timeleftinsec; | |
24 | this.maintenancenode.setAttribute('aria-live', 'polite'); | |
25 | Y.later(1000, this, 'updatetimer', null, true); | |
26 | } | |
27 | }, | |
28 | ||
29 | /** | |
30 | * Decrement time left and update display text. | |
31 | */ | |
32 | updatetimer: function() { | |
33 | this.timeleftinsec -= 1; | |
34 | if (this.timeleftinsec <= 0) { | |
35 | this.maintenancenode.set('text', M.str.admin.sitemaintenance); | |
36 | } else { | |
37 | var a = {}; | |
38 | a.sec = this.timeleftinsec % 60; | |
39 | a.min = Math.floor(this.timeleftinsec / 60); | |
40 | this.maintenancenode.set('text', M.util.get_string('maintenancemodeisscheduled', 'admin', a)); | |
41 | } | |
42 | // Set error class to highlight the importance. | |
43 | if (this.timeleftinsec < 30) { | |
44 | this.maintenancenode.addClass('error') | |
45 | .removeClass('warning'); | |
46 | } else { | |
47 | this.maintenancenode.addClass('warning') | |
48 | .removeClass('error'); | |
49 | } | |
50 | } | |
51 | }); | |
52 | M.core = M.core || {}; | |
53 | M.core.maintenancemodetimer = M.core.maintenancemodetimer || function(config) { | |
54 | return new MAINTENANCEMODETIMER(config); | |
55 | }; | |
56 | ||
57 | ||
58 | }, '@VERSION@', {"requires": ["base", "node"]}); |