# HG changeset patch # User Brian Neal # Date 1261023256 0 # Node ID b43e1288ff805f87359207944ba841afbe7be122 # Parent ab7830b067b3caa4d507acd5c59b8c6046d659d1 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. diff -r ab7830b067b3 -r b43e1288ff80 gpp/templates/shoutbox/shout_detail.html --- a/gpp/templates/shoutbox/shout_detail.html Mon Dec 14 05:07:28 2009 +0000 +++ b/gpp/templates/shoutbox/shout_detail.html Thu Dec 17 04:14:16 2009 +0000 @@ -13,9 +13,8 @@ Permalink Flag -{% ifequal user shout.user %} -Delete +{% ifequal user.id shout.user.id %} +Delete {% endifequal %} diff -r ab7830b067b3 -r b43e1288ff80 media/js/downloads/rating.js --- a/media/js/downloads/rating.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/downloads/rating.js Thu Dec 17 04:14:16 2009 +0000 @@ -26,8 +26,12 @@ var id = star.attr('id'); if (id.match(/star-(\d+)-(\d+)/)) { - $.post('/downloads/rate/', { id: RegExp.$1, rating: parseInt(RegExp.$2) + 1}, - function(rating) { + $.ajax({ + url: '/downloads/rate/', + type: 'POST', + data: { id: RegExp.$1, rating: parseInt(RegExp.$2) + 1}, + dataType: 'text', + success: function(rating) { rating = parseFloat(rating); if (rating < 0) { @@ -61,7 +65,11 @@ } } }, - 'text'); + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } diff -r ab7830b067b3 -r b43e1288ff80 media/js/gcalendar_edit.js --- a/media/js/gcalendar_edit.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/gcalendar_edit.js Thu Dec 17 04:14:16 2009 +0000 @@ -3,12 +3,22 @@ if (confirm('Really delete this event?')) { var id = this.id; if (id.match(/gcal-(\d+)/)) { - $.post('/calendar/delete/', { id : RegExp.$1 }, function (id) { - var id = '#gcal-' + id; - $(id).parents('li').hide('normal'); - }, 'text'); + $.ajax({ + url: '/calendar/delete/', + type: 'POST', + data: { id : RegExp.$1 }, + dataType: 'text', + success: function (id) { + var id = '#gcal-' + id; + $(id).parents('li').hide('normal'); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } return false; - }); + }); }); diff -r ab7830b067b3 -r b43e1288ff80 media/js/membermap.js --- a/media/js/membermap.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/membermap.js Thu Dec 17 04:14:16 2009 +0000 @@ -84,13 +84,17 @@ alert(address + ' could not be found on Google Maps.'); return; } - $.post('/member_map/add/', { - loc : address, - lat : point.lat(), - lon : point.lng(), - msg : $('#id_message').val() + $.ajax({ + url: '/member_map/add/', + type: 'POST', + data: { + loc : address, + lat : point.lat(), + lon : point.lng(), + msg : $('#id_message').val() }, - function(data, textStatus) { + dataType: 'json', + success: function(data, textStatus) { var wasOnMap = mmap.userOnMap; if (mmap.userOnMap) { @@ -114,7 +118,11 @@ alert(wasOnMap ? "Your location has been updated!" : "You've been added to the map!"); }, - 'json'); + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); }); } return false; @@ -122,7 +130,11 @@ deleteButton.click(function() { deleteButton.attr('disabled', 'disabled').val('Deleting...'); - $.post('/member_map/delete/', function(data, textStatus) { + $.ajax({ + url: '/member_map/delete/', + type: 'POST', + dataType: 'text', + success: function(data, textStatus) { $('#id_location').val(''); $('#id_message').val(''); $("#member_map_members option[value='" + mmapUser.userName + "']").remove(); @@ -137,7 +149,11 @@ mmap.resizeUserList(); alert("You've been removed from the map."); }, - 'text'); + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); return false; }); diff -r ab7830b067b3 -r b43e1288ff80 media/js/shoutbox.js --- a/media/js/shoutbox.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/shoutbox.js Thu Dec 17 04:14:16 2009 +0000 @@ -7,10 +7,12 @@ return false; } submit.attr('disabled', 'disabled'); - $.post('/shout/shout/', { - msg: msg - }, - function (data, textStatus) { + $.ajax({ + url: '/shout/shout/', + type: 'POST', + data: { msg: msg }, + dataType: 'html', + success: function (data, textStatus) { input.val(''); if (data != '') { $('#shoutbox-shout-container').prepend(data); @@ -18,7 +20,11 @@ } submit.removeAttr('disabled'); }, - 'html'); + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); return false; }); var smilies_loaded = false; diff -r ab7830b067b3 -r b43e1288ff80 media/js/shoutbox_app.js --- a/media/js/shoutbox_app.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/shoutbox_app.js Thu Dec 17 04:14:16 2009 +0000 @@ -11,13 +11,23 @@ if (confirm('Really delete this shout?')) { var id = this.id; if (id.match(/^shout-del-(\d+)/)) { - $.post('/shout/delete/', { id : RegExp.$1 }, function (id) { + $.ajax({ + url: '/shout/delete/', + type: 'POST', + data: { id : RegExp.$1 }, + dataType: 'text', + success: function (id) { var id = '#shout-del-' + id; $(id).parents('tr').fadeOut(1500, function () { $('div.shoutbox-history table tr:visible:even').removeClass('odd'); $('div.shoutbox-history table tr:visible:odd').addClass('odd'); }); - }, 'text'); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } return false; @@ -30,11 +40,21 @@ 'or is not appropriate. ' + 'A moderator will be notified and will review the shout. ' + 'Are you sure you want to flag this shout?')) { - $.post('/shout/flag/', { id : id }, function(response) { - alert(response); - }, 'text'); + $.ajax({ + url: '/shout/flag/', + type: 'POST', + data: { id : id }, + dataType: 'text', + success: function(response) { + alert(response); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } return false; }); - }); +});