annotate gpp/downloads/static/js/downloads-get.js @ 505:a5d11471d031

Refactor the logic in the rate limiter decorator. Check to see if the request was ajax, as the ajax view always returns 200. Have to decode the JSON response to see if an error occurred or not.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Dec 2011 19:13:38 +0000
parents 41411066b16d
children
rev   line source
bgneal@404 1 $(document).ready(function() {
bgneal@404 2 $('.dl-button').each(function(n) {
bgneal@404 3 var button = $(this);
bgneal@404 4 var id = button.attr('id');
bgneal@404 5 var numeric_id = -1;
bgneal@404 6 if (id.match(/dl-(\d+)/))
bgneal@404 7 {
bgneal@404 8 numeric_id = RegExp.$1;
bgneal@404 9 }
bgneal@404 10 button.click(function() {
bgneal@404 11 button.attr('disabled', 'disabled').val('Getting link, stand by...');
bgneal@404 12 $.ajax({
bgneal@404 13 url: '/downloads/request/',
bgneal@404 14 type: 'POST',
bgneal@404 15 data: { id: numeric_id },
bgneal@404 16 dataType: 'json',
bgneal@404 17 success: function(result) {
bgneal@404 18 var link_id = result.id;
bgneal@404 19 var div = $('#link-' + link_id);
bgneal@404 20 div.hide();
bgneal@404 21 div.html(
bgneal@404 22 'Thank you! Your download is now ready. <a href="' + result.url +
bgneal@404 23 '">Click here to download</a>.');
bgneal@404 24 div.fadeIn(3000);
bgneal@404 25 },
bgneal@404 26 error: function (xhr, textStatus, ex) {
bgneal@404 27 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@404 28 xhr.responseText);
bgneal@404 29 }
bgneal@404 30 });
bgneal@404 31 });
bgneal@404 32 });
bgneal@404 33 });