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

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