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.

Profile.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* global $, APP */
  2. import UIUtil from "../../util/UIUtil";
  3. import UIEvents from "../../../../service/UI/UIEvents";
  4. import Settings from '../../../settings/Settings';
  5. import { sendEvent } from '../../../../react/features/analytics';
  6. const sidePanelsContainerId = 'sideToolbarContainer';
  7. const htmlStr = `
  8. <div id="profile_container" class="sideToolbarContainer__inner">
  9. <div class="title" data-i18n="profile.title"></div>
  10. <div class="sideToolbarBlock first">
  11. <label class="first" data-i18n="profile.setDisplayNameLabel">
  12. </label>
  13. <input class="input-control" type="text" id="setDisplayName"
  14. data-i18n="[placeholder]settings.name">
  15. </div>
  16. <div class="sideToolbarBlock">
  17. <label data-i18n="profile.setEmailLabel"></label>
  18. <input id="setEmail" type="text" class="input-control"
  19. data-i18n="[placeholder]profile.setEmailInput">
  20. </div>
  21. <div id="profile_auth_container"
  22. class="sideToolbarBlock auth_container">
  23. <p data-i18n="toolbar.authenticate"></p>
  24. <ul>
  25. <li id="profile_auth_identity"></li>
  26. <li id="profile_button_login">
  27. <a class="authButton" data-i18n="toolbar.login"></a>
  28. </li>
  29. <li id="profile_button_logout">
  30. <a class="authButton" data-i18n="toolbar.logout"></a>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>`;
  35. function initHTML() {
  36. $(`#${sidePanelsContainerId}`)
  37. .append(htmlStr);
  38. // make sure we translate the panel, as adding it can be after i18n
  39. // library had initialized and translated already present html
  40. APP.translation.translateElement($(`#${sidePanelsContainerId}`));
  41. }
  42. export default {
  43. init (emitter) {
  44. initHTML();
  45. // DISPLAY NAME
  46. function updateDisplayName () {
  47. emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
  48. }
  49. $('#setDisplayName')
  50. .val(Settings.getDisplayName())
  51. .keyup(function (event) {
  52. if (event.keyCode === 13) { // enter
  53. updateDisplayName();
  54. }
  55. })
  56. .focusout(updateDisplayName);
  57. // EMAIL
  58. function updateEmail () {
  59. emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
  60. }
  61. $('#setEmail')
  62. .val(Settings.getEmail())
  63. .keyup(function (event) {
  64. if (event.keyCode === 13) { // enter
  65. updateEmail();
  66. }
  67. }).focusout(updateEmail);
  68. // LOGIN
  69. function loginClicked () {
  70. sendEvent('authenticate.login.clicked');
  71. emitter.emit(UIEvents.AUTH_CLICKED);
  72. }
  73. $('#profile_button_login').click(loginClicked);
  74. // LOGOUT
  75. function logoutClicked () {
  76. let titleKey = "dialog.logoutTitle";
  77. let msgKey = "dialog.logoutQuestion";
  78. sendEvent('authenticate.logout.clicked');
  79. // Ask for confirmation
  80. APP.UI.messageHandler.openTwoButtonDialog({
  81. titleKey: titleKey,
  82. msgKey: msgKey,
  83. leftButtonKey: "dialog.Yes",
  84. submitFunction: function (evt, yes) {
  85. if (yes) {
  86. emitter.emit(UIEvents.LOGOUT);
  87. }
  88. }
  89. });
  90. }
  91. $('#profile_button_logout').click(logoutClicked);
  92. },
  93. /**
  94. * Check if settings menu is visible or not.
  95. * @returns {boolean}
  96. */
  97. isVisible () {
  98. return UIUtil.isVisible(document.getElementById("profile_container"));
  99. },
  100. /**
  101. * Change user display name in the settings menu.
  102. * @param {string} newDisplayName
  103. */
  104. changeDisplayName (newDisplayName) {
  105. $('#setDisplayName').val(newDisplayName);
  106. },
  107. /**
  108. * Change user avatar in the settings menu.
  109. * @param {string} avatarUrl url of the new avatar
  110. */
  111. changeAvatar (avatarUrl) {
  112. $('#avatar').attr('src', avatarUrl);
  113. },
  114. /**
  115. * Change the value of the field for the user email.
  116. * @param {string} email the new value that will be displayed in the field.
  117. */
  118. changeEmail (email) {
  119. $('#setEmail').val(email);
  120. },
  121. /**
  122. * Shows or hides authentication related buttons
  123. * @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
  124. */
  125. showAuthenticationButtons (show) {
  126. let id = 'profile_auth_container';
  127. UIUtil.setVisible(id, show);
  128. },
  129. /**
  130. * Shows/hides login button.
  131. * @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
  132. */
  133. showLoginButton (show) {
  134. let id = 'profile_button_login';
  135. UIUtil.setVisible(id, show);
  136. },
  137. /**
  138. * Shows/hides logout button.
  139. * @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
  140. */
  141. showLogoutButton (show) {
  142. let id = 'profile_button_logout';
  143. UIUtil.setVisible(id, show);
  144. },
  145. /**
  146. * Displays user's authenticated identity name (login).
  147. * @param {string} authIdentity identity name to be displayed.
  148. */
  149. setAuthenticatedIdentity (authIdentity) {
  150. let id = 'profile_auth_identity';
  151. UIUtil.setVisible(id, !!authIdentity);
  152. $(`#${id}`).text(authIdentity ? authIdentity : '');
  153. }
  154. };