userHeader.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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': function(evt) {
  11. evt.preventDefault();
  12. AccountsTemplates.logout();
  13. }
  14. });
  15. Template.editProfilePopup.events({
  16. submit: function(evt, tpl) {
  17. evt.preventDefault();
  18. var fullname = $.trim(tpl.find('.js-profile-fullname').value);
  19. var username = $.trim(tpl.find('.js-profile-username').value);
  20. var 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(function() {
  35. this.find('#at-field-current_password').focus();
  36. });
  37. Template.changeLanguagePopup.helpers({
  38. languages: function() {
  39. return _.map(TAPi18n.getLanguages(), function(lang, tag) {
  40. return {
  41. tag: tag,
  42. name: lang.name
  43. };
  44. });
  45. },
  46. isCurrentLanguage: function() {
  47. return this.tag === TAPi18n.getLanguage();
  48. }
  49. });
  50. Template.changeLanguagePopup.events({
  51. 'click .js-set-language': function(evt) {
  52. Users.update(Meteor.userId(), {
  53. $set: {
  54. 'profile.language': this.tag
  55. }
  56. });
  57. evt.preventDefault();
  58. }
  59. });