app/soc/content/js/bulk-review-090304.js
author David Anderson <david.jc.anderson@gmail.com>
Fri, 13 Mar 2009 02:13:21 +0000
changeset 1825 a610a2df83d2
parent 1646 42b8e294792e
child 2800 cd9eed2b787e
permissions -rw-r--r--
Move the Paths class to the util module.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
$(document).ready(function() {
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
	$("#applications_progress_bar").progressBar({showText: false});
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
});
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
1570
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
     5
function bulkReviewInit(bulk_review_link,button) {
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
     6
	// get the JSON object with details of every application for bulk acceptance
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
     7
	$.getJSON(bulk_review_link+"?_="+(new Date().getTime()),
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
		function(data){
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
     9
			// If there are applications to review...
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    10
			if (data.nr_applications != 0) {
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
    11
				//...then fade out the button, show the progress bar and call the function for review
1570
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    12
				$("[id^=button_bulk_]").fadeOut("slow",
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    13
					function() {
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    14
						$("#applications_progress_bar").progressBar(0);
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    15
						$("#description_done").html("");
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
    16
						$("#applications_progress_bar").fadeIn("slow", bulkReview(data));
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    17
					}
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    18
				);
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    19
			}else {
1570
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    20
				var no_organization_text="No organizations to ";
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    21
				if ($(button).attr("id").indexOf("reject")!=-1) {
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    22
					no_organization_text+="reject";
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    23
				}
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    24
				else {
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    25
					no_organization_text+="accept";
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    26
				}
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    27
				$("#description_done").html("<strong>"+no_organization_text+"</strong>");
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    28
			}
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
		}
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
	);
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
}
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
    33
function bulkReview(data) {
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    34
	// some global constants
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    35
	var GLOBAL_LINK = data.link;
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    36
	var TOTAL_APPLICATIONS = data.nr_applications;
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    37
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    38
	// some global variables set needed for internal iteration
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    39
	var application_index = 0;
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    40
	// number of iteration is not taken from data.nr_applications
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    41
	// to ensure avoidance of array out of bounds errors
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    42
	var total_index = data.applications.length;
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    43
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    44
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
    45
	// call immediately the function for review
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    46
	// real iteration is inside
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    47
	setTimeout(function(){
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    48
		var error_happened = false;
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    49
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    50
		var application = data.applications[application_index];
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    51
		var current_application = application_index + 1;
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
		// regular expression to find a valid scope path inside matching parenthesis
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
		var re = /\((\w*)\)/;
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    54
		var scope_path = GLOBAL_LINK.match(re)[1];
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
		// the URL is obtained by using the scope path found in the matching parenthesis
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    56
		var url_to_call = GLOBAL_LINK.replace(re, eval("application." + scope_path));
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
		// now we can call the URL found
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
		$.ajax({
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
			async: false,
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    60
			cache: false,
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
			url: url_to_call,
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
			timeout: 10000,
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    63
			success: function(data) {
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
				if (data) {
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
					// update progress bar percentage and description
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    66
					var percentage = Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS));
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    67
					$("#description_progressbar").html(" Processed application " + application.name + " (" + (current_application) + "/" + TOTAL_APPLICATIONS + ")");
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
					$("#applications_progress_bar").progressBar(percentage);
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
				}
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    70
			},
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    71
			error: function(XMLHttpRequest, textStatus, errorThrown) {
1535
a5277d506a21 Renamed org-accept.js to bulk-review.js
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1506
diff changeset
    72
				// if there is an error return the button and leave a try again message
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    73
				error_happened = true;
1570
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    74
				$("[id^=button_bulk_]").fadeIn("slow", function() {
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    75
					$("#description_done").html("<strong class='error'> Error encountered, try again</strong>");
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    76
				});
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
			}
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
		});
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    79
		// if there were no errors, continue the iteration
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    80
		if (!error_happened) {
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    81
			// prepare for new iteration and then recall this function
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    82
			application_index++;
1367
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    83
			if (application_index < total_index) {
9899e92121b7 Style fixes in org-accept.js file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1364
diff changeset
    84
				setTimeout(arguments.callee, 0);
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    85
			}
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    86
			else {
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    87
				// all ok, tell the user we are done
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    88
				$("#applications_progress_bar").fadeOut("slow",
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    89
					function() {
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    90
						$("#applications_progress_bar").progressBar(0);
1570
cda9f118bfef Improved Organization Application review overview and bulk reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1535
diff changeset
    91
						$("[id^=button_bulk_]").fadeIn("slow");
1364
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    92
					}
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    93
				);
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    94
				$("#description_progressbar").html("");
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    95
				$("#description_done").html("<strong>Done!</strong>");
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    96
			}
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    97
		}
b2709805fafe Update org bulk accept script.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1356
diff changeset
    98
	},0);
1356
32d8d83678cd Make various JS methods into their own file
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
}