1 $(document).ready(function() { |
1 jQuery(document).ready(function () { |
2 $("#applications_progress_bar").progressBar({showText: false}); |
2 jQuery("#applications_progress_bar").progressBar({showText: false}); |
3 }); |
3 }); |
4 |
4 |
5 function bulkReviewInit(bulk_review_link,button) { |
5 function bulkReview(data) { |
6 // get the JSON object with details of every application for bulk acceptance |
6 // some global constants |
7 $.getJSON(bulk_review_link+"?_="+(new Date().getTime()), |
7 var GLOBAL_LINK = data.link; |
8 function(data){ |
8 var TOTAL_APPLICATIONS = data.nr_applications; |
9 // If there are applications to review... |
9 |
10 if (data.nr_applications != 0) { |
10 // some global variables set needed for internal iteration |
11 //...then fade out the button, show the progress bar and call the function for review |
11 var application_index = 0; |
12 $("[id^=button_bulk_]").fadeOut("slow", |
12 // number of iteration is not taken from data.nr_applications |
13 function() { |
13 // to ensure avoidance of array out of bounds errors |
14 $("#applications_progress_bar").progressBar(0); |
14 var total_index = data.applications.length; |
15 $("#description_done").html(""); |
15 |
16 $("#applications_progress_bar").fadeIn("slow", bulkReview(data)); |
16 |
17 } |
17 // call immediately the function for review |
18 ); |
18 // real iteration is inside |
19 }else { |
19 setTimeout( |
20 var no_organization_text="No organizations to "; |
20 function () { |
21 if ($(button).attr("id").indexOf("reject")!=-1) { |
21 var error_happened = false; |
22 no_organization_text+="reject"; |
22 var application = data.applications[application_index]; |
23 } |
23 var current_application = application_index + 1; |
24 else { |
24 // regular expression to find a valid scope path |
25 no_organization_text+="accept"; |
25 // inside matching parenthesis |
26 } |
26 var re = /\((\w*)\)/; |
27 $("#description_done").html("<strong>"+no_organization_text+"</strong>"); |
27 var scope_path = GLOBAL_LINK.match(re)[1]; |
28 } |
28 // the URL is obtained by using the scope path found |
29 } |
29 // in the matching parenthesis |
30 ); |
30 var url_to_call = GLOBAL_LINK.replace(re, application[scope_path]); |
|
31 // now we can call the URL found |
|
32 jQuery.ajax({ |
|
33 async: false, |
|
34 cache: false, |
|
35 url: url_to_call, |
|
36 timeout: 10000, |
|
37 success: function (data) { |
|
38 if (data) { |
|
39 // update progress bar percentage and description |
|
40 var percentage = |
|
41 Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS)); |
|
42 jQuery("#description_progressbar").html([ |
|
43 " Processed application ", application.name, |
|
44 " (", current_application, "/", TOTAL_APPLICATIONS, ")" |
|
45 ].join("")); |
|
46 jQuery("#applications_progress_bar").progressBar(percentage); |
|
47 } |
|
48 }, |
|
49 error: function (XMLHttpRequest, textStatus, errorThrown) { |
|
50 // if there is an error return the button and |
|
51 // leave a try again message |
|
52 error_happened = true; |
|
53 jQuery("[id^=button_bulk_]").fadeIn( |
|
54 "slow", |
|
55 function () { |
|
56 jQuery("#description_done").html([ |
|
57 "<strong class='error'>", |
|
58 " Error encountered, try again", |
|
59 "</strong>" |
|
60 ].join("")); |
|
61 } |
|
62 ); |
|
63 } |
|
64 }); |
|
65 // if there were no errors, continue the iteration |
|
66 if (!error_happened) { |
|
67 // prepare for new iteration and then recall this function |
|
68 application_index++; |
|
69 if (application_index < total_index) { |
|
70 setTimeout(arguments.callee, 0); |
|
71 } |
|
72 else { |
|
73 // all ok, tell the user we are done |
|
74 jQuery("#applications_progress_bar").fadeOut( |
|
75 "slow", |
|
76 function () { |
|
77 jQuery("#applications_progress_bar").progressBar(0); |
|
78 jQuery("[id^=button_bulk_]").fadeIn("slow"); |
|
79 } |
|
80 ); |
|
81 jQuery("#description_progressbar").html(""); |
|
82 jQuery("#description_done").html("<strong>Done!</strong>"); |
|
83 } |
|
84 } |
|
85 }, |
|
86 0 |
|
87 ); |
31 } |
88 } |
32 |
89 |
33 function bulkReview(data) { |
90 function bulkReviewInit(bulk_review_link, button) { |
34 // some global constants |
91 // get the JSON object with details of every application for bulk acceptance |
35 var GLOBAL_LINK = data.link; |
92 jQuery.getJSON( |
36 var TOTAL_APPLICATIONS = data.nr_applications; |
93 bulk_review_link + "?_=" + (new Date().getTime()), |
37 |
94 function (data) { |
38 // some global variables set needed for internal iteration |
95 // If there are applications to review... |
39 var application_index = 0; |
96 if (data.nr_applications !== 0) { |
40 // number of iteration is not taken from data.nr_applications |
97 //...then fade out the button, show the progress bar and call the function for review |
41 // to ensure avoidance of array out of bounds errors |
98 jQuery("[id^=button_bulk_]").fadeOut( |
42 var total_index = data.applications.length; |
99 "slow", |
43 |
100 function () { |
44 |
101 jQuery("#applications_progress_bar").progressBar(0); |
45 // call immediately the function for review |
102 jQuery("#description_done").html(""); |
46 // real iteration is inside |
103 jQuery("#applications_progress_bar").fadeIn("slow", bulkReview(data)); |
47 setTimeout(function(){ |
104 } |
48 var error_happened = false; |
105 ); |
49 |
106 } |
50 var application = data.applications[application_index]; |
107 else { |
51 var current_application = application_index + 1; |
108 var no_organization_text = "No organizations to "; |
52 // regular expression to find a valid scope path inside matching parenthesis |
109 if (jQuery(button).attr("id").indexOf("reject") !== -1) { |
53 var re = /\((\w*)\)/; |
110 no_organization_text += "reject"; |
54 var scope_path = GLOBAL_LINK.match(re)[1]; |
111 } |
55 // the URL is obtained by using the scope path found in the matching parenthesis |
112 else { |
56 var url_to_call = GLOBAL_LINK.replace(re, eval("application." + scope_path)); |
113 no_organization_text += "accept"; |
57 // now we can call the URL found |
114 } |
58 $.ajax({ |
115 jQuery("#description_done").html("<strong>" + no_organization_text + "</strong>"); |
59 async: false, |
116 } |
60 cache: false, |
117 } |
61 url: url_to_call, |
118 ); |
62 timeout: 10000, |
|
63 success: function(data) { |
|
64 if (data) { |
|
65 // update progress bar percentage and description |
|
66 var percentage = Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS)); |
|
67 $("#description_progressbar").html(" Processed application " + application.name + " (" + (current_application) + "/" + TOTAL_APPLICATIONS + ")"); |
|
68 $("#applications_progress_bar").progressBar(percentage); |
|
69 } |
|
70 }, |
|
71 error: function(XMLHttpRequest, textStatus, errorThrown) { |
|
72 // if there is an error return the button and leave a try again message |
|
73 error_happened = true; |
|
74 $("[id^=button_bulk_]").fadeIn("slow", function() { |
|
75 $("#description_done").html("<strong class='error'> Error encountered, try again</strong>"); |
|
76 }); |
|
77 } |
|
78 }); |
|
79 // if there were no errors, continue the iteration |
|
80 if (!error_happened) { |
|
81 // prepare for new iteration and then recall this function |
|
82 application_index++; |
|
83 if (application_index < total_index) { |
|
84 setTimeout(arguments.callee, 0); |
|
85 } |
|
86 else { |
|
87 // all ok, tell the user we are done |
|
88 $("#applications_progress_bar").fadeOut("slow", |
|
89 function() { |
|
90 $("#applications_progress_bar").progressBar(0); |
|
91 $("[id^=button_bulk_]").fadeIn("slow"); |
|
92 } |
|
93 ); |
|
94 $("#description_progressbar").html(""); |
|
95 $("#description_done").html("<strong>Done!</strong>"); |
|
96 } |
|
97 } |
|
98 },0); |
|
99 } |
119 } |