boardsList.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-accept-invite'() {
  66. const boardId = this.currentData()._id;
  67. Meteor.user().removeInvite(boardId);
  68. },
  69. 'click .js-decline-invite'() {
  70. const boardId = this.currentData()._id;
  71. Meteor.call('quitBoard', boardId, (err, ret) => {
  72. if (!err && ret) {
  73. Meteor.user().removeInvite(boardId);
  74. FlowRouter.go('home');
  75. }
  76. });
  77. },
  78. }];
  79. },
  80. }).register('boardList');