forked from jgraglia/Trello-Points
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.js
130 lines (121 loc) · 3.52 KB
/
card.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function Card($cardElement, debug) {
var $card = $cardElement;
if ($card == undefined || !$card.jquery) throw new Error("JQuery element required");
var $title = $card.find('a.list-card-title');
var that = this;
var log = function(message) {
tp.utils.log("Card", message);
};
function extractPoints(text) {
var parsed = parser.parsePoints(text);
if( $.isArray(parsed) && parsed.length==2)return parsed[1];
else return null;
};
this.computePoints= function() {
if(!$title[0]) {
// When you drag a card, she seems to lost her title..No need
// to broke extension, return null points is ok.
//utils.alertBrokenAPI("Card has no title. Check Trello structure");
return null;
}
var title=$title[0].text;
if (debug)log("Title is: "+title);
var points=extractPoints($title[0].otitle||title);
if (debug) log("extractPoints returns: "+points+" from "+title+" with "+parser);
return points;
};
this.removeBadge=function() {
if (this.containsBadge()) {
$card.find('.badge-points').remove();
}
};
this.containsBadge = function(){
if ($card.find('.badge-points').length==1) return true;
else return false;
};
function lookupExistingBadge (){
return $($card.find('.badge-points')[0]);
};
function ensureBadgeExists (){
if (that.containsBadge()) {
if (debug) log("previous badge found");
return lookupExistingBadge();
} else {
$badge = $('<span class="badge badge-points point-count" style="background-image: url('+iconUrl+')">');
if ($card.parent()[0]){
if (debug) log("appending Trello Scrum badge");
$badges = $card.find('.badges');
if ($badges.length!=1){
utils.alertBrokenAPI("Badges container missing in card structure");
}
$badge.prependTo($badges);
return $badge;
} else {
utils.alertBrokenAPI("Cards container missing in Trello structure");
}
}
};
this.updateBadge=function (cardPoints) {
var $badge = ensureBadgeExists();
if (debug) log("updating badge text");
$badge.text(cardPoints);
if (cardPoints >0 ) {
$badge.addClass("positive-points");
$badge.removeClass("negative-points");
} else if (cardPoints <0 ) {
$badge.removeClass("positive-points");
$badge.addClass("negative-points");
}
var rewardPoints = '';
switch( cardPoints.toUpperCase() )
{
case 'XXS':
rewardPoints = 1;
break;
case 'XS':
rewardPoints = 2;
break;
case 'S':
rewardPoints = 3;
break;
case 'M':
rewardPoints = 5;
break;
case 'L':
rewardPoints = 8;
break;
case 'XL':
rewardPoints = 13;
break;
case 'XXL':
rewardPoints = 21;
break;
case '3XL':
rewardPoints = 34;
break;
case '4XL':
rewardPoints = 55;
break;
}
$badge.attr({title: 'This card has '+cardPoints+ (rewardPoints == '' ? '' : ' (' + rewardPoints + ')')+' point' + (cardPoints == 1 ? '.' : 's.')});
};
this.removePointsFromTitle = function (cardPoints) {
var title=$title[0].text;
if (debug) log("Removing following text: '"+pointsAsTitlePattern(cardPoints)+"' from card title: "+ title);
$title[0].textContent = title.replace(pointsAsTitlePattern(cardPoints),'');
if (debug) log("After removal of points, title is: "+this.retrieveTitleText());
};
var pointsAsTitlePattern=function(cardPoints) {
return "("+cardPoints+")";
};
this.retrieveTitleText = function() {
return $title[0].text;
};
this.isMatched = function() {
return $card.hasClass("matched-card");
};
this.isVisible= function(filter) {
if (filter.isCurrentlyFiltered()) return this.isMatched();
else return true;
};
}