|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+/* global $, APP, AJS */
|
|
|
2
|
+
|
|
|
3
|
+import { reload } from '../../util/helpers';
|
|
|
4
|
+
|
|
|
5
|
+let $overlay;
|
|
|
6
|
+
|
|
|
7
|
+/**
|
|
|
8
|
+ * Conference reload counter in seconds.
|
|
|
9
|
+ * @type {number}
|
|
|
10
|
+ */
|
|
|
11
|
+let timeLeft;
|
|
|
12
|
+
|
|
|
13
|
+/**
|
|
|
14
|
+ * Conference reload timeout in seconds.
|
|
|
15
|
+ * @type {number}
|
|
|
16
|
+ */
|
|
|
17
|
+let timeout;
|
|
|
18
|
+
|
|
|
19
|
+/**
|
|
|
20
|
+ * Internal function that constructs overlay with the warning message and count
|
|
|
21
|
+ * down towards the conference reload.
|
|
|
22
|
+ */
|
|
|
23
|
+function buildReloadOverlayHtml() {
|
|
|
24
|
+ $overlay = $(`
|
|
|
25
|
+ <div class='overlay_container'>
|
|
|
26
|
+ <div class='overlay_content'>
|
|
|
27
|
+ <span data-i18n='dialog.serviceUnavailable'
|
|
|
28
|
+ class='overlay_text_small'></span>
|
|
|
29
|
+ <span data-i18n='dialog.conferenceReloadMsg'
|
|
|
30
|
+ class='overlay_text_small'></span>
|
|
|
31
|
+ <div>
|
|
|
32
|
+ <div id='reloadProgressBar' class="aui-progress-indicator">
|
|
|
33
|
+ <span class="aui-progress-indicator-value"></span>
|
|
|
34
|
+ </div>
|
|
|
35
|
+ <span id='reloadSecRemaining' class='overlay_text_small'>
|
|
|
36
|
+ </span>
|
|
|
37
|
+ </div>
|
|
|
38
|
+ </div>
|
|
|
39
|
+ </div>`);
|
|
|
40
|
+
|
|
|
41
|
+ APP.translation.translateElement($overlay);
|
|
|
42
|
+}
|
|
|
43
|
+
|
|
|
44
|
+/**
|
|
|
45
|
+ * Updates the progress indicator position and the label with the time left.
|
|
|
46
|
+ */
|
|
|
47
|
+function updateDisplay() {
|
|
|
48
|
+
|
|
|
49
|
+ const timeLeftTxt
|
|
|
50
|
+ = APP.translation.translateString(
|
|
|
51
|
+ "dialog.conferenceReloadTimeLeft",
|
|
|
52
|
+ { seconds: timeLeft });
|
|
|
53
|
+ $("#reloadSecRemaining").text(timeLeftTxt);
|
|
|
54
|
+
|
|
|
55
|
+ const ratio = (timeout-timeLeft)/timeout;
|
|
|
56
|
+ AJS.progressBars.update("#reloadProgressBar", ratio);
|
|
|
57
|
+}
|
|
|
58
|
+
|
|
|
59
|
+/**
|
|
|
60
|
+ * Starts the reload countdown with the animation.
|
|
|
61
|
+ * @param {number} timeoutSeconds how many seconds before the conference
|
|
|
62
|
+ * reload will happen.
|
|
|
63
|
+ */
|
|
|
64
|
+function start(timeoutSeconds) {
|
|
|
65
|
+
|
|
|
66
|
+ timeLeft = timeout = timeoutSeconds;
|
|
|
67
|
+
|
|
|
68
|
+ // Initialize displays
|
|
|
69
|
+ updateDisplay();
|
|
|
70
|
+
|
|
|
71
|
+ var intervalId = window.setInterval(function() {
|
|
|
72
|
+
|
|
|
73
|
+ if (timeLeft >= 1) {
|
|
|
74
|
+ timeLeft -= 1;
|
|
|
75
|
+ console.info("Reloading in " + timeLeft + " seconds...");
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ updateDisplay();
|
|
|
79
|
+
|
|
|
80
|
+ if (timeLeft === 0) {
|
|
|
81
|
+ console.info("Reloading!");
|
|
|
82
|
+ window.clearInterval(intervalId);
|
|
|
83
|
+ reload();
|
|
|
84
|
+ }
|
|
|
85
|
+ }, 1000);
|
|
|
86
|
+}
|
|
|
87
|
+
|
|
|
88
|
+export default {
|
|
|
89
|
+ /**
|
|
|
90
|
+ * Shows the page reload overlay which will do the conference reload after
|
|
|
91
|
+ * the given amount of time.
|
|
|
92
|
+ *
|
|
|
93
|
+ * @param {number} timeoutSeconds how many seconds before the conference
|
|
|
94
|
+ * reload will happen.
|
|
|
95
|
+ */
|
|
|
96
|
+ show(timeoutSeconds) {
|
|
|
97
|
+
|
|
|
98
|
+ !$overlay && buildReloadOverlayHtml();
|
|
|
99
|
+
|
|
|
100
|
+ if (!$overlay.parents('body').length) {
|
|
|
101
|
+ $overlay.appendTo('body');
|
|
|
102
|
+ start(timeoutSeconds);
|
|
|
103
|
+ }
|
|
|
104
|
+ }
|
|
|
105
|
+};
|