diff -r 0fe7767592d0 -r cd9eed2b787e app/soc/content/js/slot-allocator-090320.js --- a/app/soc/content/js/slot-allocator-090320.js Tue Aug 25 15:55:26 2009 +0100 +++ b/app/soc/content/js/slot-allocator-090320.js Tue Aug 25 15:58:30 2009 +0100 @@ -9,29 +9,52 @@ "

", "

", "
", - "", - ].join(''); + "" +].join(''); + +jQuery.postJSON = function (post_url, to_json, callback) { + jQuery.ajax({ + url: post_url, + type: 'POST', + processData: true, + data: {result: JSON.stringify(to_json)}, + contentType: 'application/json', + dataType: 'json', + success: callback + }); +}; -$.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 updateCurrentSlots() { + current_allocated_slots = 0; + jQuery.each(current_slots, function (org_id, org_details) { + current_allocated_slots = + current_allocated_slots + Number(org_details.slots); + }); +} + +function updateOverlay() { + updateCurrentSlots(); + var remaining_slots = window.MAX_AVAILABLE_SLOTS - current_allocated_slots; + jQuery("#p_assigned_slots") + .html("Assigned slots: " + current_allocated_slots); + jQuery("#p_remaining_slots") + .html("Remaining slots: " + remaining_slots); +} 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); + jQuery(data.data).each( + function (intIndex, item) { + jQuery("#id_spin_slot_count_" + item.link_id).val(item.slots); + current_slots[item.link_id] = { + slots: item.slots, + locked: item.locked, + adjustment: item.adjustment + }; + jQuery("#id_locked_slot_" + item.link_id) + .attr("checked", item.locked); + jQuery("#id_spin_adjustment_count_" + item.link_id) + .val(item.adjustment); } ); updateOverlay(); @@ -39,61 +62,49 @@ } function retrieveJSON() { - $.getJSON(RETURN_URL+"?_="+(new Date().getTime()), function(data) { - if (data) { - updateFromJSON(data); + jQuery.getJSON( + window.RETURN_URL + "?_=" + (new Date().getTime()), + function (data) { + if (data) { + updateFromJSON(data); + } } - } ); } function reCalculate() { - url = RETURN_URL+"?_="+(new Date().getTime()) -  $.postJSON(url, current_slots, updateFromJSON); + var url = window.RETURN_URL + "?_=" + (new Date().getTime()); +  jQuery.postJSON(url, current_slots, updateFromJSON); } function submit() { - url = RETURN_URL+"?submit=1&_="+(new Date().getTime()) -  $.postJSON(url, current_slots, updateFromJSON); + var url = window.RETURN_URL + "?submit=1&_=" + (new Date().getTime()); +  jQuery.postJSON(url, current_slots, updateFromJSON); } function load() { - url = RETURN_URL+"?load=1&_="+(new Date().getTime()) -  $.postJSON(url, current_slots, updateFromJSON); + var url = window.RETURN_URL + "?load=1&_=" + (new Date().getTime()); +  jQuery.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"); +function lockSlots(checkbox) { + var locked = jQuery(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) { +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(); + current_slots[org_link_id].slots = jQuery(counter).val(); updateCurrentSlots(); updateOverlay(); } -function assignAdjustment (counter) { +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(); + current_slots[org_link_id].adjustment = jQuery(counter).val(); }