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.5KB

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