userHeader.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (username !== Meteor.user().username) {
  27. Meteor.call('setUsername', username, function(error) {
  28. const messageElement = tpl.$('.username-taken');
  29. if (error) {
  30. messageElement.show();
  31. } else {
  32. messageElement.hide();
  33. Popup.back();
  34. }
  35. });
  36. } else Popup.back();
  37. },
  38. });
  39. Template.editNotificationPopup.helpers({
  40. hasTag(tag) {
  41. const user = Meteor.user();
  42. return user && user.hasTag(tag);
  43. },
  44. });
  45. // we defined github like rules, see: https://github.com/settings/notifications
  46. Template.editNotificationPopup.events({
  47. 'click .js-toggle-tag-notify-participate'() {
  48. const user = Meteor.user();
  49. if (user) user.toggleTag('notify-participate');
  50. },
  51. 'click .js-toggle-tag-notify-watch'() {
  52. const user = Meteor.user();
  53. if (user) user.toggleTag('notify-watch');
  54. },
  55. });
  56. // XXX For some reason the useraccounts autofocus isnt working in this case.
  57. // See https://github.com/meteor-useraccounts/core/issues/384
  58. Template.changePasswordPopup.onRendered(function() {
  59. this.find('#at-field-current_password').focus();
  60. });
  61. Template.changeLanguagePopup.helpers({
  62. languages() {
  63. return _.map(TAPi18n.getLanguages(), (lang, tag) => {
  64. const name = lang.name;
  65. return { tag, name };
  66. });
  67. },
  68. isCurrentLanguage() {
  69. return this.tag === TAPi18n.getLanguage();
  70. },
  71. });
  72. Template.changeLanguagePopup.events({
  73. 'click .js-set-language'(evt) {
  74. Users.update(Meteor.userId(), {
  75. $set: {
  76. 'profile.language': this.tag,
  77. },
  78. });
  79. evt.preventDefault();
  80. },
  81. });