cardDetails.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. BlazeComponent.extendComponent({
  2. template() {
  3. return 'cardDetails';
  4. },
  5. mixins() {
  6. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  7. },
  8. calculateNextPeak() {
  9. const altitude = this.find('.js-card-details').scrollHeight;
  10. this.callFirstWith(this, 'setNextPeak', altitude);
  11. },
  12. reachNextPeak() {
  13. const activitiesComponent = this.componentChildren('activities')[0];
  14. activitiesComponent.loadNextPage();
  15. },
  16. onCreated() {
  17. this.isLoaded = new ReactiveVar(false);
  18. this.componentParent().showOverlay.set(true);
  19. this.componentParent().mouseHasEnterCardDetails = false;
  20. },
  21. scrollParentContainer() {
  22. const cardPanelWidth = 510;
  23. const bodyBoardComponent = this.componentParent();
  24. const $cardContainer = bodyBoardComponent.$('.js-lists');
  25. const $cardView = this.$(this.firstNode());
  26. const cardContainerScroll = $cardContainer.scrollLeft();
  27. const cardContainerWidth = $cardContainer.width();
  28. const cardViewStart = $cardView.offset().left;
  29. const cardViewEnd = cardViewStart + cardPanelWidth;
  30. let offset = false;
  31. if (cardViewStart < 0) {
  32. offset = cardViewStart;
  33. } else if(cardViewEnd > cardContainerWidth) {
  34. offset = cardViewEnd - cardContainerWidth;
  35. }
  36. if (offset) {
  37. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  38. }
  39. },
  40. onRendered() {
  41. this.scrollParentContainer();
  42. },
  43. onDestroyed() {
  44. this.componentParent().showOverlay.set(false);
  45. },
  46. updateCard(modifier) {
  47. Cards.update(this.data()._id, {
  48. $set: modifier,
  49. });
  50. },
  51. events() {
  52. const events = {
  53. [`${CSSEvents.animationend} .js-card-details`]() {
  54. this.isLoaded.set(true);
  55. },
  56. };
  57. return [_.extend(events, {
  58. 'click .js-close-card-details'() {
  59. Utils.goBoardId(this.data().boardId);
  60. },
  61. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  62. 'submit .js-card-description'(evt) {
  63. evt.preventDefault();
  64. const description = this.currentComponent().getValue();
  65. this.updateCard({ description });
  66. },
  67. 'submit .js-card-details-title'(evt) {
  68. evt.preventDefault();
  69. const title = this.currentComponent().getValue();
  70. if ($.trim(title)) {
  71. this.updateCard({ title });
  72. }
  73. },
  74. 'click .js-member': Popup.open('cardMember'),
  75. 'click .js-add-members': Popup.open('cardMembers'),
  76. 'click .js-add-labels': Popup.open('cardLabels'),
  77. 'mouseenter .js-card-details'() {
  78. this.componentParent().showOverlay.set(true);
  79. this.componentParent().mouseHasEnterCardDetails = true;
  80. },
  81. })];
  82. },
  83. }).register('cardDetails');
  84. // We extends the normal InlinedForm component to support UnsavedEdits draft
  85. // feature.
  86. (class extends InlinedForm {
  87. _getUnsavedEditKey() {
  88. return {
  89. fieldName: 'cardDescription',
  90. docId: Session.get('currentCard'),
  91. };
  92. }
  93. close(isReset = false) {
  94. if (this.isOpen.get() && !isReset) {
  95. const draft = $.trim(this.getValue());
  96. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  97. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  98. }
  99. }
  100. super();
  101. }
  102. reset() {
  103. UnsavedEdits.reset(this._getUnsavedEditKey());
  104. this.close(true);
  105. }
  106. events() {
  107. const parentEvents = InlinedForm.prototype.events()[0];
  108. return [{
  109. ...parentEvents,
  110. 'click .js-close-inlined-form': this.reset,
  111. }];
  112. }
  113. }).register('inlinedCardDescription');
  114. Template.cardDetailsActionsPopup.events({
  115. 'click .js-members': Popup.open('cardMembers'),
  116. 'click .js-labels': Popup.open('cardLabels'),
  117. 'click .js-attachments': Popup.open('cardAttachments'),
  118. 'click .js-move-card': Popup.open('moveCard'),
  119. // 'click .js-copy': Popup.open(),
  120. 'click .js-archive'(evt) {
  121. evt.preventDefault();
  122. Cards.update(this._id, {
  123. $set: {
  124. archived: true,
  125. },
  126. });
  127. Popup.close();
  128. },
  129. 'click .js-more': Popup.open('cardMore'),
  130. });
  131. Template.moveCardPopup.events({
  132. 'click .js-select-list'() {
  133. // XXX We should *not* get the currentCard from the global state, but
  134. // instead from a “component” state.
  135. const cardId = Session.get('currentCard');
  136. const newListId = this._id;
  137. Cards.update(cardId, {
  138. $set: {
  139. listId: newListId,
  140. },
  141. });
  142. Popup.close();
  143. },
  144. });
  145. Template.cardMorePopup.events({
  146. 'click .js-delete': Popup.afterConfirm('cardDelete', () => {
  147. Popup.close();
  148. Cards.remove(this._id);
  149. Utils.goBoardId(this.board()._id);
  150. }),
  151. });
  152. // Close the card details pane by pressing escape
  153. EscapeActions.register('detailsPane',
  154. () => { Utils.goBoardId(Session.get('currentBoard')); },
  155. () => { return !Session.equals('currentCard', null); }, {
  156. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  157. }
  158. );