project_content.js
1.65 KB
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
jQuery(showProjectContent);
function showProjectContent() {
callAction('project_state', {}, showProjectContentFor);
}
function showProjectContentFor(state){
if (state == 'ERROR')
callAction('project_error', {}, setProjectContent);
else if (state == 'READY')
callAction('project_result', {}, setProjectContent);
else if (state.endsWith("ING"))
showProjectContentAfter(20);
}
function showProjectContentAfter(seconds){
if (seconds > 0){
setProjectContent("Not ready. Trying again in " + seconds + " seconds");
setTimeout(function() { showProjectContentAfter(seconds - 1);}, 1000);
} else {
setProjectContent("Trying now...");
showProjectContent();
}
}
function setProjectContent(content){
jQuery('#project-content').html(content);
jQuery('.module-result-link').click(showModuleResult);
}
function showModuleResult(){
var module_name = jQuery(this).attr('data-module-name');
setModuleResult("Loading results for " + module_name + "...");
callAction('module_result', {module_name: module_name}, setModuleResult);
return false;
}
function setModuleResult(content){
jQuery('#module-result').html(content);
}
function callAction(action, params, callback){
var profile = projectContentData('profile');
var content = projectContentData('content');
var endpoint = '/profile/' + profile + '/plugins/mezuro/' + action + '/' + content;
jQuery.get(endpoint, params, callback);
}
function projectContentData(data){
return jQuery('#project-content').attr('data-' + data);
}
function sourceNodeToggle(id){
var suffixes = ['_hidden', '_plus', '_minus'];
for (var i in suffixes)
jQuery('#' + id + suffixes[i]).toggle();
}