From 8c8d1986e041b6a01f9bdb47c955889b11e4227a Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Tue, 14 Aug 2007 04:40:14 +0000 Subject: [PATCH] Improved spam protection question updating. Now refreshes immediately after posting the form, no matter if you get it right or wrong. More consistent notification if you get the question wrong (same box used as other notifications). git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39982 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/PageCommentInterface.js | 66 ++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/javascript/PageCommentInterface.js b/javascript/PageCommentInterface.js index b35fe99b..fae9a6ac 100755 --- a/javascript/PageCommentInterface.js +++ b/javascript/PageCommentInterface.js @@ -26,6 +26,12 @@ PageCommentInterface.prototype = { }); }, + loadSpamQuestion: function(response) { + var spamQuestionDiv = $('Math'); + var mathLabel = spamQuestionDiv.getElementsByTagName('label')[0]; + mathLabel.innerHTML = response.responseText; + }, + postComment: function() { var form = $("PageCommentInterface_Form_PageCommentsPostCommentForm"); var message = $("PageCommentInterface_Form_PageCommentsPostCommentForm_error"); @@ -44,28 +50,57 @@ PageCommentInterface.prototype = { var pageComments = $('PageComments').getElementsByTagName('li'); var __newComment = document.createElement('li'); - // Add it to the list with a 'loading' message + + // Add it to the list with a 'loading' message $('PageComments').insertBefore(__newComment, pageComments[0]); __newComment.innerHTML = '

Loading...

'; - + __newComment.className ="even"; + // Submit the form via ajax Ajax.SubmitForm(form, "action_postcomment", { onSuccess : function(response) { - // Load the response into the new
  • - __newComment.innerHTML = response.responseText; - Behaviour.apply(__newComment); - // Flash it using Scriptaculous - new Effect.Highlight(__newComment, { endcolor: '#e9e9e9' } ); - if(response.responseText.match('Spam detected!!')) { - __newComment.className = 'spam'; + // Create an Ajax request to regenerate the spam protection question + //need to check if there is actually a spam question to change first + if(form.elements.Math){ + new Ajax.Request(document.getElementsByTagName('base')[0].href+'PageCommentInterface_Controller/newspamquestion', { + onSuccess: loadSpamQuestion, + onFailure: Ajax.Evaluator + }); + } + + if(response.responseText != "spamprotectionfalied"){ + + // Load the response into the new
  • + __newComment.innerHTML = response.responseText; + Behaviour.apply(__newComment); + + // Flash it using Scriptaculous + new Effect.Highlight(__newComment, { endcolor: '#e9e9e9' } ); + if(response.responseText.match('Spam detected!!')) { + __newComment.className = 'spam'; + } + + }else{ + __newComment.innerHTML = ""; + Behaviour.apply(__newComment); + message.style.display = ''; + message.innerHTML = "You got the spam question wrong."; + + } + + + }, + onFailure : function(response) { + alert(response.responseText); } - }, - onFailure : function(response) { - alert(response.responseText); - } + + + }); + + // Clear the fields // form.elements.Name.value = ""; @@ -214,3 +249,8 @@ PageCommentInterface.prototype = { } PageCommentInterface.applyTo("#PageComments_holder"); +function loadSpamQuestion(response) { + var spamQuestionDiv = $('Math'); + var mathLabel = spamQuestionDiv.getElementsByTagName('label')[0]; + mathLabel.innerHTML = response.responseText; +}