userHeader.js 2.3 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-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. // We display the form to change the password in a popup window that already
  33. // have a title, so we unset the title automatically displayed by useraccounts.
  34. AccountsTemplates.configure({
  35. texts: {
  36. title: {
  37. changePwd: ''
  38. }
  39. }
  40. });
  41. AccountsTemplates.configureRoute('changePwd', {
  42. redirect: function() {
  43. // XXX We should emit a notification once we have a notification system.
  44. // Currently the user has no indication that his modification has been
  45. // applied.
  46. Popup.back();
  47. }
  48. });
  49. // XXX For some reason the useraccounts autofocus isnt working in this case.
  50. // See https://github.com/meteor-useraccounts/core/issues/384
  51. Template.changePasswordPopup.onRendered(function() {
  52. this.find('#at-field-current_password').focus();
  53. });
  54. Template.changeLanguagePopup.helpers({
  55. languages: function() {
  56. return _.map(TAPi18n.getLanguages(), function(lang, tag) {
  57. return {
  58. tag: tag,
  59. name: lang.name
  60. };
  61. });
  62. },
  63. isCurrentLanguage: function() {
  64. return this.tag === TAPi18n.getLanguage();
  65. }
  66. });
  67. Template.changeLanguagePopup.events({
  68. 'click .js-set-language': function(evt) {
  69. Users.update(Meteor.userId(), {
  70. $set: {
  71. 'profile.language': this.tag
  72. }
  73. });
  74. evt.preventDefault();
  75. }
  76. });