# HG changeset patch # User Pawel Solyga # Date 1237560022 0 # Node ID 6bd827320b3dd931803146e673ed9dd7de541b15 # Parent 7c97323fd20b678867289730b9aefd330d09ada2 Add date postfix to slot-allocator.js file. Update base.html template with path to slot-allocator-090320.js. Patch by: Pawel Solyga Reviewed by: to-be-reviewed diff -r 7c97323fd20b -r 6bd827320b3d app/soc/content/js/slot-allocator-090320.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/content/js/slot-allocator-090320.js Fri Mar 20 14:40:22 2009 +0000 @@ -0,0 +1,89 @@ +var current_allocated_slots = 0; +var current_slots = {}; +var tooltip = [ + "
", + "
", + "", + "

Slots

", + "

", + "

", + "

", + "
", + "
", + ].join(''); + +$.postJSON = function (post_url, to_json, callback) { + $.ajax({ + url: post_url, + type: 'POST', + processData: true, + data: {result: JSON.stringify(to_json)}, + contentType: 'application/json', + dataType: 'json', + success: callback, + }); +}; + +function updateFromJSON(data) { + if (data) { + $(data.data).each( + function (intIndex,item) { + $("#id_spin_slot_count_"+item.link_id).val(item.slots); + current_slots[item.link_id] = {slots: item.slots, locked: item.locked, adjustment: item.adjustment}; + $("#id_locked_slot_"+item.link_id).attr("checked",item.locked); + $("#id_spin_adjustment_count_"+item.link_id).val(item.adjustment); + } + ); + updateOverlay(); + } +} + +function retrieveJSON() { + $.getJSON(RETURN_URL+"?_="+(new Date().getTime()), function(data) { + if (data) { + updateFromJSON(data); + } + } + ); +} + +function reCalculate() { + url = RETURN_URL+"?_="+(new Date().getTime()) +  $.postJSON(url, current_slots, updateFromJSON); +} + +function updateOverlay() { + updateCurrentSlots(); + var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots; + $("#p_assigned_slots").html("Assigned slots: "+current_allocated_slots); + $("#p_remaining_slots").html("Remaining slots: "+remaining_slots); +} + +function updateCurrentSlots() { + current_allocated_slots = 0; + for (var org_id in current_slots) { + current_allocated_slots = current_allocated_slots+new Number(current_slots[org_id].slots); + } +} + +function lockSlots (checkbox) { + var locked = $(checkbox).attr("checked"); + var re = /^id_locked_slot_(\w*)/; + var org_link_id = checkbox.id.match(re)[1]; + current_slots[org_link_id].locked = locked; +} + +function assignSlots (counter) { + var re = /^id_spin_slot_count_(\w*)/; + var org_link_id = counter.id.match(re)[1]; + current_slots[org_link_id].slots = $(counter).val(); + updateCurrentSlots(); + updateOverlay(); +} + +function assignAdjustment (counter) { + var re = /^id_spin_adjustment_count_(\w*)/; + var org_link_id = counter.id.match(re)[1]; + current_slots[org_link_id].adjustment = $(counter).val(); +} + diff -r 7c97323fd20b -r 6bd827320b3d app/soc/content/js/slot-allocator.js --- a/app/soc/content/js/slot-allocator.js Fri Mar 20 14:37:52 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -var current_allocated_slots = 0; -var current_slots = {}; -var tooltip = [ - "
", - "
", - "", - "

Slots

", - "

", - "

", - "

", - "
", - "
", - ].join(''); - -$.postJSON = function (post_url, to_json, callback) { - $.ajax({ - url: post_url, - type: 'POST', - processData: true, - data: {result: JSON.stringify(to_json)}, - contentType: 'application/json', - dataType: 'json', - success: callback, - }); -}; - -function updateFromJSON(data) { - if (data) { - $(data.data).each( - function (intIndex,item) { - $("#id_spin_slot_count_"+item.link_id).val(item.slots); - current_slots[item.link_id] = {slots: item.slots, locked: item.locked, adjustment: item.adjustment}; - $("#id_locked_slot_"+item.link_id).attr("checked",item.locked); - $("#id_spin_adjustment_count_"+item.link_id).val(item.adjustment); - } - ); - updateOverlay(); - } -} - -function retrieveJSON() { - $.getJSON(RETURN_URL+"?_="+(new Date().getTime()), function(data) { - if (data) { - updateFromJSON(data); - } - } - ); -} - -function reCalculate() { - url = RETURN_URL+"?_="+(new Date().getTime()) -  $.postJSON(url, current_slots, updateFromJSON); -} - -function updateOverlay() { - updateCurrentSlots(); - var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots; - $("#p_assigned_slots").html("Assigned slots: "+current_allocated_slots); - $("#p_remaining_slots").html("Remaining slots: "+remaining_slots); -} - -function updateCurrentSlots() { - current_allocated_slots = 0; - for (var org_id in current_slots) { - current_allocated_slots = current_allocated_slots+new Number(current_slots[org_id].slots); - } -} - -function lockSlots (checkbox) { - var locked = $(checkbox).attr("checked"); - var re = /^id_locked_slot_(\w*)/; - var org_link_id = checkbox.id.match(re)[1]; - current_slots[org_link_id].locked = locked; -} - -function assignSlots (counter) { - var re = /^id_spin_slot_count_(\w*)/; - var org_link_id = counter.id.match(re)[1]; - current_slots[org_link_id].slots = $(counter).val(); - updateCurrentSlots(); - updateOverlay(); -} - -function assignAdjustment (counter) { - var re = /^id_spin_adjustment_count_(\w*)/; - var org_link_id = counter.id.match(re)[1]; - current_slots[org_link_id].adjustment = $(counter).val(); -} - diff -r 7c97323fd20b -r 6bd827320b3d app/soc/templates/soc/base.html --- a/app/soc/templates/soc/base.html Fri Mar 20 14:37:52 2009 +0000 +++ b/app/soc/templates/soc/base.html Fri Mar 20 14:40:22 2009 +0000 @@ -96,7 +96,7 @@ {% endif %} {% if uses_slot_allocator %} - + {% endif %} {% endblock %}