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.

MessageHandler.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* global $, APP */
  2. import {
  3. NOTIFICATION_TIMEOUT,
  4. showErrorNotification,
  5. showNotification,
  6. showWarningNotification
  7. } from '../../../react/features/notifications';
  8. const messageHandler = {
  9. OK: 'dialog.OK',
  10. CANCEL: 'dialog.Cancel',
  11. /**
  12. * Returns the formatted title string.
  13. *
  14. * @return the title string formatted as a div.
  15. */
  16. _getFormattedTitleString(titleKey) {
  17. const $titleString = $('<h2>');
  18. $titleString.addClass('aui-dialog2-header-main');
  19. $titleString.attr('data-i18n', titleKey);
  20. return $('<div>').append($titleString)
  21. .html();
  22. },
  23. /**
  24. * Returns the dialog css classes.
  25. *
  26. * @return the dialog css classes
  27. */
  28. _getDialogClasses(size = 'small') {
  29. return {
  30. box: '',
  31. form: '',
  32. prompt: `dialog aui-layer aui-dialog2 aui-dialog2-${size}`,
  33. close: 'aui-hide',
  34. fade: 'aui-blanket',
  35. button: 'button-control',
  36. message: 'aui-dialog2-content',
  37. buttons: 'aui-dialog2-footer',
  38. defaultButton: 'button-control_primary',
  39. title: 'aui-dialog2-header'
  40. };
  41. },
  42. /**
  43. * Opens new popup window for given <tt>url</tt> centered over current
  44. * window.
  45. *
  46. * @param url the URL to be displayed in the popup window
  47. * @param w the width of the popup window
  48. * @param h the height of the popup window
  49. * @param onPopupClosed optional callback function called when popup window
  50. * has been closed.
  51. *
  52. * @returns {object} popup window object if opened successfully or undefined
  53. * in case we failed to open it(popup blocked)
  54. */
  55. // eslint-disable-next-line max-params
  56. openCenteredPopup(url, w, h, onPopupClosed) {
  57. const l = window.screenX + (window.innerWidth / 2) - (w / 2);
  58. const t = window.screenY + (window.innerHeight / 2) - (h / 2);
  59. const popup = window.open(
  60. url, '_blank',
  61. String(`top=${t}, left=${l}, width=${w}, height=${h}`));
  62. if (popup && onPopupClosed) {
  63. const pollTimer = window.setInterval(() => {
  64. if (popup.closed !== false) {
  65. window.clearInterval(pollTimer);
  66. onPopupClosed();
  67. }
  68. }, 200);
  69. }
  70. return popup;
  71. },
  72. /**
  73. * Shows an error dialog to the user.
  74. *
  75. * @param {object} props - The properties to pass to the
  76. * showErrorNotification action.
  77. */
  78. showError(props) {
  79. APP.store.dispatch(showErrorNotification(props));
  80. },
  81. /**
  82. * Shows a warning dialog to the user.
  83. *
  84. * @param {object} props - The properties to pass to the
  85. * showWarningNotification action.
  86. */
  87. showWarning(props) {
  88. APP.store.dispatch(showWarningNotification(props));
  89. },
  90. /**
  91. * Displays a notification about participant action.
  92. * @param displayName the display name of the participant that is
  93. * associated with the notification.
  94. * @param displayNameKey the key from the language file for the display
  95. * name. Only used if displayName is not provided.
  96. * @param cls css class for the notification
  97. * @param messageKey the key from the language file for the text of the
  98. * message.
  99. * @param messageArguments object with the arguments for the message.
  100. * @param optional configurations for the notification (e.g. timeout)
  101. */
  102. participantNotification( // eslint-disable-line max-params
  103. displayName,
  104. displayNameKey,
  105. cls,
  106. messageKey,
  107. messageArguments,
  108. timeout = NOTIFICATION_TIMEOUT) {
  109. APP.store.dispatch(showNotification({
  110. descriptionArguments: messageArguments,
  111. descriptionKey: messageKey,
  112. titleKey: displayNameKey,
  113. title: displayName
  114. },
  115. timeout));
  116. }
  117. };
  118. export default messageHandler;