annotate bandmap/static/js/bandmap.js @ 824:704b47356a49

Bandmap WIP: made a start on view unit tests.
author Brian Neal <bgneal@gmail.com>
date Wed, 24 Sep 2014 21:22:24 -0500
parents 71db8076dc3d
children 5103edd3acc4
rev   line source
bgneal@821 1 var bandmap = null;
bgneal@821 2 var geocoder = null;
bgneal@821 3
bgneal@821 4 function addBandOnSubmit(event) {
bgneal@821 5 var location = $('#id_location').val();
bgneal@821 6 if (!location) {
bgneal@821 7 alert("Please enter a location");
bgneal@821 8 return false;
bgneal@821 9 }
bgneal@821 10 var button = $(this);
bgneal@821 11 button.attr('disabled', 'disabled');
bgneal@821 12 var form = $('#bandmap-add-form');
bgneal@821 13 geocoder.geocode({'address': location}, function(results, status) {
bgneal@821 14 button.removeAttr('disabled');
bgneal@821 15 if (status == google.maps.GeocoderStatus.OK) {
bgneal@821 16 $('#id_lat').val(results[0].geometry.location.lat().toString());
bgneal@821 17 $('#id_lon').val(results[0].geometry.location.lng().toString());
bgneal@821 18 $(form).submit();
bgneal@821 19 }
bgneal@821 20 else {
bgneal@821 21 var msg = "Geocode unsuccessful: " + status + "\n" +
bgneal@821 22 "Enter a new location";
bgneal@821 23 alert(msg);
bgneal@821 24 }
bgneal@821 25 });
bgneal@821 26 return false;
bgneal@821 27 }
bgneal@821 28
bgneal@820 29 $(document).ready(function() {
bgneal@820 30 var map_div = $('#map-canvas');
bgneal@820 31 if (map_div.length) {
bgneal@820 32 var map_options = {
bgneal@820 33 center: {lat: 15.0, lng: -30.0},
bgneal@820 34 zoom: 2
bgneal@820 35 };
bgneal@821 36 bandmap = new google.maps.Map(map_div[0], map_options);
bgneal@820 37 }
bgneal@820 38
bgneal@820 39 var add_form = $('#bandmap-add-form');
bgneal@820 40 if (add_form.length) {
bgneal@821 41 geocoder = new google.maps.Geocoder();
bgneal@821 42 $('#bandmap-add-submit').click(addBandOnSubmit);
bgneal@820 43 }
bgneal@820 44 });