-
Notifications
You must be signed in to change notification settings - Fork 3
/
list.js
51 lines (42 loc) · 2.21 KB
/
list.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
function List(pageIndex, node, cards) {
return {
pageIndex: pageIndex,
node: node,
cards: cards,
badgesContainerNode: undefined,
badgesContainer: function() {
var badgesContainerNode = this.node.getElementsByClassName("pointy-list-badges")[0];
if (badgesContainerNode === undefined) {
badgesContainerNode = document.createElement("div");
badgesContainerNode.classList.add("pointy-list-badges");
badgesContainerNode.classList.add("badges");
this.node.getElementsByClassName("list-header")[0].innerHTML += badgesContainerNode.outerHTML;
badgesContainerNode = this.node.getElementsByClassName("pointy-list-badges")[0];
}
return badgesContainerNode;
},
addBadge: function(fieldName, badgeText, badgeIcon, fontColor, badgeColor, fontSize, fontWeight) {
var badge = newBadge(fieldName, badgeText, badgeIcon, fontColor, badgeColor, fontSize, fontWeight);
this.badgesContainer().innerHTML += badge.outerHTML;
},
processBadge: function(fieldName, iconName, fontColor, badgeColor, fontSize, fontWeight, reduceFunc, initialValue) {
var result = this.cards.reduce(reduceFunc, initialValue);
this[fieldName] = result;
this.addBadge(fieldName, result, iconName, fontColor, badgeColor, fontSize, fontWeight);
},
process: function(config) {
var fontColor = "#FFF", fontSize = "smaller", fontWeight = "400";
this.cards.forEach(function(card) { card.processBadges(); });
for (var k = 0; k < config.listBadges.length; k++) {
var listBadgeConf = config.listBadges[k];
this.processBadge(listBadgeConf.field, listBadgeConf.icon,
listBadgeConf.textColor, listBadgeConf.bgColor,
listBadgeConf.fontSize, listBadgeConf.fontWeight,
listBadgeConf.reduce, listBadgeConf.reduceInit);
}
},
refresh: function() {
this.cards.forEach(function(card) { card.refresh(); });
}
};
}