userHeader.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-settings': Popup.open('changeSettings'),
  8. 'click .js-change-avatar': Popup.open('changeAvatar'),
  9. 'click .js-change-password': Popup.open('changePassword'),
  10. 'click .js-change-language': Popup.open('changeLanguage'),
  11. 'click .js-edit-notification': Popup.open('editNotification'),
  12. 'click .js-logout'(evt) {
  13. evt.preventDefault();
  14. AccountsTemplates.logout();
  15. },
  16. 'click .js-go-setting'() {
  17. Popup.close();
  18. },
  19. });
  20. Template.editProfilePopup.events({
  21. submit(evt, tpl) {
  22. evt.preventDefault();
  23. const fullname = tpl.find('.js-profile-fullname').value.trim();
  24. const username = tpl.find('.js-profile-username').value.trim();
  25. const initials = tpl.find('.js-profile-initials').value.trim();
  26. Users.update(Meteor.userId(), {$set: {
  27. 'profile.fullname': fullname,
  28. 'profile.initials': initials,
  29. }});
  30. if (username !== Meteor.user().username) {
  31. Meteor.call('setUsername', username, function(error) {
  32. const messageElement = tpl.$('.username-taken');
  33. if (error) {
  34. messageElement.show();
  35. } else {
  36. messageElement.hide();
  37. Popup.back();
  38. }
  39. });
  40. } else Popup.back();
  41. },
  42. });
  43. Template.editNotificationPopup.helpers({
  44. hasTag(tag) {
  45. const user = Meteor.user();
  46. return user && user.hasTag(tag);
  47. },
  48. });
  49. // we defined github like rules, see: https://github.com/settings/notifications
  50. Template.editNotificationPopup.events({
  51. 'click .js-toggle-tag-notify-participate'() {
  52. const user = Meteor.user();
  53. if (user) user.toggleTag('notify-participate');
  54. },
  55. 'click .js-toggle-tag-notify-watch'() {
  56. const user = Meteor.user();
  57. if (user) user.toggleTag('notify-watch');
  58. },
  59. });
  60. // XXX For some reason the useraccounts autofocus isnt working in this case.
  61. // See https://github.com/meteor-useraccounts/core/issues/384
  62. Template.changePasswordPopup.onRendered(function() {
  63. this.find('#at-field-current_password').focus();
  64. });
  65. Template.changeLanguagePopup.helpers({
  66. languages() {
  67. return _.map(TAPi18n.getLanguages(), (lang, tag) => {
  68. const name = lang.name;
  69. return { tag, name };
  70. });
  71. },
  72. isCurrentLanguage() {
  73. return this.tag === TAPi18n.getLanguage();
  74. },
  75. });
  76. Template.changeLanguagePopup.events({
  77. 'click .js-set-language'(evt) {
  78. Users.update(Meteor.userId(), {
  79. $set: {
  80. 'profile.language': this.tag,
  81. },
  82. });
  83. evt.preventDefault();
  84. },
  85. });
  86. Template.changeSettingsPopup.helpers({
  87. hiddenSystemMessages() {
  88. return Meteor.user().hasHiddenSystemMessages();
  89. },
  90. showCardsCountAt() {
  91. return Meteor.user().getLimitToShowCardsCount();
  92. },
  93. });
  94. Template.changeSettingsPopup.events({
  95. 'click .js-toggle-system-messages'() {
  96. Meteor.call('toggleSystemMessages');
  97. },
  98. 'click .js-apply-show-cards-at'(evt, tpl) {
  99. evt.preventDefault();
  100. const minLimit = parseInt(tpl.$('#show-cards-count-at').val(), 10);
  101. if (!isNaN(minLimit)) {
  102. Meteor.call('changeLimitToShowCardsCount', minLimit);
  103. Popup.back();
  104. }
  105. },
  106. });