author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 04 Jul 2009 15:16:54 +0200 | |
changeset 2532 | 0b4dbe4b3fb7 |
parent 2302 | 7b281ac17abd |
child 2800 | cd9eed2b787e |
permissions | -rw-r--r-- |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
var duplicateSlots = new function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
// this variable will contain all the org details, and filled |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
// incrementally |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
var orgs_details = {}; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
// this variable will contain all student/proposal data details, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
// filled incrementally |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
var assigned_proposals = new Array(); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
// public function to begin iterating load of JSONs and then call printing |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
// of duplicates |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
this.showDuplicatesInit = function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
|
2301
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
14 |
html_string = ''; |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
// Remember this object for Javascript scoping |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
var this_object = this; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
var NUMBER_OF_ORGS = number_of_orgs; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
var OFFSET_LENGTH = offset_length; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
// Variables to handle progress bar updating |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
var ITERATIONS = (number_of_orgs % offset_length)==0 ? Math.floor(number_of_orgs/offset_length) : Math.floor(number_of_orgs/offset_length)+1; |
2301
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
21 |
|
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
22 |
if (ITERATIONS==0) { |
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
23 |
$("#div_duplicate_slots").html("<strong>No org slots to process</strong>"); |
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
24 |
return; |
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
25 |
} |
fd14daa4b45a
Fixes Issue 625 where the Duplicate calculation would hang if no assigned slots where available.
Mario Ferraro <fadinlight@gmail.com>
parents:
2044
diff
changeset
|
26 |
|
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
var successful_calls = 0; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
$("#id_button_duplicate_slots").fadeOut("slow", |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
$("#duplicates_progress_bar").progressBar(0); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
$("#description_done").html(""); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
// For every ajax success, bind this function to update user feedback |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
$(this).bind("ajaxSuccess", function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
successful_calls++; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS)); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
$("#duplicates_progress_bar").progressBar(percentage); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
$("#description_progressbar").html(" Processed orgs chunk " + (successful_calls) + "/" + ITERATIONS); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
// If this is the last call, feedback the user and print the duplicates data |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
if (successful_calls==ITERATIONS) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
$("#applications_progress_bar").fadeOut("slow", |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
$("#duplicates_progress_bar").progressBar(0); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
$("#id_button_duplicate_slots").fadeIn("slow"); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
$("#description_progressbar").html(""); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
$("#description_done").html("<strong> Done!</strong>"); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
$("#duplicates_progress_bar").fadeOut("slow", |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
$("#id_button_duplicate_slots").val("Recalculate").fadeIn("slow", |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
// Call printing to HTML function with correct scope |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
printDuplicatesAndSendJSON.call(this_object); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
}); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
// Call the showDuplicates function for the first time with correct scope |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
$("#duplicates_progress_bar").fadeIn("slow", showDuplicates.apply(this_object,[url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS])); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
function showDuplicates(url_to_query,OFFSET_LENGTH,NUMBER_OF_ORGS) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
var current_offset = 0; |
2034
59de158c936d
Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2033
diff
changeset
|
69 |
orgs_details = {}; |
59de158c936d
Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2033
diff
changeset
|
70 |
assigned_proposals = new Array(); |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
// Here Ajax call is handled |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
setTimeout(function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
$.ajax({ |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
cache:false, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
mode: "sync", |
2044
3aa6123be2a7
Now using GET request for getting the data.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2042
diff
changeset
|
77 |
type: "GET", |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
timeout: 1000000, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
dataType: "json", |
2044
3aa6123be2a7
Now using GET request for getting the data.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2042
diff
changeset
|
80 |
url: "/program/assigned_proposals/"+url_to_query+"?limit="+OFFSET_LENGTH+"&offset="+current_offset, |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
success: function (data, textStatus) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
if (data) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
// Load JSON data |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
loadSingleJSONData(data); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
85 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
}, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
88 |
// if there is an error return the button and leave a try again message |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
89 |
if (XMLHttpRequest!=undefined) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
90 |
$("#id_button_duplicate_slots").fadeIn("slow", function() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
91 |
$("#description_done").html("<strong class='error'> Error encountered, try again</strong>"); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
92 |
}); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
93 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
94 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
95 |
}); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
96 |
current_offset+=OFFSET_LENGTH; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
97 |
if (current_offset<NUMBER_OF_ORGS) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
98 |
setTimeout(arguments.callee,1); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
99 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
100 |
},1); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
101 |
// This prevent page reloading after each ajax call |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
102 |
return false; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
103 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
104 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
105 |
// private function to load a JSON and pushing the data to the |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
106 |
// private global variables |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
107 |
function loadSingleJSONData(data) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
108 |
if (data) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
109 |
// pushing org details |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
110 |
for (var org_key in data.data.orgs) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
111 |
orgs_details[org_key] = data.data.orgs[org_key]; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
112 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
113 |
// pushing proposals |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
114 |
$(data.data.proposals).each( |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
115 |
function(intIndex, proposal) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
116 |
// if this student_key is not yet present |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
117 |
if (assigned_proposals[proposal.student_key]==undefined) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
118 |
// create the object and insert general info |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
119 |
assigned_proposals[proposal.student_key] = {}; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
120 |
assigned_proposals[proposal.student_key].name = proposal.student_name; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
121 |
assigned_proposals[proposal.student_key].contact = proposal.student_contact; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
122 |
assigned_proposals[proposal.student_key].proposals = new Array(); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
123 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
124 |
// anyway, push the accepted proposals |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
125 |
assigned_proposals[proposal.student_key].proposals.push( |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
126 |
{ |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
127 |
"org_key" : proposal.org_key, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
128 |
"proposal_key" : proposal.key_name, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
129 |
"proposal_title": proposal.proposal_title |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
130 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
131 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
132 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
133 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
134 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
135 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
136 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
137 |
// private function to generate the JSON to send for caching and calling |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
138 |
// the actual function that will print the data |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
139 |
function printDuplicatesAndSendJSON() { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
140 |
// JSON skeleton that need to be sent to the server |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
141 |
var to_json = { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
142 |
"data": { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
143 |
"orgs" : orgs_details, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
144 |
"students": {} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
145 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
146 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
147 |
// for every student... |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
148 |
for (var student_key in assigned_proposals) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
149 |
var accepted_proposals = assigned_proposals[student_key].proposals.length; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
150 |
// if accepted proposal are less than 2, then ignore and continue the iteration |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
151 |
if (accepted_proposals<2) continue; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
152 |
var student = assigned_proposals[student_key]; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
153 |
// push this student to the caching JSON |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
154 |
to_json.data.students[student_key] = student; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
155 |
var proposals = student.proposals; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
156 |
// call the function that prints the output html |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
157 |
this.showDuplicatesHtml(orgs_details,student,student_key,proposals); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
158 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
159 |
if (html_string=="") { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
160 |
$("#div_duplicate_slots").html("<strong>No duplicate slots found</strong>"); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
161 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
162 |
// at the end, send the JSON for caching purposes |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
163 |
$.ajax({ |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
164 |
url: location.href, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
165 |
type: 'POST', |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
166 |
processData: true, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
167 |
data: {result: JSON.stringify(to_json)}, |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
168 |
contentType: 'application/json', |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
169 |
dataType: 'json', |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
170 |
}); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
171 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
172 |
|
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
173 |
// public function to output actual HTML out of the data (cached or not) |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
174 |
this.showDuplicatesHtml = function(orgs_details,student,student_key,proposals) { |
2034
59de158c936d
Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2033
diff
changeset
|
175 |
if (html_string == '') { |
59de158c936d
Fixed the duplicate slots view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2033
diff
changeset
|
176 |
$("#div_duplicate_slots").html(''); |
2004
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
177 |
html_string='<ul>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
178 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
179 |
html_string+= '<li>Student: <strong><a href="/student/show/'+student_key+'">'+student.name+'</a></strong> (<a href="mailto:'+student.contact+'">'+student.contact+'</a>)'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
180 |
html_string+='<ul>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
181 |
$(proposals).each( |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
182 |
function (intIndex, proposal) { |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
183 |
html_string+='<li>Organization: <a href="/org/show/'+proposal.org_key+'">'+orgs_details[proposal.org_key].name+'</a>, admin: '+orgs_details[proposal.org_key].admin_name+' (<a href="mailto:'+orgs_details[proposal.org_key].admin_email+'">'+orgs_details[proposal.org_key].admin_email+'</a>)</li>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
184 |
html_string+='<ul><li>Proposal: <a href="/student_proposal/show/'+proposal.proposal_key+'">'+proposal.proposal_title+'</a></li></ul>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
185 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
186 |
); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
187 |
html_string+='</ul></li>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
188 |
html_string+='</ul>'; |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
189 |
$("#div_duplicate_slots").html(html_string); |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
190 |
} |
4d9e41c947fd
Added JS to the duplicate proposals page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
191 |
} |