boardsList.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. archived: false,
  22. 'members.userId': Meteor.userId(),
  23. type: 'board',
  24. }, { sort: ['title'] });
  25. },
  26. isStarred() {
  27. const user = Meteor.user();
  28. return user && user.hasStarred(this.currentData()._id);
  29. },
  30. hasOvertimeCards() {
  31. subManager.subscribe('board', this.currentData()._id);
  32. return this.currentData().hasOvertimeCards();
  33. },
  34. hasSpentTimeCards() {
  35. subManager.subscribe('board', this.currentData()._id);
  36. return this.currentData().hasSpentTimeCards();
  37. },
  38. isInvited() {
  39. const user = Meteor.user();
  40. return user && user.isInvitedTo(this.currentData()._id);
  41. },
  42. events() {
  43. return [{
  44. 'click .js-add-board': Popup.open('createBoard'),
  45. 'click .js-star-board'(evt) {
  46. const boardId = this.currentData()._id;
  47. Meteor.user().toggleBoardStar(boardId);
  48. evt.preventDefault();
  49. },
  50. 'click .js-clone-board'(evt) {
  51. Meteor.call('cloneBoard',
  52. this.currentData()._id,
  53. Session.get('fromBoard'),
  54. (err, res) => {
  55. if (err) {
  56. this.setError(err.error);
  57. } else {
  58. Session.set('fromBoard', null);
  59. Utils.goBoardId(res);
  60. }
  61. }
  62. );
  63. evt.preventDefault();
  64. },
  65. 'click .js-archive-board'(evt) {
  66. const boardId = this.currentData()._id;
  67. Meteor.call('archiveBoard', boardId);
  68. evt.preventDefault();
  69. },
  70. 'click .js-accept-invite'() {
  71. const boardId = this.currentData()._id;
  72. Meteor.user().removeInvite(boardId);
  73. },
  74. 'click .js-decline-invite'() {
  75. const boardId = this.currentData()._id;
  76. Meteor.call('quitBoard', boardId, (err, ret) => {
  77. if (!err && ret) {
  78. Meteor.user().removeInvite(boardId);
  79. FlowRouter.go('home');
  80. }
  81. });
  82. },
  83. }];
  84. },
  85. }).register('boardList');