cardDetails.js 4.8 KB

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