cardDetails.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. BlazeComponent.extendComponent({
  2. mixins() {
  3. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  4. },
  5. calculateNextPeak() {
  6. const cardElement = this.find('.js-card-details');
  7. if (cardElement) {
  8. const altitude = cardElement.scrollHeight;
  9. this.callFirstWith(this, 'setNextPeak', altitude);
  10. }
  11. },
  12. reachNextPeak() {
  13. const activitiesComponent = this.childComponents('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. this.calculateNextPeak();
  21. },
  22. isWatching() {
  23. const card = this.currentData();
  24. return card.findWatcher(Meteor.userId());
  25. },
  26. scrollParentContainer() {
  27. const cardPanelWidth = 510;
  28. const bodyBoardComponent = this.parentComponent();
  29. const $cardContainer = bodyBoardComponent.$('.js-lists');
  30. const $cardView = this.$(this.firstNode());
  31. const cardContainerScroll = $cardContainer.scrollLeft();
  32. const cardContainerWidth = $cardContainer.width();
  33. const cardViewStart = $cardView.offset().left;
  34. const cardViewEnd = cardViewStart + cardPanelWidth;
  35. let offset = false;
  36. if (cardViewStart < 0) {
  37. offset = cardViewStart;
  38. } else if(cardViewEnd > cardContainerWidth) {
  39. offset = cardViewEnd - cardContainerWidth;
  40. }
  41. if (offset) {
  42. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  43. }
  44. },
  45. onRendered() {
  46. if (!Utils.isMiniScreen()) this.scrollParentContainer();
  47. },
  48. onDestroyed() {
  49. this.parentComponent().showOverlay.set(false);
  50. },
  51. events() {
  52. const events = {
  53. [`${CSSEvents.animationend} .js-card-details`]() {
  54. this.isLoaded.set(true);
  55. },
  56. };
  57. return [{
  58. ...events,
  59. 'click .js-close-card-details'() {
  60. Utils.goBoardId(this.data().boardId);
  61. },
  62. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  63. 'submit .js-card-description'(evt) {
  64. evt.preventDefault();
  65. const description = this.currentComponent().getValue();
  66. this.data().setDescription(description);
  67. },
  68. 'submit .js-card-details-title'(evt) {
  69. evt.preventDefault();
  70. const title = this.currentComponent().getValue().trim();
  71. if (title) {
  72. this.data().setTitle(title);
  73. }
  74. },
  75. 'click .js-member': Popup.open('cardMember'),
  76. 'click .js-add-members': Popup.open('cardMembers'),
  77. 'click .js-add-labels': Popup.open('cardLabels'),
  78. 'mouseenter .js-card-details'() {
  79. this.parentComponent().showOverlay.set(true);
  80. this.parentComponent().mouseHasEnterCardDetails = true;
  81. },
  82. }];
  83. },
  84. }).register('cardDetails');
  85. // We extends the normal InlinedForm component to support UnsavedEdits draft
  86. // feature.
  87. (class extends InlinedForm {
  88. _getUnsavedEditKey() {
  89. return {
  90. fieldName: 'cardDescription',
  91. // XXX Recovering the currentCard identifier form a session variable is
  92. // fragile because this variable may change for instance if the route
  93. // change. We should use some component props instead.
  94. docId: Session.get('currentCard'),
  95. };
  96. }
  97. close(isReset = false) {
  98. if (this.isOpen.get() && !isReset) {
  99. const draft = this.getValue().trim();
  100. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  101. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  102. }
  103. }
  104. super.close();
  105. }
  106. reset() {
  107. UnsavedEdits.reset(this._getUnsavedEditKey());
  108. this.close(true);
  109. }
  110. events() {
  111. const parentEvents = InlinedForm.prototype.events()[0];
  112. return [{
  113. ...parentEvents,
  114. 'click .js-close-inlined-form': this.reset,
  115. }];
  116. }
  117. }).register('inlinedCardDescription');
  118. Template.cardDetailsActionsPopup.helpers({
  119. isWatching() {
  120. return this.findWatcher(Meteor.userId());
  121. },
  122. });
  123. Template.cardDetailsActionsPopup.events({
  124. 'click .js-members': Popup.open('cardMembers'),
  125. 'click .js-labels': Popup.open('cardLabels'),
  126. 'click .js-attachments': Popup.open('cardAttachments'),
  127. 'click .js-move-card': Popup.open('moveCard'),
  128. 'click .js-move-card-to-top'(evt) {
  129. evt.preventDefault();
  130. const minOrder = _.min(this.list().cards().map((c) => c.sort));
  131. this.move(this.listId, minOrder / 2);
  132. },
  133. 'click .js-move-card-to-bottom'(evt) {
  134. evt.preventDefault();
  135. const maxOrder = _.max(this.list().cards().map((c) => c.sort));
  136. this.move(this.listId, Math.floor(maxOrder) + 1);
  137. },
  138. 'click .js-archive'(evt) {
  139. evt.preventDefault();
  140. this.archive();
  141. Popup.close();
  142. },
  143. 'click .js-more': Popup.open('cardMore'),
  144. 'click .js-toggle-watch-card'() {
  145. const currentCard = this;
  146. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  147. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  148. if (!err && ret) Popup.close();
  149. });
  150. },
  151. });
  152. Template.editCardTitleForm.onRendered(function() {
  153. autosize(this.$('.js-edit-card-title'));
  154. });
  155. Template.editCardTitleForm.events({
  156. 'keydown .js-edit-card-title'(evt) {
  157. // If enter key was pressed, submit the data
  158. if (evt.keyCode === 13) {
  159. $('.js-submit-edit-card-title-form').click();
  160. }
  161. },
  162. });
  163. Template.moveCardPopup.events({
  164. 'click .js-select-list'() {
  165. // XXX We should *not* get the currentCard from the global state, but
  166. // instead from a “component” state.
  167. const card = Cards.findOne(Session.get('currentCard'));
  168. const newListId = this._id;
  169. card.move(newListId);
  170. Popup.close();
  171. },
  172. });
  173. Template.cardMorePopup.events({
  174. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  175. Popup.close();
  176. Cards.remove(this._id);
  177. Utils.goBoardId(this.boardId);
  178. }),
  179. });
  180. // Close the card details pane by pressing escape
  181. EscapeActions.register('detailsPane',
  182. () => { Utils.goBoardId(Session.get('currentBoard')); },
  183. () => { return !Session.equals('currentCard', null); }, {
  184. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  185. }
  186. );