userHeader.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Template.headerUserBar.events({
  2. 'click .js-open-header-member-menu': Popup.open('memberMenu'),
  3. 'click .js-change-avatar': Popup.open('changeAvatar'),
  4. });
  5. Template.memberMenuPopup.events({
  6. 'click .js-edit-profile': Popup.open('editProfile'),
  7. 'click .js-change-avatar': Popup.open('changeAvatar'),
  8. 'click .js-change-password': Popup.open('changePassword'),
  9. 'click .js-change-language': Popup.open('changeLanguage'),
  10. 'click .js-logout'(evt) {
  11. evt.preventDefault();
  12. AccountsTemplates.logout();
  13. },
  14. });
  15. Template.editProfilePopup.events({
  16. submit(evt, tpl) {
  17. evt.preventDefault();
  18. const fullname = $.trim(tpl.find('.js-profile-fullname').value);
  19. const username = $.trim(tpl.find('.js-profile-username').value);
  20. const initials = $.trim(tpl.find('.js-profile-initials').value);
  21. Users.update(Meteor.userId(), {$set: {
  22. 'profile.fullname': fullname,
  23. 'profile.initials': initials,
  24. }});
  25. // XXX We should report the error to the user.
  26. if (username !== Meteor.user().username) {
  27. Meteor.call('setUsername', username);
  28. }
  29. Popup.back();
  30. },
  31. });
  32. // XXX For some reason the useraccounts autofocus isnt working in this case.
  33. // See https://github.com/meteor-useraccounts/core/issues/384
  34. Template.changePasswordPopup.onRendered(() => {
  35. this.find('#at-field-current_password').focus();
  36. });
  37. Template.changeLanguagePopup.helpers({
  38. languages() {
  39. return _.map(TAPi18n.getLanguages(), (lang, tag) => {
  40. const name = lang.name;
  41. return { tag, name };
  42. });
  43. },
  44. isCurrentLanguage() {
  45. return this.tag === TAPi18n.getLanguage();
  46. },
  47. });
  48. Template.changeLanguagePopup.events({
  49. 'click .js-set-language'(evt) {
  50. Users.update(Meteor.userId(), {
  51. $set: {
  52. 'profile.language': this.tag,
  53. },
  54. });
  55. evt.preventDefault();
  56. },
  57. });