cardDetails.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. onRendered: function() {
  22. var bodyBoardComponent = this.componentParent();
  23. var additionalMargin = 550;
  24. var $cardDetails = this.$(this.firstNode());
  25. var scollLeft = $cardDetails.offset().left + additionalMargin;
  26. bodyBoardComponent.scrollLeft(scollLeft);
  27. },
  28. onDestroyed: function() {
  29. this.componentParent().showOverlay.set(false);
  30. },
  31. updateCard: function(modifier) {
  32. Cards.update(this.data()._id, {
  33. $set: modifier
  34. });
  35. },
  36. events: function() {
  37. var events = {
  38. [CSSEvents.animationend + ' .js-card-details']: function() {
  39. this.isLoaded.set(true);
  40. }
  41. };
  42. return [_.extend(events, {
  43. 'click .js-close-card-details': function() {
  44. Utils.goBoardId(this.data().boardId);
  45. },
  46. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  47. 'submit .js-card-description': function(evt) {
  48. evt.preventDefault();
  49. var description = this.currentComponent().getValue();
  50. this.updateCard({ description: description });
  51. },
  52. 'submit .js-card-details-title': function(evt) {
  53. evt.preventDefault();
  54. var title = this.currentComponent().getValue();
  55. if ($.trim(title)) {
  56. this.updateCard({ title: title });
  57. }
  58. },
  59. 'click .js-member': Popup.open('cardMember'),
  60. 'click .js-add-members': Popup.open('cardMembers'),
  61. 'click .js-add-labels': Popup.open('cardLabels'),
  62. 'mouseenter .js-card-details': function() {
  63. this.componentParent().showOverlay.set(true);
  64. this.componentParent().mouseHasEnterCardDetails = true;
  65. }
  66. })];
  67. }
  68. }).register('cardDetails');
  69. // We extends the normal InlinedForm component to support UnsavedEdits draft
  70. // feature.
  71. (class extends InlinedForm {
  72. _getUnsavedEditKey() {
  73. return {
  74. fieldName: 'cardDescription',
  75. docId: Session.get('currentCard'),
  76. }
  77. }
  78. close(isReset = false) {
  79. if (this.isOpen.get() && ! isReset) {
  80. let draft = $.trim(this.getValue());
  81. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  82. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  83. }
  84. }
  85. super();
  86. }
  87. reset() {
  88. UnsavedEdits.reset(this._getUnsavedEditKey());
  89. this.close(true);
  90. }
  91. events() {
  92. const parentEvents = InlinedForm.prototype.events()[0];
  93. return [{
  94. ...parentEvents,
  95. 'click .js-close-inlined-form': this.reset,
  96. }];
  97. }
  98. }).register('inlinedCardDescription');
  99. Template.cardDetailsActionsPopup.events({
  100. 'click .js-members': Popup.open('cardMembers'),
  101. 'click .js-labels': Popup.open('cardLabels'),
  102. 'click .js-attachments': Popup.open('cardAttachments'),
  103. 'click .js-move-card': Popup.open('moveCard'),
  104. // 'click .js-copy': Popup.open(),
  105. 'click .js-archive': function(evt) {
  106. evt.preventDefault();
  107. Cards.update(this._id, {
  108. $set: {
  109. archived: true
  110. }
  111. });
  112. Popup.close();
  113. },
  114. 'click .js-more': Popup.open('cardMore')
  115. });
  116. Template.moveCardPopup.events({
  117. 'click .js-select-list': function() {
  118. // XXX We should *not* get the currentCard from the global state, but
  119. // instead from a “component” state.
  120. var cardId = Session.get('currentCard');
  121. var newListId = this._id;
  122. Cards.update(cardId, {
  123. $set: {
  124. listId: newListId
  125. }
  126. });
  127. Popup.close();
  128. }
  129. });
  130. Template.cardMorePopup.events({
  131. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  132. Popup.close();
  133. Cards.remove(this._id);
  134. Utils.goBoardId(this.board()._id);
  135. })
  136. });
  137. // Close the card details pane by pressing escape
  138. EscapeActions.register('detailsPane',
  139. function() { Utils.goBoardId(Session.get('currentBoard')); },
  140. function() { return ! Session.equals('currentCard', null); }, {
  141. noClickEscapeOn: '.js-card-details,.board-sidebar,#header'
  142. }
  143. );