cardDetails.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. events() {
  47. const events = {
  48. [`${CSSEvents.animationend} .js-card-details`]() {
  49. this.isLoaded.set(true);
  50. },
  51. };
  52. return [_.extend(events, {
  53. 'click .js-close-card-details'() {
  54. Utils.goBoardId(this.data().boardId);
  55. },
  56. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  57. 'submit .js-card-description'(evt) {
  58. evt.preventDefault();
  59. const description = this.currentComponent().getValue();
  60. this.data().setDescription(description);
  61. },
  62. 'submit .js-card-details-title'(evt) {
  63. evt.preventDefault();
  64. const title = this.currentComponent().getValue();
  65. if ($.trim(title)) {
  66. this.data().setTitle(title);
  67. }
  68. },
  69. 'click .js-member': Popup.open('cardMember'),
  70. 'click .js-add-members': Popup.open('cardMembers'),
  71. 'click .js-add-labels': Popup.open('cardLabels'),
  72. 'mouseenter .js-card-details'() {
  73. this.componentParent().showOverlay.set(true);
  74. this.componentParent().mouseHasEnterCardDetails = true;
  75. },
  76. })];
  77. },
  78. }).register('cardDetails');
  79. // We extends the normal InlinedForm component to support UnsavedEdits draft
  80. // feature.
  81. (class extends InlinedForm {
  82. _getUnsavedEditKey() {
  83. return {
  84. fieldName: 'cardDescription',
  85. // XXX Recovering the currentCard identifier form a session variable is
  86. // fragile because this variable may change for instance if the route
  87. // change. We should use some component props instead.
  88. docId: Session.get('currentCard'),
  89. };
  90. }
  91. close(isReset = false) {
  92. if (this.isOpen.get() && !isReset) {
  93. const draft = $.trim(this.getValue());
  94. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  95. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  96. }
  97. }
  98. super();
  99. }
  100. reset() {
  101. UnsavedEdits.reset(this._getUnsavedEditKey());
  102. this.close(true);
  103. }
  104. events() {
  105. const parentEvents = InlinedForm.prototype.events()[0];
  106. return [{
  107. ...parentEvents,
  108. 'click .js-close-inlined-form': this.reset,
  109. }];
  110. }
  111. }).register('inlinedCardDescription');
  112. Template.cardDetailsActionsPopup.events({
  113. 'click .js-members': Popup.open('cardMembers'),
  114. 'click .js-labels': Popup.open('cardLabels'),
  115. 'click .js-attachments': Popup.open('cardAttachments'),
  116. 'click .js-move-card': Popup.open('moveCard'),
  117. 'click .js-archive'(evt) {
  118. evt.preventDefault();
  119. this.archive();
  120. Popup.close();
  121. },
  122. 'click .js-more': Popup.open('cardMore'),
  123. });
  124. Template.moveCardPopup.events({
  125. 'click .js-select-list'() {
  126. // XXX We should *not* get the currentCard from the global state, but
  127. // instead from a “component” state.
  128. const card = Cards.findOne(Session.get('currentCard'));
  129. const newListId = this._id;
  130. card.move(newListId);
  131. Popup.close();
  132. },
  133. });
  134. Template.cardMorePopup.events({
  135. 'click .js-delete': Popup.afterConfirm('cardDelete', () => {
  136. Popup.close();
  137. Cards.remove(this._id);
  138. Utils.goBoardId(this.board()._id);
  139. }),
  140. });
  141. // Close the card details pane by pressing escape
  142. EscapeActions.register('detailsPane',
  143. () => { Utils.goBoardId(Session.get('currentBoard')); },
  144. () => { return !Session.equals('currentCard', null); }, {
  145. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  146. }
  147. );