cardDetails.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // XXX Obviously this shouldn't be a global, but this is currently the only way
  2. // to share a variable between two files.
  3. BlazeComponent.extendComponent({
  4. template: function() {
  5. return 'cardDetails';
  6. },
  7. mixins: function() {
  8. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  9. },
  10. calculateNextPeak: function() {
  11. var altitude = this.find('.js-card-details').scrollHeight;
  12. this.callFirstWith(this, 'setNextPeak', altitude);
  13. },
  14. reachNextPeak: function() {
  15. var activitiesComponent = this.componentChildren('activities')[0];
  16. activitiesComponent.loadNextPage();
  17. },
  18. onCreated: function() {
  19. this.isLoaded = new ReactiveVar(false);
  20. this.componentParent().showOverlay.set(true);
  21. this.componentParent().mouseHasEnterCardDetails = false;
  22. },
  23. onRendered: function() {
  24. var bodyBoardComponent = this.componentParent();
  25. var additionalMargin = 550;
  26. var $cardDetails = this.$(this.firstNode());
  27. var scollLeft = $cardDetails.offset().left + additionalMargin;
  28. bodyBoardComponent.scrollLeft(scollLeft);
  29. },
  30. onDestroyed: function() {
  31. this.componentParent().showOverlay.set(false);
  32. },
  33. updateCard: function(modifier) {
  34. Cards.update(this.data()._id, {
  35. $set: modifier
  36. });
  37. },
  38. events: function() {
  39. var events = {
  40. [CSSEvents.animationend + ' .js-card-details']: function() {
  41. this.isLoaded.set(true);
  42. }
  43. };
  44. return [_.extend(events, {
  45. 'click .js-close-card-details': function() {
  46. Utils.goBoardId(this.data().boardId);
  47. },
  48. 'click .js-move-card': Popup.open('moveCard'),
  49. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  50. 'submit .js-card-description': function(evt) {
  51. evt.preventDefault();
  52. var description = this.currentComponent().getValue();
  53. this.updateCard({ description: description });
  54. },
  55. 'submit .js-card-details-title': function(evt) {
  56. evt.preventDefault();
  57. var title = this.currentComponent().getValue();
  58. if ($.trim(title)) {
  59. this.updateCard({ title: title });
  60. }
  61. },
  62. 'click .js-member': Popup.open('cardMember'),
  63. 'click .js-add-members': Popup.open('cardMembers'),
  64. 'click .js-add-labels': Popup.open('cardLabels'),
  65. 'mouseenter .js-card-details': function() {
  66. this.componentParent().showOverlay.set(true);
  67. this.componentParent().mouseHasEnterCardDetails = true;
  68. }
  69. })];
  70. }
  71. }).register('cardDetails');
  72. Template.cardDetailsActionsPopup.events({
  73. 'click .js-members': Popup.open('cardMembers'),
  74. 'click .js-labels': Popup.open('cardLabels'),
  75. 'click .js-attachments': Popup.open('cardAttachments'),
  76. // 'click .js-copy': Popup.open(),
  77. 'click .js-archive': function(evt) {
  78. evt.preventDefault();
  79. Cards.update(this._id, {
  80. $set: {
  81. archived: true
  82. }
  83. });
  84. Popup.close();
  85. },
  86. 'click .js-more': Popup.open('cardMore')
  87. });
  88. Template.moveCardPopup.events({
  89. 'click .js-select-list': function() {
  90. // XXX We should *not* get the currentCard from the global state, but
  91. // instead from a “component” state.
  92. var cardId = Session.get('currentCard');
  93. var newListId = this._id;
  94. Cards.update(cardId, {
  95. $set: {
  96. listId: newListId
  97. }
  98. });
  99. Popup.close();
  100. }
  101. });
  102. Template.cardMorePopup.events({
  103. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  104. Popup.close();
  105. Cards.remove(this._id);
  106. Utils.goBoardId(this.board()._id);
  107. })
  108. });
  109. // Close the card details pane by pressing escape
  110. EscapeActions.register('detailsPane',
  111. function() { Utils.goBoardId(Session.get('currentBoard')); },
  112. function() { return ! Session.equals('currentCard', null); }, {
  113. noClickEscapeOn: '.js-card-details,.board-sidebar,#header'
  114. }
  115. );