details.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'cardDetails';
  4. },
  5. mixins: function() {
  6. return [Mixins.InfiniteScrolling];
  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. onRendered: function() {
  17. var bodyBoardComponent = this.componentParent();
  18. var additionalMargin = 550;
  19. var $cardDetails = this.$(this.firstNode());
  20. var scollLeft = $cardDetails.offset().left + additionalMargin;
  21. bodyBoardComponent.scrollLeft(scollLeft);
  22. },
  23. onDestroyed: function() {
  24. this.componentParent().showOverlay.set(false);
  25. },
  26. updateCard: function(modifier) {
  27. Cards.update(this.data()._id, {
  28. $set: modifier
  29. });
  30. },
  31. events: function() {
  32. return [{
  33. 'click .js-close-card-details': function() {
  34. Utils.goBoardId(this.data().boardId);
  35. },
  36. 'click .js-move-card': Popup.open('moveCard'),
  37. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  38. 'submit .js-card-description': function(evt) {
  39. evt.preventDefault();
  40. var description = this.currentComponent().getValue();
  41. this.updateCard({ description: description });
  42. },
  43. 'submit .js-card-details-title': function(evt) {
  44. evt.preventDefault();
  45. var title = this.currentComponent().getValue();
  46. if ($.trim(title)) {
  47. this.updateCard({ title: title });
  48. }
  49. },
  50. 'click .js-member': Popup.open('cardMember'),
  51. 'click .js-add-members': Popup.open('cardMembers'),
  52. 'click .js-add-labels': Popup.open('cardLabels'),
  53. 'mouseenter .js-card-details': function() {
  54. this.componentParent().showOverlay.set(true);
  55. },
  56. 'mouseleave .js-card-details': function(evt) {
  57. // We don't want to hide the overlay if the mouse is entering a pop-over
  58. var $pointedElement = $(evt.toElement || evt.relatedTarget);
  59. if ($pointedElement.closest('.pop-over').length === 0)
  60. this.componentParent().showOverlay.set(false);
  61. }
  62. }];
  63. }
  64. }).register('cardDetails');
  65. Template.cardDetailsActionsPopup.events({
  66. 'click .js-members': Popup.open('cardMembers'),
  67. 'click .js-labels': Popup.open('cardLabels'),
  68. 'click .js-attachments': Popup.open('cardAttachments'),
  69. // 'click .js-copy': Popup.open(),
  70. 'click .js-archive': function(evt) {
  71. evt.preventDefault();
  72. Cards.update(this._id, {
  73. $set: {
  74. archived: true
  75. }
  76. });
  77. Popup.close();
  78. }
  79. });
  80. Template.moveCardPopup.events({
  81. 'click .js-select-list': function() {
  82. // XXX We should *not* get the currentCard from the global state, but
  83. // instead from a “component” state.
  84. var cardId = Session.get('currentCard');
  85. var newListId = this._id;
  86. Cards.update(cardId, {
  87. $set: {
  88. listId: newListId
  89. }
  90. });
  91. Popup.close();
  92. }
  93. });