Vote buttons should be disabled while in use

Clicking quickly on up/down votes in forums generates a race condition
where the votes can continue going up or down (and I can get e.g. large
negative numbers). This is client-side; the server-side is not affected.

This is caused by safeAjax calling code (including updateWithUndo) not
handling the possible undefined return value. This is returned in the case
where the element that triggers the event is already disabled.

Corrected typo in DiscussionThreadView cleanup: @responseRequest -> @responsesRequest

Resolves TNL-1061
This commit is contained in:
Mat Moore
2015-01-05 15:19:08 +00:00
parent 55edd327ac
commit d857695d62
4 changed files with 28 additions and 2 deletions

View File

@@ -134,8 +134,12 @@ class @DiscussionUtil
@safeAjax: (params) ->
$elem = params.$elem
if $elem and $elem.attr("disabled")
return
deferred = $.Deferred()
deferred.reject()
return deferred.promise()
params["url"] = URI(params["url"]).addSearch ajax: 1
params["beforeSend"] = ->
if $elem

View File

@@ -127,7 +127,7 @@ if Backbone?
$loading: elem
takeFocus: true
complete: =>
@responseRequest = null
@responsesRequest = null
success: (data, textStatus, xhr) =>
Content.loadContentInfos(data['annotated_content_info'])
if @isQuestion()