|
1 var current_allocated_slots = 0; |
|
2 var current_slots = {}; |
|
3 var tooltip = [ |
|
4 "<div class='tooltip'>", |
|
5 "<div class='tooltip-body'>", |
|
6 "<img src='/soc/content/images/purrInfo.png' alt='' />", |
|
7 "<h3>Slots</h3>", |
|
8 "<p id='p_assigned_slots'></p>", |
|
9 "<p id='p_remaining_slots'></p>", |
|
10 "<p id='p_total_slots'></p></div>", |
|
11 "<div class='tooltip-bottom'></div>", |
|
12 "</div>", |
|
13 ].join(''); |
|
14 |
|
15 $.postJSON = function (post_url, to_json, callback) { |
|
16 $.ajax({ |
|
17 url: post_url, |
|
18 type: 'POST', |
|
19 processData: true, |
|
20 data: {result: JSON.stringify(to_json)}, |
|
21 contentType: 'application/json', |
|
22 dataType: 'json', |
|
23 success: callback, |
|
24 }); |
|
25 }; |
|
26 |
|
27 function updateFromJSON(data) { |
|
28 if (data) { |
|
29 $(data.data).each( |
|
30 function (intIndex,item) { |
|
31 $("#id_spin_slot_count_"+item.link_id).val(item.slots); |
|
32 current_slots[item.link_id] = {slots: item.slots, locked: item.locked, adjustment: item.adjustment}; |
|
33 $("#id_locked_slot_"+item.link_id).attr("checked",item.locked); |
|
34 $("#id_spin_adjustment_count_"+item.link_id).val(item.adjustment); |
|
35 } |
|
36 ); |
|
37 updateOverlay(); |
|
38 } |
|
39 } |
|
40 |
|
41 function retrieveJSON() { |
|
42 $.getJSON(RETURN_URL+"?_="+(new Date().getTime()), function(data) { |
|
43 if (data) { |
|
44 updateFromJSON(data); |
|
45 } |
|
46 } |
|
47 ); |
|
48 } |
|
49 |
|
50 function reCalculate() { |
|
51 url = RETURN_URL+"?_="+(new Date().getTime()) |
|
52 $.postJSON(url, current_slots, updateFromJSON); |
|
53 } |
|
54 |
|
55 function updateOverlay() { |
|
56 updateCurrentSlots(); |
|
57 var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots; |
|
58 $("#p_assigned_slots").html("<strong>Assigned slots:</strong> "+current_allocated_slots); |
|
59 $("#p_remaining_slots").html("<strong>Remaining slots:</strong> "+remaining_slots); |
|
60 } |
|
61 |
|
62 function updateCurrentSlots() { |
|
63 current_allocated_slots = 0; |
|
64 for (var org_id in current_slots) { |
|
65 current_allocated_slots = current_allocated_slots+new Number(current_slots[org_id].slots); |
|
66 } |
|
67 } |
|
68 |
|
69 function lockSlots (checkbox) { |
|
70 var locked = $(checkbox).attr("checked"); |
|
71 var re = /^id_locked_slot_(\w*)/; |
|
72 var org_link_id = checkbox.id.match(re)[1]; |
|
73 current_slots[org_link_id].locked = locked; |
|
74 } |
|
75 |
|
76 function assignSlots (counter) { |
|
77 var re = /^id_spin_slot_count_(\w*)/; |
|
78 var org_link_id = counter.id.match(re)[1]; |
|
79 current_slots[org_link_id].slots = $(counter).val(); |
|
80 updateCurrentSlots(); |
|
81 updateOverlay(); |
|
82 } |
|
83 |
|
84 function assignAdjustment (counter) { |
|
85 var re = /^id_spin_adjustment_count_(\w*)/; |
|
86 var org_link_id = counter.id.match(re)[1]; |
|
87 current_slots[org_link_id].adjustment = $(counter).val(); |
|
88 } |
|
89 |