Mercurial > public > sg101
diff gpp/downloads/static/js/downloads-get.js @ 404:41411066b16d
Fixing #199; redid the downloads so the user has more control about how to save the file.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 27 Mar 2011 23:21:17 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/downloads/static/js/downloads-get.js Sun Mar 27 23:21:17 2011 +0000 @@ -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); + } + }); + }); + }); +});