view downloads/static/js/downloads-get.js @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents ee87ea74d46b
children f56798c96ec2
line wrap: on
line source
$(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);
               }
           });
        });
    });
});