boardsList.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. const subManager = new SubsManager();
  2. const { calculateIndex, enableClickOnTouch } = Utils;
  3. Template.boardListHeaderBar.events({
  4. 'click .js-open-archived-board'() {
  5. Modal.open('archivedBoards');
  6. },
  7. });
  8. Template.boardListHeaderBar.helpers({
  9. title() {
  10. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  11. },
  12. templatesBoardId() {
  13. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  14. },
  15. templatesBoardSlug() {
  16. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  17. },
  18. });
  19. BlazeComponent.extendComponent({
  20. onCreated() {
  21. Meteor.subscribe('setting');
  22. let currUser = Meteor.user();
  23. let userLanguage;
  24. if(currUser && currUser.profile){
  25. userLanguage = currUser.profile.language
  26. }
  27. if (userLanguage) {
  28. TAPi18n.setLanguage(userLanguage);
  29. T9n.setLanguage(userLanguage);
  30. }
  31. },
  32. onRendered() {
  33. const itemsSelector = '.js-board:not(.placeholder)';
  34. const $boards = this.$('.js-boards');
  35. $boards.sortable({
  36. connectWith: '.js-boards',
  37. tolerance: 'pointer',
  38. appendTo: '.board-list',
  39. helper: 'clone',
  40. distance: 7,
  41. items: itemsSelector,
  42. placeholder: 'board-wrapper placeholder',
  43. start(evt, ui) {
  44. ui.helper.css('z-index', 1000);
  45. ui.placeholder.height(ui.helper.height());
  46. EscapeActions.executeUpTo('popup-close');
  47. },
  48. stop(evt, ui) {
  49. // To attribute the new index number, we need to get the DOM element
  50. // of the previous and the following card -- if any.
  51. const prevBoardDom = ui.item.prev('.js-board').get(0);
  52. const nextBoardBom = ui.item.next('.js-board').get(0);
  53. const sortIndex = calculateIndex(prevBoardDom, nextBoardBom, 1);
  54. const boardDomElement = ui.item.get(0);
  55. const board = Blaze.getData(boardDomElement);
  56. // Normally the jquery-ui sortable library moves the dragged DOM element
  57. // to its new position, which disrupts Blaze reactive updates mechanism
  58. // (especially when we move the last card of a list, or when multiple
  59. // users move some cards at the same time). To prevent these UX glitches
  60. // we ask sortable to gracefully cancel the move, and to put back the
  61. // DOM in its initial state. The card move is then handled reactively by
  62. // Blaze with the below query.
  63. $boards.sortable('cancel');
  64. board.move(sortIndex.base);
  65. },
  66. });
  67. // ugly touch event hotfix
  68. enableClickOnTouch(itemsSelector);
  69. // Disable drag-dropping if the current user is not a board member or is comment only
  70. this.autorun(() => {
  71. if (Utils.isMiniScreen()) {
  72. $boards.sortable({
  73. handle: '.board-handle',
  74. });
  75. }
  76. });
  77. },
  78. boards() {
  79. const query = {
  80. archived: false,
  81. type: { $in: ['board','template-container'] },
  82. };
  83. if (FlowRouter.getRouteName() === 'home')
  84. query['members.userId'] = Meteor.userId();
  85. else query.permission = 'public';
  86. return Boards.find(query, {
  87. sort: { sort: 1 /* boards default sorting */ },
  88. });
  89. },
  90. isStarred() {
  91. const user = Meteor.user();
  92. return user && user.hasStarred(this.currentData()._id);
  93. },
  94. isAdministrable() {
  95. const user = Meteor.user();
  96. return user && user.isBoardAdmin(this.currentData()._id);
  97. },
  98. hasOvertimeCards() {
  99. subManager.subscribe('board', this.currentData()._id, false);
  100. return this.currentData().hasOvertimeCards();
  101. },
  102. hasSpentTimeCards() {
  103. subManager.subscribe('board', this.currentData()._id, false);
  104. return this.currentData().hasSpentTimeCards();
  105. },
  106. isInvited() {
  107. const user = Meteor.user();
  108. return user && user.isInvitedTo(this.currentData()._id);
  109. },
  110. events() {
  111. return [
  112. {
  113. 'click .js-add-board': Popup.open('createBoard'),
  114. 'click .js-star-board'(evt) {
  115. const boardId = this.currentData()._id;
  116. Meteor.user().toggleBoardStar(boardId);
  117. evt.preventDefault();
  118. },
  119. 'click .js-clone-board'(evt) {
  120. Meteor.call(
  121. 'copyBoard',
  122. this.currentData()._id,
  123. {
  124. sort: Boards.find({ archived: false }).count(),
  125. type: 'board',
  126. title: Boards.findOne(this.currentData()._id).title,
  127. },
  128. (err, res) => {
  129. if (err) {
  130. this.setError(err.error);
  131. } else {
  132. Session.set('fromBoard', null);
  133. Utils.goBoardId(res);
  134. }
  135. },
  136. );
  137. evt.preventDefault();
  138. },
  139. 'click .js-archive-board'(evt) {
  140. const boardId = this.currentData()._id;
  141. Meteor.call('archiveBoard', boardId);
  142. evt.preventDefault();
  143. },
  144. 'click .js-accept-invite'() {
  145. const boardId = this.currentData()._id;
  146. Meteor.call('acceptInvite', boardId);
  147. },
  148. 'click .js-decline-invite'() {
  149. const boardId = this.currentData()._id;
  150. Meteor.call('quitBoard', boardId, (err, ret) => {
  151. if (!err && ret) {
  152. Meteor.call('acceptInvite', boardId);
  153. FlowRouter.go('home');
  154. }
  155. });
  156. },
  157. },
  158. ];
  159. },
  160. }).register('boardList');