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

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