summaryrefslogtreecommitdiffstats
path: root/client/components/cards/cardTime.js
blob: 80b7fc84b6a1e3c8cff2b9b33172a70c88f15e29 (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
BlazeComponent.extendComponent({
  template() {
    return 'editCardSpentTime';
  },
  onCreated() {
    this.error = new ReactiveVar('');
    this.card = this.data();
  },
  toggleOvertime() {
    this.card.setIsOvertime(!this.card.getIsOvertime());
    $('#overtime .materialCheckBox').toggleClass('is-checked');

    $('#overtime').toggleClass('is-checked');
  },
  storeTime(spentTime, isOvertime) {
    this.card.setSpentTime(spentTime);
    this.card.setIsOvertime(isOvertime);
  },
  deleteTime() {
    this.card.setSpentTime(null);
  },
  events() {
    return [{
      //TODO : need checking this portion
      'submit .edit-time'(evt) {
        evt.preventDefault();

        const spentTime = parseFloat(evt.target.time.value);
        const isOvertime = this.card.getIsOvertime();

        if (spentTime >= 0) {
          this.storeTime(spentTime, isOvertime);
          Popup.close();
        } else {
          this.error.set('invalid-time');
          evt.target.time.focus();
        }
      },
      'click .js-delete-time'(evt) {
        evt.preventDefault();
        this.deleteTime();
        Popup.close();
      },
      'click a.js-toggle-overtime': this.toggleOvertime,
    }];
  },
}).register('editCardSpentTimePopup');

BlazeComponent.extendComponent({
  template() {
    return 'timeBadge';
  },
  onCreated() {
    const self = this;
    self.time = ReactiveVar();
  },
  showTitle() {
    if (this.data().getIsOvertime()) {
      return `${TAPi18n.__('overtime')} ${this.data().getSpentTime()} ${TAPi18n.__('hours')}`;
    } else {
      return `${TAPi18n.__('card-spent')} ${this.data().getSpentTime()} ${TAPi18n.__('hours')}`;
    }
  },
  showTime() {
    return this.data().getSpentTime();
  },
  events() {
    return [{
      'click .js-edit-time': Popup.open('editCardSpentTime'),
    }];
  },
}).register('cardSpentTime');

Template.timeBadge.helpers({
  canModifyCard() {
    return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  },
});