userHeader.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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-edit-notification': Popup.open('editNotification'),
  11. 'click .js-logout'(evt) {
  12. evt.preventDefault();
  13. AccountsTemplates.logout();
  14. },
  15. });
  16. Template.editProfilePopup.events({
  17. submit(evt, tpl) {
  18. evt.preventDefault();
  19. const fullname = tpl.find('.js-profile-fullname').value.trim();
  20. const username = tpl.find('.js-profile-username').value.trim();
  21. const initials = tpl.find('.js-profile-initials').value.trim();
  22. Users.update(Meteor.userId(), {$set: {
  23. 'profile.fullname': fullname,
  24. 'profile.initials': initials,
  25. }});
  26. // XXX We should report the error to the user.
  27. if (username !== Meteor.user().username) {
  28. Meteor.call('setUsername', username);
  29. }
  30. Popup.back();
  31. },
  32. });
  33. Template.editNotificationPopup.helpers({
  34. hasTag(tag) {
  35. const user = Meteor.user();
  36. return user && user.hasTag(tag);
  37. },
  38. });
  39. // we defined github like rules, see: https://github.com/settings/notifications
  40. Template.editNotificationPopup.events({
  41. 'click .js-toggle-tag-notify-participate'() {
  42. const user = Meteor.user();
  43. if (user) user.toggleTag('notify-participate');
  44. },
  45. 'click .js-toggle-tag-notify-watch'() {
  46. const user = Meteor.user();
  47. if (user) user.toggleTag('notify-watch');
  48. },
  49. });
  50. // XXX For some reason the useraccounts autofocus isnt working in this case.
  51. // See https://github.com/meteor-useraccounts/core/issues/384
  52. Template.changePasswordPopup.onRendered(function() {
  53. this.find('#at-field-current_password').focus();
  54. });
  55. Template.changeLanguagePopup.helpers({
  56. languages() {
  57. return _.map(TAPi18n.getLanguages(), (lang, tag) => {
  58. const name = lang.name;
  59. return { tag, name };
  60. });
  61. },
  62. isCurrentLanguage() {
  63. return this.tag === TAPi18n.getLanguage();
  64. },
  65. });
  66. Template.changeLanguagePopup.events({
  67. 'click .js-set-language'(evt) {
  68. Users.update(Meteor.userId(), {
  69. $set: {
  70. 'profile.language': this.tag,
  71. },
  72. });
  73. evt.preventDefault();
  74. },
  75. });