From: Matthias Schmidt Date: Thu, 27 Mar 2014 15:16:14 +0000 (+0100) Subject: Allow guests to use the comment system X-Git-Tag: 2.1.0_Alpha_1~952 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b9f4bd6989b58417ee5ffde706edd5b3d94310d2;p=GitHub%2FWoltLab%2FWCF.git Allow guests to use the comment system --- diff --git a/com.woltlab.wcf/templates/__commentJavaScript.tpl b/com.woltlab.wcf/templates/__commentJavaScript.tpl index 307ea7b42b..55f3a12fd7 100644 --- a/com.woltlab.wcf/templates/__commentJavaScript.tpl +++ b/com.woltlab.wcf/templates/__commentJavaScript.tpl @@ -1,5 +1,8 @@ +{if !$__wcf->user->userID} + +{/if} +
+ {if !$ajaxRecaptcha|isset || !$ajaxRecaptcha} + + {/if}
- {if $errorField == 'recaptchaString'} + {if $errorField|isset && $errorField == 'recaptchaString'} {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} {if $errorType == 'false'}{lang}wcf.recaptcha.error.recaptchaString.false{/lang}{/if} @@ -37,19 +39,30 @@
- - + {if !$ajaxRecaptcha|isset || !$ajaxRecaptcha} + + + {else} + + {/if}
diff --git a/com.woltlab.wcf/userOption.xml b/com.woltlab.wcf/userOption.xml index 683bd4321f..08a21e0feb 100644 --- a/com.woltlab.wcf/userOption.xml +++ b/com.woltlab.wcf/userOption.xml @@ -247,7 +247,8 @@ settings.privacy.messaging select 3 - 1 diff --git a/wcfsetup/install/files/js/WCF.Comment.js b/wcfsetup/install/files/js/WCF.Comment.js index 6a70cbfd42..60aafbaa3c 100644 --- a/wcfsetup/install/files/js/WCF.Comment.js +++ b/wcfsetup/install/files/js/WCF.Comment.js @@ -1,7 +1,7 @@ /** * Namespace for comments */ -WCF.Comment = {}; +WCF.Comment = { }; /** * Comment support for WCF @@ -77,6 +77,24 @@ WCF.Comment.Handler = Class.extend({ */ _userAvatar: '', + /** + * data of the comment the active guest user is about to create + * @var object + */ + _commentData: { }, + + /** + * guest dialog with username input field and recaptcha + * @var jQuery + */ + _guestDialog: null, + + /** + * true if the guest has to solve a recaptcha challenge to save the comment + * @var boolean + */ + _useRecaptcha: true, + /** * Initializes the WCF.Comment.Handler class. * @@ -100,6 +118,7 @@ WCF.Comment.Handler = Class.extend({ } this._proxy = new WCF.Action.Proxy({ + failure: $.proxy(this._failure, this), success: $.proxy(this._success, this) }); @@ -437,17 +456,45 @@ WCF.Comment.Handler = Class.extend({ $data.commentID = $input.data('commentID'); } - this._proxy.setOption('data', { - actionName: $actionName, - className: 'wcf\\data\\comment\\CommentAction', - parameters: { - data: $data + if (!WCF.User.userID) { + this._commentData = $data; + + // check if guest dialog has already been loaded + if (this._guestDialog === null) { + this._proxy.setOption('data', { + actionName: 'getGuestDialog', + className: 'wcf\\data\\comment\\CommentAction', + parameters: { + data: { + message: $value, + objectID: this._container.data('objectID'), + objectTypeID: this._container.data('objectTypeID') + } + } + }); + this._proxy.sendRequest(); } - }); - this._proxy.sendRequest(); - - // reset input - //$input.val('').blur(); + else { + // request a new recaptcha + if (this._useRecaptcha) { + Recaptcha.reload(); + } + + this._guestDialog.find('input[type="submit"]').enable(); + + this._guestDialog.wcfDialog('open'); + } + } + else { + this._proxy.setOption('data', { + actionName: $actionName, + className: 'wcf\\data\\comment\\CommentAction', + parameters: { + data: $data + } + }); + this._proxy.sendRequest(); + } }, /** @@ -482,6 +529,24 @@ WCF.Comment.Handler = Class.extend({ }, this)); }, + /** + * Handles a failed AJAX request. + * + * @param object data + * @param object jqXHR + * @param string textStatus + * @param string errorThrown + * @return boolean + */ + _failure: function(data, jqXHR, textStatus, errorThrown) { + if (!WCF.User.userID && this._guestDialog) { + // enable submit button again + this._guestDialog.find('input[type="submit"]').enable(); + } + + return true; + }, + /** * Handles successful AJAX requests. * @@ -492,17 +557,35 @@ WCF.Comment.Handler = Class.extend({ _success: function(data, textStatus, jqXHR) { switch (data.actionName) { case 'addComment': - this._commentAdd.find('input').val('').blur(); - $(data.returnValues.template).insertAfter(this._commentAdd).wcfFadeIn(); + if (data.returnValues.errors) { + this._handleGuestDialogErrors(data.returnValues.errors); + } + else { + this._commentAdd.find('input').val('').blur(); + $(data.returnValues.template).insertAfter(this._commentAdd).wcfFadeIn(); + + if (!WCF.User.userID) { + this._guestDialog.wcfDialog('close'); + } + } break; case 'addResponse': - var $comment = this._comments[data.returnValues.commentID]; - $comment.find('.jsCommentResponseAdd input').val('').blur(); + if (data.returnValues.errors) { + this._handleGuestDialogErrors(data.returnValues.errors); + } + else { + var $comment = this._comments[data.returnValues.commentID]; + $comment.find('.jsCommentResponseAdd input').val('').blur(); + + var $responseList = $comment.find('ul.commentResponseList'); + if (!$responseList.length) $responseList = $('