app/soc/templates/soc/org_app/review_overview.html
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 14 Feb 2009 21:18:12 +0000
changeset 1328 cd175dddc15c
parent 1294 359987b7027d
child 1358 6be502a1bcc6
permissions -rw-r--r--
Added bulk acceptance and progress bar in review org applications view. In the list of organization applications for reviewing, if you click the button "click here" the whole first text line will fade out and the progress bar will fade in while starting to contact the server for the list of orgs to accept and then make synchronous calls for acceptance, while updating the progress bar, the name of the organization currently accepting and the number of orgs already accepted against the total. Inside the script, what's inside the parenthesis is converted due to regexp (in this case (link_id)) and then read the json_object.applications[index].link_id. By doing this with an eval(), you can use other names as well and the script will be reading for example json_object.applications[index].attribute_name if you insert "(attribute_name)" inside the link returned by {{ bulk_accept_link }}. Notes by Lennard: -Put Done outside the for-loop so that it also shows when there are 0 pre-accepted organizations. -Made some minor style fixes Patch by: Mario Ferraro Reviewed by: Lennard de Rijk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
{% extends "soc/models/list.html" %}
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
{% comment %}
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
Licensed under the Apache License, Version 2.0 (the "License");
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
you may not use this file except in compliance with the License.
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
You may obtain a copy of the License at
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
  http://www.apache.org/licenses/LICENSE-2.0
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
Unless required by applicable law or agreed to in writing, software
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
distributed under the License is distributed on an "AS IS" BASIS,
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
See the License for the specific language governing permissions and
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
limitations under the License.
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
{% endcomment %}
1328
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    15
{% block scripts %}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    16
<script type="text/javascript" src="/jquery/jquery-progressbar.js"></script>
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    17
<script type="text/javascript">
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    18
	$(document).ready(function() {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    19
		$("#applications_progress_bar").progressBar({showText: false});
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    20
	});
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    21
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    22
	function acceptOrgInit() {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    23
		$("#acceptance_text").fadeOut("slow",
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    24
			function() {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    25
				$("#applications_progress_bar").fadeIn("slow");
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    26
			}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    27
		);
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    28
		$.getJSON("{{ bulk_accept_link|safe }}",
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    29
			function(data){
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    30
				setTimeout(function(){acceptOrg(data)}, 0);
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    31
			}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    32
		);
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    33
	}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    34
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    35
	function acceptOrg(accepted_applications) {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    36
		var application_index = 0, max_applications=accepted_applications.applications.length;
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    37
		for (application_index; application_index<max_applications; application_index++) {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    38
			// regular expression to find a valid scope path inside matching parenthesis
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    39
			var re = /\((\w*)\)/;
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    40
			var scope_path = accepted_applications.link.match(re)[1];
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    41
			// the URL is obtained by using the scope path found in the matching parenthesis
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    42
			var url_to_call = accepted_applications.link.replace(re,eval("accepted_applications.applications[application_index]."+scope_path));
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    43
			// now we can call the URL found
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    44
			$.ajax({
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    45
				async: false,
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    46
				url: url_to_call,
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    47
				timeout: 10000,
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    48
				complete: function(data) {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    49
					if (data) {
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    50
						// update progress bar percentage and description
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    51
						var percentage = Math.floor(100 * (application_index+1) / (accepted_applications.nr_applications));
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    52
						$("#description_progressbar").html(" Processed application "+accepted_applications.applications[application_index].name+" ("+(application_index+1)+"/"+accepted_applications.nr_applications+")");
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    53
						$("#applications_progress_bar").progressBar(percentage);
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    54
					}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    55
				}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    56
			});
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    57
		}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    58
		// tell the user we are done
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    59
		$("#description_done").html(" <strong>Done!</strong>");
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    60
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    61
	}
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    62
</script>
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    63
{% endblock %}
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
{% block body %}
1328
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    65
<span id="acceptance_text">If you want to accept all pre-accepted organizations please <button id="button_accept" onclick="javascript:acceptOrgInit();">click here</button></span><span class="progressBar" style="display:none;" id="applications_progress_bar"></span><span id="description_progressbar"></span><span id="description_done"></span>
1294
359987b7027d Added bulk_accept view which returns a JSON object.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
{{ block.super}}
1328
cd175dddc15c Added bulk acceptance and progress bar in review org applications view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1294
diff changeset
    67
{% endblock %}