project_content.js
1.71 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
58
59
60
jQuery(function (){
jQuery('.source-tree-link').live("click", reloadModule);
showProjectContent();
});
function showProjectContent() {
callAction('project_state', {}, showProjectContentFor);
}
function reloadModule(){
var module_name = jQuery(this).attr('data-module-name');
callAction('project_tree', {module_name: module_name }, showProjectTree);
callAction('module_result', {module_name: module_name}, showModuleResult);
return false;
}
function showProjectContentFor(state){
if (state == 'ERROR')
callAction('project_error', {}, showProjectResult);
else if (state == 'READY') {
callAction('project_result', {}, showProjectResult);
callAction('project_tree', {}, showProjectTree);
callAction('module_result', {}, showModuleResult);
}
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 showProjectResult(content) {
jQuery('#project-result').html(content);
}
function showProjectTree(content){
jQuery('#project-tree').html(content);
}
function showModuleResult(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-result').attr('data-' + data);
}