-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax.js
74 lines (60 loc) · 2.33 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
68
69
70
71
72
73
74
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
M.plagiarism_plagscan = {
reports: []
};
M.plagiarism_plagscan.init = function (Y, contextid, viewlinks, showlinks, viewreport, ps_yellow_level, ps_red_level, pageurl) {
var handleReport = function (report) {
var reportArea = Y.one('.psreport.pid-' + report.id);
if (!report.content.includes('psfile_progress')) {
reportArea.insert(report.content, 'after').remove();
var reports = M.plagiarism_plagscan.reports;
reports.splice(reports.indexOf(report.id), 1);
}
};
var checkReportStatus = function (Y, reports, contextid, viewlinks, showlinks, viewreport, ps_yellow_level, ps_red_level, pageurl) {
if (!reports[0]) {
return;
}
var url = M.cfg.wwwroot + '/plagiarism/plagscan/ajax.php';
var callback = {
method: 'get',
context: this,
sync: false,
data: {
'sesskey': M.cfg.sesskey,
'data': Y.JSON.stringify({
psreports: reports,
cmid: contextid,
viewlinks: viewlinks,
showlinks: showlinks,
viewreport: viewreport,
ps_yellow_level: ps_yellow_level,
ps_red_level: ps_red_level,
pageurl: pageurl
})
},
on: {
success: function (tid, response) {
var jsondata = Y.JSON.parse(response.responseText);
Y.each(jsondata, handleReport);
},
failure: function () {
M.plagiarism_plagscan.reports = [];
}
}
};
Y.io(url, callback);
};
Y.all(".psreport").each(function (row) {
if (row._node.childNodes[0].className == 'psfile_progress') {
M.plagiarism_plagscan.reports.push(row._node.classList[1].substring(4));
}
});
setInterval(function () {
checkReportStatus(Y, M.plagiarism_plagscan.reports, contextid, viewlinks, showlinks, viewreport, ps_yellow_level, ps_red_level, pageurl)
}, 3000);
};