cardDetails.js 6.4 KB

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