summaryrefslogtreecommitdiffstats
path: root/client/components/cards/details.js
blob: d44adb6705a9cf4e0ea10a7f330ea38955b60d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
BlazeComponent.extendComponent({
  template: function() {
    return 'cardDetails';
  },

  mixins: function() {
    return [Mixins.InfiniteScrolling];
  },

  calculateNextPeak: function() {
    var altitude = this.find('.js-card-details').scrollHeight;
    this.callFirstWith(this, 'setNextPeak', altitude);
  },

  reachNextPeak: function() {
    var activitiesComponent = this.componentChildren('activities')[0];
    activitiesComponent.loadNextPage();
  },

  onRendered: function() {
    var bodyBoardComponent = this.componentParent();
    var additionalMargin = 550;
    var $cardDetails = this.$(this.firstNode());
    var scollLeft = $cardDetails.offset().left + additionalMargin;
    bodyBoardComponent.scrollLeft(scollLeft);
  },

  onDestroyed: function() {
    this.componentParent().showOverlay.set(false);
  },

  updateCard: function(modifier) {
    Cards.update(this.data()._id, {
      $set: modifier
    });
  },

  events: function() {
    return [{
      'click .js-close-card-details': function() {
        Utils.goBoardId(this.data().boardId);
      },
      'click .js-move-card': Popup.open('moveCard'),
      'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
      'submit .js-card-description': function(evt) {
        evt.preventDefault();
        var description = this.currentComponent().getValue();
        this.updateCard({ description: description });
      },
      'submit .js-card-details-title': function(evt) {
        evt.preventDefault();
        var title = this.currentComponent().getValue();
        if ($.trim(title)) {
          this.updateCard({ title: title });
        }
      },
      'click .js-member': Popup.open('cardMember'),
      'click .js-add-members': Popup.open('cardMembers'),
      'click .js-add-labels': Popup.open('cardLabels'),
      'mouseenter .js-card-details': function() {
        this.componentParent().showOverlay.set(true);
      },
      'mouseleave .js-card-details': function(evt) {
        // We don't want to hide the overlay if the mouse is entering a pop-over
        var $pointedElement = $(evt.toElement || evt.relatedTarget);
        if ($pointedElement.closest('.pop-over').length === 0)
          this.componentParent().showOverlay.set(false);
      }
    }];
  }
}).register('cardDetails');

Template.cardDetailsActionsPopup.events({
  'click .js-members': Popup.open('cardMembers'),
  'click .js-labels': Popup.open('cardLabels'),
  'click .js-attachments': Popup.open('cardAttachments'),
  // 'click .js-copy': Popup.open(),
  'click .js-archive': function(evt) {
    evt.preventDefault();
    Cards.update(this._id, {
      $set: {
        archived: true
      }
    });
    Popup.close();
  }
});

Template.moveCardPopup.events({
  'click .js-select-list': function() {
    // XXX We should *not* get the currentCard from the global state, but
    // instead from a “component” state.
    var cardId = Session.get('currentCard');
    var newListId = this._id;
    Cards.update(cardId, {
      $set: {
        listId: newListId
      }
    });
    Popup.close();
  }
});