boardsList.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const subManager = new SubsManager();
  2. Template.boardListHeaderBar.events({
  3. 'click .js-open-archived-board'() {
  4. Modal.open('archivedBoards');
  5. },
  6. });
  7. Template.boardListHeaderBar.helpers({
  8. templatesBoardId() {
  9. return Meteor.user().getTemplatesBoardId();
  10. },
  11. templatesBoardSlug() {
  12. return Meteor.user().getTemplatesBoardSlug();
  13. },
  14. });
  15. BlazeComponent.extendComponent({
  16. onCreated() {
  17. Meteor.subscribe('setting');
  18. },
  19. boards() {
  20. return Boards.find(
  21. {
  22. archived: false,
  23. 'members.userId': Meteor.userId(),
  24. type: 'board',
  25. },
  26. { sort: ['title'] },
  27. );
  28. },
  29. isStarred() {
  30. const user = Meteor.user();
  31. return user && user.hasStarred(this.currentData()._id);
  32. },
  33. hasOvertimeCards() {
  34. subManager.subscribe('board', this.currentData()._id, false);
  35. return this.currentData().hasOvertimeCards();
  36. },
  37. hasSpentTimeCards() {
  38. subManager.subscribe('board', this.currentData()._id, false);
  39. return this.currentData().hasSpentTimeCards();
  40. },
  41. isInvited() {
  42. const user = Meteor.user();
  43. return user && user.isInvitedTo(this.currentData()._id);
  44. },
  45. events() {
  46. return [
  47. {
  48. 'click .js-add-board': Popup.open('createBoard'),
  49. 'click .js-star-board'(evt) {
  50. const boardId = this.currentData()._id;
  51. Meteor.user().toggleBoardStar(boardId);
  52. evt.preventDefault();
  53. },
  54. 'click .js-clone-board'(evt) {
  55. Meteor.call(
  56. 'cloneBoard',
  57. this.currentData()._id,
  58. Session.get('fromBoard'),
  59. (err, res) => {
  60. if (err) {
  61. this.setError(err.error);
  62. } else {
  63. Session.set('fromBoard', null);
  64. Utils.goBoardId(res);
  65. }
  66. },
  67. );
  68. evt.preventDefault();
  69. },
  70. 'click .js-archive-board'(evt) {
  71. const boardId = this.currentData()._id;
  72. Meteor.call('archiveBoard', boardId);
  73. evt.preventDefault();
  74. },
  75. 'click .js-accept-invite'() {
  76. const boardId = this.currentData()._id;
  77. Meteor.user().removeInvite(boardId);
  78. },
  79. 'click .js-decline-invite'() {
  80. const boardId = this.currentData()._id;
  81. Meteor.call('quitBoard', boardId, (err, ret) => {
  82. if (!err && ret) {
  83. Meteor.user().removeInvite(boardId);
  84. FlowRouter.go('home');
  85. }
  86. });
  87. },
  88. },
  89. ];
  90. },
  91. }).register('boardList');