Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Profile.js 5.6KB

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