boardsList.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. type: 'board',
  83. };
  84. if (FlowRouter.getRouteName() === 'home')
  85. query['members.userId'] = Meteor.userId();
  86. else query.permission = 'public';
  87. return Boards.find(query, {
  88. sort: { sort: 1 /* boards default sorting */ },
  89. });
  90. },
  91. isStarred() {
  92. const user = Meteor.user();
  93. return user && user.hasStarred(this.currentData()._id);
  94. },
  95. isAdministrable() {
  96. const user = Meteor.user();
  97. return user && user.isBoardAdmin(this.currentData()._id);
  98. },
  99. hasOvertimeCards() {
  100. subManager.subscribe('board', this.currentData()._id, false);
  101. return this.currentData().hasOvertimeCards();
  102. },
  103. hasSpentTimeCards() {
  104. subManager.subscribe('board', this.currentData()._id, false);
  105. return this.currentData().hasSpentTimeCards();
  106. },
  107. isInvited() {
  108. const user = Meteor.user();
  109. return user && user.isInvitedTo(this.currentData()._id);
  110. },
  111. events() {
  112. return [
  113. {
  114. 'click .js-add-board': Popup.open('createBoard'),
  115. 'click .js-star-board'(evt) {
  116. const boardId = this.currentData()._id;
  117. Meteor.user().toggleBoardStar(boardId);
  118. evt.preventDefault();
  119. },
  120. 'click .js-clone-board'(evt) {
  121. Meteor.call(
  122. 'copyBoard',
  123. this.currentData()._id,
  124. {
  125. sort: Boards.find({ archived: false }).count(),
  126. type: 'board',
  127. title: Boards.findOne(this.currentData()._id).title,
  128. },
  129. (err, res) => {
  130. if (err) {
  131. this.setError(err.error);
  132. } else {
  133. Session.set('fromBoard', null);
  134. Utils.goBoardId(res);
  135. }
  136. },
  137. );
  138. evt.preventDefault();
  139. },
  140. 'click .js-archive-board'(evt) {
  141. const boardId = this.currentData()._id;
  142. Meteor.call('archiveBoard', boardId);
  143. evt.preventDefault();
  144. },
  145. 'click .js-accept-invite'() {
  146. const boardId = this.currentData()._id;
  147. Meteor.call('acceptInvite', boardId);
  148. },
  149. 'click .js-decline-invite'() {
  150. const boardId = this.currentData()._id;
  151. Meteor.call('quitBoard', boardId, (err, ret) => {
  152. if (!err && ret) {
  153. Meteor.call('acceptInvite', boardId);
  154. FlowRouter.go('home');
  155. }
  156. });
  157. },
  158. },
  159. ];
  160. },
  161. }).register('boardList');