diff downloads/static/js/downloads-get.js @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/downloads/static/js/downloads-get.js@41411066b16d
children f56798c96ec2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/downloads/static/js/downloads-get.js	Sat May 05 17:10:48 2012 -0500
@@ -0,0 +1,33 @@
+$(document).ready(function() {
+    $('.dl-button').each(function(n) {
+        var button = $(this);
+        var id = button.attr('id');
+        var numeric_id = -1;
+        if (id.match(/dl-(\d+)/))
+        {
+            numeric_id = RegExp.$1;
+        }
+        button.click(function() {
+           button.attr('disabled', 'disabled').val('Getting link, stand by...');
+           $.ajax({
+               url: '/downloads/request/', 
+               type: 'POST',
+               data: { id: numeric_id },
+               dataType: 'json',
+               success: function(result) {
+                  var link_id = result.id;
+                  var div = $('#link-' + link_id);
+                  div.hide();
+                  div.html(
+                     'Thank you! Your download is now ready. <a href="' + result.url +
+                        '">Click here to download</a>.');
+                  div.fadeIn(3000);
+               },
+               error: function (xhr, textStatus, ex) {
+                   alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + 
+                      xhr.responseText);
+               }
+           });
+        });
+    });
+});