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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* global $ */
  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 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"
  18. data-i18n="[placeholder]profile.setEmailInput">
  19. </div>
  20. <div id="authenticationContainer"
  21. class="sideToolbarBlock auth_container">
  22. <p data-i18n="toolbar.authenticate"></p>
  23. <ul>
  24. <li id="toolbar_auth_identity"></li>
  25. <li id="toolbar_button_login">
  26. <a class="authButton" data-i18n="toolbar.login"></a>
  27. </li>
  28. <li id="toolbar_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. },
  65. /**
  66. * Check if settings menu is visible or not.
  67. * @returns {boolean}
  68. */
  69. isVisible () {
  70. return UIUtil.isVisible(document.getElementById("profile_container"));
  71. },
  72. /**
  73. * Change user display name in the settings menu.
  74. * @param {string} newDisplayName
  75. */
  76. changeDisplayName (newDisplayName) {
  77. $('#setDisplayName').val(newDisplayName);
  78. },
  79. /**
  80. * Change user avatar in the settings menu.
  81. * @param {string} avatarUrl url of the new avatar
  82. */
  83. changeAvatar (avatarUrl) {
  84. $('#avatar').attr('src', avatarUrl);
  85. }
  86. };