author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 08 Mar 2009 13:14:28 +0000 | |
changeset 1741 | 0da1285f5bc0 |
parent 1734 | c9ecc7449632 |
child 1744 | 0288cb88edd2 |
permissions | -rw-r--r-- |
1734
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
var current_allocated_slots = 0; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
var current_slots = {}; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
var tooltip = [ |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
"<div class='tooltip'>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
"<div class='tooltip-body'>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
"<img src='/soc/content/images/purrInfo.png' alt='' />", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
"<h3>Slots</h3>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
"<p id='p_assigned_slots'></p>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
"<p id='p_remaining_slots'></p>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
"<p id='p_total_slots'></p></div>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
"<div class='tooltip-bottom'></div>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
"</div>", |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
].join(''); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
$.postJSON = function (post_url, to_json, callback) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
$.ajax({ |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
url: post_url, |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
type: 'POST', |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
processData: true, |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
data: {result: JSON.stringify(to_json)}, |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
contentType: 'application/json', |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
success: callback, |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
}); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
}; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
function updateFromJSON(data) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
if (data) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
$(data.data).each( |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
function (intIndex,item) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
$("#id_spin_slot_count_"+item.link_id).val(item.slots); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
current_slots[item.link_id] = {slots: item.slots, locked: item.locked, adjustment: item.adjustment}; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
$("#id_locked_slot_"+item.link_id).attr("checked",item.locked); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
$("#id_spin_adjustment_count_"+item.link_id).val(item.adjustment); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
updateOverlay(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
function retrieveJSON() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
$.getJSON("http://localhost:8080/program/slots/google/gsoc2009?_="+(new Date().getTime()), |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
updateFromJSON |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
function reCalculate() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
url = "http://localhost:8080/program/slots/google/gsoc2009?_="+(new Date().getTime()) |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
$.postJSON(url, current_slots, updateFromJSON); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
function updateOverlay() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
updateCurrentSlots(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
$("#p_assigned_slots").html("<strong>Assigned slots:</strong> "+current_allocated_slots); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
$("#p_remaining_slots").html("<strong>Remaining slots:</strong> "+remaining_slots); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
function updateCurrentSlots() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
current_allocated_slots = 0; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
for (var org_id in current_slots) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
current_allocated_slots = current_allocated_slots+new Number(current_slots[org_id].slots); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
function lockSlots (checkbox) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
var locked = $(checkbox).attr("checked"); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
var re = /^id_locked_slot_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
var org_link_id = checkbox.id.match(re)[1]; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
current_slots[org_link_id].locked = locked; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
function assignSlots (counter) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
var re = /^id_spin_slot_count_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
var org_link_id = counter.id.match(re)[1]; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
current_slots[org_link_id].slots = $(counter).val(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
76 |
updateCurrentSlots(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
updateOverlay(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
function assignAdjustment (counter) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
var re = /^id_spin_adjustment_count_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
var org_link_id = counter.id.match(re)[1]; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
current_slots[org_link_id].adjustment = $(counter).val(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |