# HG changeset patch # User Brian Neal # Date 1258230631 0 # Node ID b0d62247c3e4e1576845af68bb46add48644e333 # Parent 903ae6168071e7627f46401f50875a779b918f2a Add some javascript to check for posting a blank comment. Change wording on forum error message for the same thing. diff -r 903ae6168071 -r b0d62247c3e4 media/js/comments.js --- a/media/js/comments.js Sat Nov 14 20:09:17 2009 +0000 +++ b/media/js/comments.js Sat Nov 14 20:30:31 2009 +0000 @@ -1,24 +1,40 @@ $(document).ready(function() { - $('#comment-form-post').click(function () { - $(this).attr('disabled', 'disabled').val('Posting Comment...'); - $.post('/comments/post/', { - comment : $('#id_comment').val(), - content_type : $('#id_content_type').val(), - object_pk : $('#id_object_pk').val() + var postText = $('#id_comment'); + var postButton = $('#comment-form-post'); + postButton.click(function () { + var text = $.trim(postText.val()); + if (text.length == 0) { + alert('Please enter some text.'); + return false; + } + postButton.attr('disabled', 'disabled').val('Posting Comment...'); + $.ajax({ + url: '/comments/post/', + type: 'POST', + data: { + comment : text, + content_type : $('#id_content_type').val(), + object_pk : $('#id_object_pk').val() }, - function (data, textStatus) { - $('#id_comment').val(''); + dataType: 'html', + success: function (data, textStatus) { + postText.val(''); $('#comment-list').append(data); var lastLi = $('#comment-list > li:last'); lastLi.hide(); lastLi.fadeIn(3000); - $('#comment-form-post').removeAttr('disabled').val('Post Comment'); + postButton.removeAttr('disabled').val('Post Comment'); var count = $('#comment-count'); if (count.length) { count.html(parseInt(count.html()) + 1); } }, - 'html'); + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + postButton.removeAttr('disabled').val('Post Comment'); + } + }); return false; }); $('a.comment-flag').click(function () { @@ -45,5 +61,5 @@ } return false; }); - $('#id_comment').markItUp(mySettings); + postText.markItUp(mySettings); }); diff -r 903ae6168071 -r b0d62247c3e4 media/js/forums.js --- a/media/js/forums.js Sat Nov 14 20:09:17 2009 +0000 +++ b/media/js/forums.js Sat Nov 14 20:30:31 2009 +0000 @@ -4,7 +4,7 @@ postButton.click(function () { var text = $.trim(postText.val()); if (text.length == 0) { - alert('Please enter some reply text.'); + alert('Please enter some text.'); return false; } $(this).attr('disabled', 'disabled').val('Posting reply...');