You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageReloadOverlay.js 2.9KB

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