author | Sverre Rabbelier <srabbelier@gmail.com> |
Mon, 09 Mar 2009 23:56:42 +0000 | |
changeset 1781 | f8e85447fbdf |
parent 1747 | 02f15a955c42 |
child 1952 | 7c97323fd20b |
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', |
1744
0288cb88edd2
Treat the response from the server as a JSON object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1734
diff
changeset
|
22 |
dataType: 'json', |
1734
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
success: callback, |
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
function updateFromJSON(data) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
if (data) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
$(data.data).each( |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
function (intIndex,item) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
$("#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
|
32 |
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
|
33 |
$("#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
|
34 |
$("#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
|
35 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
updateOverlay(); |
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
function retrieveJSON() { |
1747
02f15a955c42
Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1744
diff
changeset
|
42 |
$.getJSON(RETURN_URL+"?_="+(new Date().getTime()), |
1734
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
updateFromJSON |
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
function reCalculate() { |
1747
02f15a955c42
Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1744
diff
changeset
|
48 |
url = RETURN_URL+"?_="+(new Date().getTime()) |
02f15a955c42
Provide the 'return_url' in the allocate slots view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1744
diff
changeset
|
49 |
$.postJSON(url, current_slots, updateFromJSON); |
1734
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
function updateOverlay() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
updateCurrentSlots(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
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
|
55 |
$("#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
|
56 |
$("#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
|
57 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
function updateCurrentSlots() { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
current_allocated_slots = 0; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
for (var org_id in current_slots) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
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
|
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
function lockSlots (checkbox) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
var locked = $(checkbox).attr("checked"); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
var re = /^id_locked_slot_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
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
|
70 |
current_slots[org_link_id].locked = locked; |
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
function assignSlots (counter) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
var re = /^id_spin_slot_count_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
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
|
76 |
current_slots[org_link_id].slots = $(counter).val(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
77 |
updateCurrentSlots(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
78 |
updateOverlay(); |
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 |
|
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
function assignAdjustment (counter) { |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
var re = /^id_spin_adjustment_count_(\w*)/; |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
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
|
84 |
current_slots[org_link_id].adjustment = $(counter).val(); |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
} |
c9ecc7449632
Add a slot allocation script and template
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |