annotate downloads/static/js/downloads-get.js @ 629:f4c043cf55ac

Wiki integration. Requests don't always have sessions. In particular this occurs when a request is made without a trailing slash. The Common middleware redirects when this happens, and the middleware process_request() processing stops before a session can get added. So just set an attribute on the request object for each operation. This seemed weird to me at first, but there are plenty of examples of this in the Django code base already.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Nov 2012 13:50:06 -0600
parents ee87ea74d46b
children f56798c96ec2
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 });