1 jQuery(document).ready(function () { |
|
2 jQuery("#applications_progress_bar").progressBar({showText: false}); |
|
3 }); |
|
4 |
|
5 function bulkReview(data) { |
|
6 // some global constants |
|
7 var GLOBAL_LINK = data.link; |
|
8 var TOTAL_APPLICATIONS = data.nr_applications; |
|
9 |
|
10 // some global variables set needed for internal iteration |
|
11 var application_index = 0; |
|
12 // number of iteration is not taken from data.nr_applications |
|
13 // to ensure avoidance of array out of bounds errors |
|
14 var total_index = data.applications.length; |
|
15 |
|
16 |
|
17 // call immediately the function for review |
|
18 // real iteration is inside |
|
19 setTimeout( |
|
20 function () { |
|
21 var error_happened = false; |
|
22 var application = data.applications[application_index]; |
|
23 var current_application = application_index + 1; |
|
24 // regular expression to find a valid scope path |
|
25 // inside matching parenthesis |
|
26 var re = /\((\w*)\)/; |
|
27 var scope_path = GLOBAL_LINK.match(re)[1]; |
|
28 // the URL is obtained by using the scope path found |
|
29 // in the matching parenthesis |
|
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 ); |
|
88 } |
|
89 |
|
90 function bulkReviewInit(bulk_review_link, button) { |
|
91 // get the JSON object with details of every application for bulk acceptance |
|
92 jQuery.getJSON( |
|
93 bulk_review_link + "?_=" + (new Date().getTime()), |
|
94 function (data) { |
|
95 // If there are applications to review... |
|
96 if (data.nr_applications !== 0) { |
|
97 //...then fade out the button, show the progress bar and call the function for review |
|
98 jQuery("[id^=button_bulk_]").fadeOut( |
|
99 "slow", |
|
100 function () { |
|
101 jQuery("#applications_progress_bar").progressBar(0); |
|
102 jQuery("#description_done").html(""); |
|
103 jQuery("#applications_progress_bar").fadeIn("slow", bulkReview(data)); |
|
104 } |
|
105 ); |
|
106 } |
|
107 else { |
|
108 var no_organization_text = "No organizations to "; |
|
109 if (jQuery(button).attr("id").indexOf("reject") !== -1) { |
|
110 no_organization_text += "reject"; |
|
111 } |
|
112 else { |
|
113 no_organization_text += "accept"; |
|
114 } |
|
115 jQuery("#description_done").html("<strong>" + no_organization_text + "</strong>"); |
|
116 } |
|
117 } |
|
118 ); |
|
119 } |
|