-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (73 loc) · 2.28 KB
/
index.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
$(document).ready(function() {
var $analyzeButton = $('#analyze');
var $cardList = $('#cards');
var $highlightAllButton = $('#highlight_all');
var $unhighlightAllButton = $('#unhighlight_all');
var CHECK_STATUS_DELAY = 1000;
var comments = [];
$analyzeButton.on('click', function(_) {
Ajax.submitDocument(analysisStart, submitFailure);
});
$highlightAllButton.on('click', function(_) {
if (comments) {
Ajax.highlightComments(comments, function() {
toggleHighlightAllButton(false);
toggleUnhighlightAllButton(true);
selectAllCards();
});
}
});
$unhighlightAllButton.on('click', function(_) {
Ajax.unhighlightComments(function() {
toggleUnhighlightAllButton(false);
toggleHighlightAllButton(true);
unselectAllCards();
});
});
// Text has been submitted for analysis, so we show
// the spinner and start polling the backend.
function analysisStart(location) {
toggleSpinner(true);
// Poll the server for the comments
var id = setInterval(function() {
Ajax.checkStatus(location, function(response) {
// If no response, continue
if (!response) {return;}
// Otherwise, stop polling
clearInterval(id);
// Extract the comments
comments = response.comments;
// Hide the spinner
toggleSpinner(false);
// Populate and render the cards
populateCards(comments);
showCards(true);
// Initially all cards are selected
selectAllCards();
toggleUnhighlightAllButton(true);
listenOnCards();
});
}, CHECK_STATUS_DELAY);
}
function submitFailure(err) {
errorNotify('Sorry, wasn\'t able to submit the text.');
showCards(false);
}
function listenOnCards() {
$cardList.children('li').on('click', function(_) {
// Select only $(this) card
unselectAllCards();
selectCard($(this));
// Highlight the corresponding tokens
Ajax.emphasizeByIndices(
$(this).attr('data-indices'),
$(this).attr('data-module'),
// Upon success, enable (un)highlight all button(s)
function() {
toggleHighlightAllButton(true);
toggleUnhighlightAllButton(true);
},
comments);
});
}
});