Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Profile.js 5.7KB

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