userHeader.js 3.2 KB

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