2
0

cardDetails.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.transitionend} .js-card-details`]() {
  54. this.isLoaded.set(true);
  55. },
  56. [`${CSSEvents.animationend} .js-card-details`]() {
  57. this.isLoaded.set(true);
  58. },
  59. };
  60. return [{
  61. ...events,
  62. 'click .js-close-card-details'() {
  63. Utils.goBoardId(this.data().boardId);
  64. },
  65. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  66. 'submit .js-card-description'(evt) {
  67. evt.preventDefault();
  68. const description = this.currentComponent().getValue();
  69. this.data().setDescription(description);
  70. },
  71. 'submit .js-card-details-title'(evt) {
  72. evt.preventDefault();
  73. const title = this.currentComponent().getValue().trim();
  74. if (title) {
  75. this.data().setTitle(title);
  76. }
  77. },
  78. 'click .js-member': Popup.open('cardMember'),
  79. 'click .js-add-members': Popup.open('cardMembers'),
  80. 'click .js-add-labels': Popup.open('cardLabels'),
  81. 'mouseenter .js-card-details'() {
  82. this.parentComponent().showOverlay.set(true);
  83. this.parentComponent().mouseHasEnterCardDetails = true;
  84. },
  85. }];
  86. },
  87. }).register('cardDetails');
  88. // We extends the normal InlinedForm component to support UnsavedEdits draft
  89. // feature.
  90. (class extends InlinedForm {
  91. _getUnsavedEditKey() {
  92. return {
  93. fieldName: 'cardDescription',
  94. // XXX Recovering the currentCard identifier form a session variable is
  95. // fragile because this variable may change for instance if the route
  96. // change. We should use some component props instead.
  97. docId: Session.get('currentCard'),
  98. };
  99. }
  100. close(isReset = false) {
  101. if (this.isOpen.get() && !isReset) {
  102. const draft = this.getValue().trim();
  103. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  104. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  105. }
  106. }
  107. super.close();
  108. }
  109. reset() {
  110. UnsavedEdits.reset(this._getUnsavedEditKey());
  111. this.close(true);
  112. }
  113. events() {
  114. const parentEvents = InlinedForm.prototype.events()[0];
  115. return [{
  116. ...parentEvents,
  117. 'click .js-close-inlined-form': this.reset,
  118. }];
  119. }
  120. }).register('inlinedCardDescription');
  121. Template.cardDetailsActionsPopup.helpers({
  122. isWatching() {
  123. return this.findWatcher(Meteor.userId());
  124. },
  125. });
  126. Template.cardDetailsActionsPopup.events({
  127. 'click .js-members': Popup.open('cardMembers'),
  128. 'click .js-labels': Popup.open('cardLabels'),
  129. 'click .js-attachments': Popup.open('cardAttachments'),
  130. 'click .js-start-date': Popup.open('editCardStartDate'),
  131. 'click .js-due-date': Popup.open('editCardDueDate'),
  132. 'click .js-move-card': Popup.open('moveCard'),
  133. 'click .js-move-card-to-top'(evt) {
  134. evt.preventDefault();
  135. const minOrder = _.min(this.list().cards().map((c) => c.sort));
  136. this.move(this.listId, minOrder - 1);
  137. },
  138. 'click .js-move-card-to-bottom'(evt) {
  139. evt.preventDefault();
  140. const maxOrder = _.max(this.list().cards().map((c) => c.sort));
  141. this.move(this.listId, maxOrder + 1);
  142. },
  143. 'click .js-archive'(evt) {
  144. evt.preventDefault();
  145. this.archive();
  146. Popup.close();
  147. },
  148. 'click .js-more': Popup.open('cardMore'),
  149. 'click .js-toggle-watch-card'() {
  150. const currentCard = this;
  151. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  152. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  153. if (!err && ret) Popup.close();
  154. });
  155. },
  156. });
  157. Template.editCardTitleForm.onRendered(function() {
  158. autosize(this.$('.js-edit-card-title'));
  159. });
  160. Template.editCardTitleForm.events({
  161. 'keydown .js-edit-card-title'(evt) {
  162. // If enter key was pressed, submit the data
  163. if (evt.keyCode === 13) {
  164. $('.js-submit-edit-card-title-form').click();
  165. }
  166. },
  167. });
  168. Template.moveCardPopup.events({
  169. 'click .js-select-list'() {
  170. // XXX We should *not* get the currentCard from the global state, but
  171. // instead from a “component” state.
  172. const card = Cards.findOne(Session.get('currentCard'));
  173. const newListId = this._id;
  174. card.move(newListId);
  175. Popup.close();
  176. },
  177. });
  178. Template.cardMorePopup.events({
  179. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  180. Popup.close();
  181. Cards.remove(this._id);
  182. Utils.goBoardId(this.boardId);
  183. }),
  184. });
  185. // Close the card details pane by pressing escape
  186. EscapeActions.register('detailsPane',
  187. () => { Utils.goBoardId(Session.get('currentBoard')); },
  188. () => { return !Session.equals('currentCard', null); }, {
  189. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  190. }
  191. );