-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
91 lines (76 loc) · 1.93 KB
/
ui.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
var $cardList = $('#cards');
var $highlightAllButton = $('#highlight_all');
var $spinner = $('#spinner');
var $unhighlightAllButton = $('#unhighlight_all');
// Given a list of comments, generate Cards and render them.
function populateCards(comments) {
var $cards = $cardList.html('');
comments.forEach(function(comment) {
new Card({
text: comment.text,
module: comment.module,
indices: comment.indices}).appendTo($cards);
});
}
// Displaying cards involves selectively showing
// toolbar buttons. Note: it's a little too clever
// for the sake of keeping things DRY.
function showCards(show) {
var elements = {
'#no_comments': show,
'#yes_comments': !show,
'#cards': !show,
};
Object.keys(elements).forEach(function(key) {
$(key)[elements[key] ? 'addClass' : 'removeClass']('hidden');
});
}
// Spinner
function toggleSpinner(yes) {
_toggleHidden($spinner, yes);
}
// (Un)select all cards
function selectAllCards() {
$cardList.children('li').each(function() {
selectCard($(this));
});
}
function unselectAllCards() {
$cardList.children('li').each(function() {
unselectCard($(this));
});
}
// Card (un)select
function selectCard($card) {
_selectCard($card, true);
}
function unselectCard($card) {
_selectCard($card, false);
}
// (Un)Highlight All Button(s)
function toggleHighlightAllButton(enable) {
_toggleHidden($highlightAllButton, enable);
}
function toggleUnhighlightAllButton(enable) {
_toggleHidden($unhighlightAllButton, enable);
}
// Error notifications
function errorNotify(msg) {
var $errors = $('#errors');
var $error = $('<li>').text(msg);
$errors.append($error);
$errors.fadeIn();
setTimeout(function() {
$errors.html('');
$errors.fadeOut();
}, 5000);
}
/*
* Helpers
*/
function _selectCard($card, yes) {
$card.attr('data-selected', yes ? 'yes' : 'no');
}
function _toggleHidden($el, yes) {
$el[yes ? 'removeClass' : 'addClass']('hidden');
}