annotate media/js/membermap.js @ 36:296b610ee507

Added IPN logic to the donations module. Added a thank-you view. Need to add logging to the IPN function.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Jun 2009 00:54:44 +0000
parents dbd703f7d63a
children c515b7401078
rev   line source
gremmie@1 1 var mmap = {
gremmie@1 2 map: null,
gremmie@1 3 geocoder: null,
gremmie@1 4 users: Object,
gremmie@1 5 userOnMap: false,
gremmie@1 6 userClick: function() {
gremmie@1 7 var name = $('option:selected', this).text();
gremmie@1 8 if (name != mmap.selectText)
gremmie@1 9 {
gremmie@1 10 mmap.clickUser(name);
gremmie@1 11 }
gremmie@1 12 },
gremmie@1 13 clickUser: function(name) {
gremmie@1 14 pt = new GLatLng(mmap.users[name].lat, mmap.users[name].lon);
gremmie@1 15 mmap.map.setCenter(pt);
gremmie@1 16 mmap.users[name].marker.openInfoWindowHtml(mmap.users[name].message);
gremmie@1 17 },
gremmie@1 18 clear: function() {
gremmie@1 19 mmap.users.length = 0;
gremmie@1 20 },
gremmie@1 21 resizeUserList: function() {
gremmie@1 22 var sel = $('#member_map_members');
gremmie@1 23 sel[0].size = Math.min(29, sel[0].length);
gremmie@1 24 $('#member_map_count').html(sel[0].length);
gremmie@1 25 },
gremmie@1 26 selectText: "(select)",
gremmie@1 27 onMapDir: 'You have previously added yourself to the member map. Your information appears below. You may change ' +
gremmie@1 28 'the information if you wish. To delete yourself from the map, click the Delete button.',
gremmie@1 29 offMapDir: 'Your location is not on the map. If you would like to appear on the map, please fill out the form below ' +
gremmie@1 30 'and click the Submit button.'
gremmie@1 31 };
gremmie@1 32 $(document).ready(function() {
gremmie@1 33 $('#id_message').markItUp(mySettings);
gremmie@1 34 if (GBrowserIsCompatible())
gremmie@1 35 {
gremmie@1 36 $(window).unload(GUnload);
gremmie@1 37 mmap.map = new GMap2($('#member_map_map')[0]);
gremmie@1 38 mmap.map.setCenter(new GLatLng(15.0, -30.0), 2);
gremmie@1 39 mmap.map.enableScrollWheelZoom();
gremmie@1 40 mmap.map.addControl(new GLargeMapControl());
gremmie@1 41 mmap.map.addControl(new GMapTypeControl());
gremmie@1 42 mmap.geocoder = new GClientGeocoder();
gremmie@1 43
gremmie@1 44 if (mmapUser.userName)
gremmie@1 45 {
gremmie@1 46 $.getJSON('/member_map/query/',
gremmie@1 47 function(data) {
gremmie@1 48 mmap.map.clearOverlays();
gremmie@1 49 var sel = $('#member_map_members');
gremmie@1 50 sel[0].length = 0;
gremmie@1 51 mmap.clear();
gremmie@1 52 $.each(data.users, function(i, item) {
gremmie@1 53 sel.append($('<option />').html(item.name));
gremmie@1 54 var marker = new GMarker(new GLatLng(item.lat, item.lon));
gremmie@1 55 marker.bindInfoWindowHtml(item.message);
gremmie@1 56 mmap.map.addOverlay(marker);
gremmie@1 57 mmap.users[item.name] = item;
gremmie@1 58 mmap.users[item.name].marker = marker;
gremmie@1 59 if (mmapUser.userName == item.name)
gremmie@1 60 {
gremmie@1 61 mmap.userOnMap = true;
gremmie@1 62 }
gremmie@1 63 });
gremmie@1 64 sel[0].size = Math.min(29, data.users.length);
gremmie@1 65 $('#member_map_count').html(data.users.length);
gremmie@1 66
gremmie@1 67 sel = $('#member_map_recent');
gremmie@1 68 sel[0].length = 0;
gremmie@1 69 sel.append($('<option />').html(mmap.selectText));
gremmie@1 70 $.each(data.recent, function(i, item) {
gremmie@1 71 sel.append($('<option />').html(item));
gremmie@1 72 });
gremmie@1 73 var submitButton = $('#member_map_submit');
gremmie@1 74 var deleteButton = $('#member_map_delete');
gremmie@1 75
gremmie@1 76 submitButton.click(function() {
gremmie@1 77 if (mmap.geocoder)
gremmie@1 78 {
gremmie@1 79 $(this).attr('disabled', 'disabled').val('Updating Map...');
gremmie@1 80 var address = $('#id_location').val();
gremmie@1 81 mmap.geocoder.getLatLng(address,
gremmie@1 82 function(point) {
gremmie@1 83 if (!point)
gremmie@1 84 {
gremmie@1 85 alert(address + ' could not be found on Google Maps.');
gremmie@1 86 return;
gremmie@1 87 }
gremmie@1 88 $.post('/member_map/add/', {
gremmie@1 89 loc : address,
gremmie@1 90 lat : point.lat(),
gremmie@1 91 lon : point.lng(),
gremmie@1 92 msg : $('#id_message').val()
gremmie@1 93 },
gremmie@1 94 function(data, textStatus) {
gremmie@1 95 var wasOnMap = mmap.userOnMap;
gremmie@1 96 if (mmap.userOnMap)
gremmie@1 97 {
gremmie@1 98 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
gremmie@1 99 }
gremmie@1 100 else
gremmie@1 101 {
gremmie@1 102 $('#member_map_members').append($('<option />').html(data.name));
gremmie@1 103 mmap.userOnMap = true;
gremmie@1 104 deleteButton.removeAttr('disabled').val('Delete');
gremmie@1 105 }
gremmie@1 106 var marker = new GMarker(new GLatLng(data.lat, data.lon));
gremmie@1 107 marker.bindInfoWindowHtml(data.message);
gremmie@1 108 mmap.map.addOverlay(marker);
gremmie@1 109 mmap.users[mmapUser.userName] = data;
gremmie@1 110 mmap.users[mmapUser.userName].marker = marker;
gremmie@1 111 mmap.clickUser(mmapUser.userName);
gremmie@1 112 submitButton.removeAttr('disabled').val('Update');
gremmie@1 113 $('#member_map_directions').html(mmap.onMapDir);
gremmie@1 114 mmap.resizeUserList();
gremmie@1 115 alert(wasOnMap ? "Your location has been updated!" :
gremmie@1 116 "You've been added to the map!");
gremmie@1 117 },
gremmie@1 118 'json');
gremmie@1 119 });
gremmie@1 120 }
gremmie@1 121 return false;
gremmie@1 122 });
gremmie@1 123
gremmie@1 124 deleteButton.click(function() {
gremmie@1 125 deleteButton.attr('disabled', 'disabled').val('Deleting...');
gremmie@1 126 $.post('/member_map/delete/', function(data, textStatus) {
gremmie@1 127 $('#id_location').val('');
gremmie@1 128 $('#id_message').val('');
gremmie@1 129 $("#member_map_members option[value='" + mmapUser.userName + "']").remove();
gremmie@1 130 $("#member_map_recent option[value='" + mmapUser.userName + "']").remove();
gremmie@1 131 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
gremmie@1 132 mmap.users[mmapUser.userName].marker = null;
gremmie@1 133 mmap.users[mmapUser.userName] = null;
gremmie@1 134 mmap.userOnMap = false;
gremmie@1 135 deleteButton.val('Delete');
gremmie@1 136 submitButton.removeAttr('disabled').val('Add');
gremmie@1 137 $('#member_map_directions').html(mmap.offMapDir);
gremmie@1 138 mmap.resizeUserList();
gremmie@1 139 alert("You've been removed from the map.");
gremmie@1 140 },
gremmie@1 141 'text');
gremmie@1 142 return false;
gremmie@1 143 });
gremmie@1 144
gremmie@1 145 if (mmap.userOnMap)
gremmie@1 146 {
gremmie@1 147 submitButton.val('Update');
gremmie@1 148 $('#member_map_directions').html(mmap.onMapDir);
gremmie@1 149 }
gremmie@1 150 else
gremmie@1 151 {
gremmie@1 152 submitButton.val('Add');
gremmie@1 153 deleteButton.attr('disabled', 'disabled');
gremmie@1 154 $('#member_map_directions').html(mmap.offMapDir);
gremmie@1 155 }
gremmie@1 156 });
gremmie@1 157 $('#member_map_members').change(mmap.userClick);
gremmie@1 158 $('#member_map_recent').change(mmap.userClick);
gremmie@1 159 }
gremmie@1 160 }
gremmie@1 161 });