cardDetails.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'cardDetails';
  4. },
  5. mixins: function() {
  6. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  7. },
  8. calculateNextPeak: function() {
  9. var altitude = this.find('.js-card-details').scrollHeight;
  10. this.callFirstWith(this, 'setNextPeak', altitude);
  11. },
  12. reachNextPeak: function() {
  13. var activitiesComponent = this.componentChildren('activities')[0];
  14. activitiesComponent.loadNextPage();
  15. },
  16. onCreated: function() {
  17. this.isLoaded = new ReactiveVar(false);
  18. this.componentParent().showOverlay.set(true);
  19. this.componentParent().mouseHasEnterCardDetails = false;
  20. },
  21. scrollParentContainer: function() {
  22. const cardPanelWidth = 510;
  23. let bodyBoardComponent = this.componentParent();
  24. let $cardContainer = bodyBoardComponent.$('.js-lists');
  25. let $cardView = this.$(this.firstNode());
  26. let cardContainerScroll = $cardContainer.scrollLeft();
  27. let cardContainerWidth = $cardContainer.width();
  28. let cardViewStart = $cardView.offset().left;
  29. let 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: function() {
  41. this.scrollParentContainer();
  42. },
  43. onDestroyed: function() {
  44. this.componentParent().showOverlay.set(false);
  45. },
  46. updateCard: function(modifier) {
  47. Cards.update(this.data()._id, {
  48. $set: modifier
  49. });
  50. },
  51. events: function() {
  52. var events = {
  53. [CSSEvents.animationend + ' .js-card-details']: function() {
  54. this.isLoaded.set(true);
  55. }
  56. };
  57. return [_.extend(events, {
  58. 'click .js-close-card-details': function() {
  59. Utils.goBoardId(this.data().boardId);
  60. },
  61. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  62. 'submit .js-card-description': function(evt) {
  63. evt.preventDefault();
  64. var description = this.currentComponent().getValue();
  65. this.updateCard({ description: description });
  66. },
  67. 'submit .js-card-details-title': function(evt) {
  68. evt.preventDefault();
  69. var title = this.currentComponent().getValue();
  70. if ($.trim(title)) {
  71. this.updateCard({ title: 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': function() {
  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. let 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': function(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': function() {
  133. // XXX We should *not* get the currentCard from the global state, but
  134. // instead from a “component” state.
  135. var cardId = Session.get('currentCard');
  136. var 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', function() {
  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. function() { Utils.goBoardId(Session.get('currentBoard')); },
  155. function() { return ! Session.equals('currentCard', null); }, {
  156. noClickEscapeOn: '.js-card-details,.board-sidebar,#header'
  157. }
  158. );