Mercurial > public > sg101
changeset 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 | ab7830b067b3 |
children | e1d1a70d312d |
files | gpp/templates/shoutbox/shout_detail.html media/js/downloads/rating.js media/js/gcalendar_edit.js media/js/membermap.js media/js/shoutbox.js media/js/shoutbox_app.js |
diffstat | 6 files changed, 90 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <a href="{% url shoutbox-view shout.id %}"><img src="{{ MEDIA_URL }}icons/link.png" alt="Permalink" title="Permalink" /></a> <a href="#" class="shout-flag" id="shout-flag-{{ shout.id }}"><img src="{{ MEDIA_URL }}icons/flag_red.png" alt="Flag" title="Flag this shout as offensive" /></a> -{% ifequal user shout.user %} -<a href="#" class="shout-del" id="shout-del-{{ shout.id }}"><img src="{{ MEDIA_URL }}icons/cross.png" alt="Delete" - title="Delete this shout" /></a> +{% ifequal user.id shout.user.id %} +<a href="#" class="shout-del" id="shout-del-{{ shout.id }}"><img src="{{ MEDIA_URL }}icons/cross.png" alt="Delete" title="Delete this shout" /></a> {% endifequal %} </td> </tr>
--- 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); + } + }); } }
--- 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; - }); + }); });
--- 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; });
--- 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;
--- 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; }); - }); +});