annotate media/js/forums.js @ 231:a2d388ed106e

Guard against the request object not having a user attribute in my Who's online middleware. This can happen if a redirect is issued before the authentication middleware gets to run.
author Brian Neal <bgneal@gmail.com>
date Wed, 14 Jul 2010 02:35:39 +0000
parents 13330e1836f3
children 8fd4984d5c3b
rev   line source
bgneal@89 1 $(document).ready(function() {
bgneal@89 2 var postText = $('#id_body');
bgneal@89 3 var postButton = $('#forums-reply-post');
bgneal@89 4 postButton.click(function () {
bgneal@89 5 var text = $.trim(postText.val());
bgneal@89 6 if (text.length == 0) {
bgneal@126 7 alert('Please enter some text.');
bgneal@89 8 return false;
bgneal@89 9 }
bgneal@89 10 $(this).attr('disabled', 'disabled').val('Posting reply...');
bgneal@89 11 $.ajax({
bgneal@89 12 url: '/forums/quick-reply/',
bgneal@89 13 type: 'POST',
bgneal@89 14 data: {
bgneal@89 15 body : postText.val(),
bgneal@89 16 topic_id : $('#id_topic_id').val()
bgneal@89 17 },
bgneal@89 18 dataType: 'html',
bgneal@89 19 success: function (data, textStatus) {
bgneal@89 20 postText.val('');
bgneal@89 21 $('#forum-topic tr:last').after(data);
bgneal@89 22 var lastTr = $('#forum-topic tr:last');
bgneal@89 23 lastTr.hide();
bgneal@89 24 lastTr.fadeIn(3000);
bgneal@89 25 postButton.removeAttr('disabled').val('Submit Reply');
bgneal@89 26 },
bgneal@89 27 error: function (xhr, textStatus, ex) {
bgneal@108 28 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@108 29 xhr.responseText);
bgneal@89 30 postButton.removeAttr('disabled').val('Submit Reply');
bgneal@89 31 }
bgneal@89 32 });
bgneal@89 33 return false;
bgneal@89 34 });
bgneal@98 35 $('a.post-flag').click(function () {
bgneal@98 36 var id = this.id;
bgneal@107 37 if (id.match(/fp-(\d+)/)) {
bgneal@98 38 id = RegExp.$1;
bgneal@98 39 if (confirm('Only flag a post if you feel it is spam, abuse, violates site rules, ' +
bgneal@98 40 'or is not appropriate. ' +
bgneal@98 41 'A moderator will be notified and will review the post. ' +
bgneal@98 42 'Are you sure you want to flag this post?')) {
bgneal@99 43 $.ajax({
bgneal@99 44 url: '/forums/flag-post/',
bgneal@99 45 type: 'POST',
bgneal@99 46 data: {id: id},
bgneal@99 47 dataType: 'text',
bgneal@99 48 success: function (response, textStatus) {
bgneal@99 49 alert(response);
bgneal@99 50 },
bgneal@99 51 error: function (xhr, textStatus, ex) {
bgneal@99 52 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@99 53 }
bgneal@99 54 });
bgneal@98 55 }
bgneal@98 56 }
bgneal@98 57 return false;
bgneal@98 58 });
bgneal@107 59 $('a.post-delete').click(function () {
bgneal@107 60 var id = this.id;
bgneal@107 61 if (id.match(/dp-(\d+)/)) {
bgneal@107 62 id = RegExp.$1;
bgneal@107 63 if (confirm('Are you sure you want to delete this post?')) {
bgneal@107 64 $.ajax({
bgneal@107 65 url: '/forums/delete-post/',
bgneal@107 66 type: 'POST',
bgneal@107 67 data: {id: id},
bgneal@107 68 dataType: 'text',
bgneal@107 69 success: function (response, textStatus) {
bgneal@107 70 alert(response);
bgneal@107 71 $('#post-' + id).fadeOut(3000);
bgneal@107 72 },
bgneal@107 73 error: function (xhr, textStatus, ex) {
bgneal@107 74 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@107 75 }
bgneal@107 76 });
bgneal@107 77 }
bgneal@107 78 }
bgneal@107 79 return false;
bgneal@107 80 });
bgneal@109 81 $('#forum-mod-del-topic').click(function () {
bgneal@109 82 return confirm('Are you sure you want to delete this topic?\n' +
bgneal@109 83 'WARNING: all posts will be lost.');
bgneal@109 84 });
bgneal@89 85 });