-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.js
67 lines (59 loc) · 2.26 KB
/
ajax.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
// The interface for making backend calls
var Ajax = (function(){
return {
// A helper for those methods that don't have
// anything more interesting to report in cases of failure.
genericFailure: function(func_name) {
console.log('Ajax error: ' + func_name);
},
// Submit the text of the current document for analysis.
//
// The handler `success` will get a location argument passed
// to it, using which, it'll be possible to check the status
// of the draft.
submitDocument: function(success, failure) {
google.script.run
.withSuccessHandler(success)
.withFailureHandler(failure || this.genericFailure('submitDocument'))
.analyze_all();
},
// Check the document status using `location`. Note that success
// and failure handlers have nothing to do with status itself,
// but are for responding to the ajax call: if the status check
// call succeeds, `success` gets called, otherwise `failure` does.
//
// If the the document at `location` has not been processed,
// `success` gets called with a falsy value. Otherwise, it gets
// an options object of form {status: 200, comments: []}.
checkStatus: function(location, success, failure) {
google.script.run
.withSuccessHandler(success)
.withFailureHandler(failure || this.genericFailure('checkStatus'))
.checkStatus(location);
},
// Highlight the given comments
highlightComments: function(comments, success) {
google.script.run
.withSuccessHandler(success)
.highlightComments(comments);
},
// Unhighlight all comments
unhighlightComments: function(success) {
google.script.run
.withSuccessHandler(success)
.unhighlight();
},
// Highlight indices with the color of module.
highlightByIndices: function(indices, module, success) {
google.script.run
.withSuccessHandler(success)
.highlightByIndices(indices, module);
},
// Comments are passed so that unemphasize can piggyback on highlight
emphasizeByIndices: function(indices, module, success, comments) {
google.script.run
.withSuccessHandler(success)
.emphasizeByIndices(indices, module, comments);
},
};
}());