comparison media/js/membermap.js @ 150:b43e1288ff80

Fix #33; use $.ajax instead of $.post so we can handle errors. Also, for some reason comparing objects in a template doesn't work now. Have to compare id fields.
author Brian Neal <bgneal@gmail.com>
date Thu, 17 Dec 2009 04:14:16 +0000
parents c515b7401078
children 13d052fbe4f1
comparison
equal deleted inserted replaced
149:ab7830b067b3 150:b43e1288ff80
82 if (!point) 82 if (!point)
83 { 83 {
84 alert(address + ' could not be found on Google Maps.'); 84 alert(address + ' could not be found on Google Maps.');
85 return; 85 return;
86 } 86 }
87 $.post('/member_map/add/', { 87 $.ajax({
88 loc : address, 88 url: '/member_map/add/',
89 lat : point.lat(), 89 type: 'POST',
90 lon : point.lng(), 90 data: {
91 msg : $('#id_message').val() 91 loc : address,
92 lat : point.lat(),
93 lon : point.lng(),
94 msg : $('#id_message').val()
92 }, 95 },
93 function(data, textStatus) { 96 dataType: 'json',
97 success: function(data, textStatus) {
94 var wasOnMap = mmap.userOnMap; 98 var wasOnMap = mmap.userOnMap;
95 if (mmap.userOnMap) 99 if (mmap.userOnMap)
96 { 100 {
97 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker); 101 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
98 } 102 }
112 $('#member_map_directions').html(mmap.onMapDir); 116 $('#member_map_directions').html(mmap.onMapDir);
113 mmap.resizeUserList(); 117 mmap.resizeUserList();
114 alert(wasOnMap ? "Your location has been updated!" : 118 alert(wasOnMap ? "Your location has been updated!" :
115 "You've been added to the map!"); 119 "You've been added to the map!");
116 }, 120 },
117 'json'); 121 error: function (xhr, textStatus, ex) {
122 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
123 xhr.responseText);
124 }
125 });
118 }); 126 });
119 } 127 }
120 return false; 128 return false;
121 }); 129 });
122 130
123 deleteButton.click(function() { 131 deleteButton.click(function() {
124 deleteButton.attr('disabled', 'disabled').val('Deleting...'); 132 deleteButton.attr('disabled', 'disabled').val('Deleting...');
125 $.post('/member_map/delete/', function(data, textStatus) { 133 $.ajax({
134 url: '/member_map/delete/',
135 type: 'POST',
136 dataType: 'text',
137 success: function(data, textStatus) {
126 $('#id_location').val(''); 138 $('#id_location').val('');
127 $('#id_message').val(''); 139 $('#id_message').val('');
128 $("#member_map_members option[value='" + mmapUser.userName + "']").remove(); 140 $("#member_map_members option[value='" + mmapUser.userName + "']").remove();
129 $("#member_map_recent option[value='" + mmapUser.userName + "']").remove(); 141 $("#member_map_recent option[value='" + mmapUser.userName + "']").remove();
130 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker); 142 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
135 submitButton.removeAttr('disabled').val('Add'); 147 submitButton.removeAttr('disabled').val('Add');
136 $('#member_map_directions').html(mmap.offMapDir); 148 $('#member_map_directions').html(mmap.offMapDir);
137 mmap.resizeUserList(); 149 mmap.resizeUserList();
138 alert("You've been removed from the map."); 150 alert("You've been removed from the map.");
139 }, 151 },
140 'text'); 152 error: function (xhr, textStatus, ex) {
153 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
154 xhr.responseText);
155 }
156 });
141 return false; 157 return false;
142 }); 158 });
143 159
144 if (mmap.userOnMap) 160 if (mmap.userOnMap)
145 { 161 {