Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-05-24 20:47:10 +0300
committerFatih Acet <acetfatih@gmail.com>2016-05-24 20:47:10 +0300
commit20e6e0dbe609f7b0fdd480281223a1a98d645f34 (patch)
treeb3d517b9ceafb2c2a737f1539a53e67164288873 /app/assets/javascripts/awards_handler.coffee
parentb0082bec7305f9bf4322d8d532807e5607f5655a (diff)
Handle posting emoji only vote +1 and -1 comments.
And remove mutual votes.
Diffstat (limited to 'app/assets/javascripts/awards_handler.coffee')
-rw-r--r--app/assets/javascripts/awards_handler.coffee54
1 files changed, 30 insertions, 24 deletions
diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee
index b4a341675bd..67f04dcac73 100644
--- a/app/assets/javascripts/awards_handler.coffee
+++ b/app/assets/javascripts/awards_handler.coffee
@@ -25,26 +25,9 @@ class @AwardsHandler
e.preventDefault()
- $emojiBtn = $(e.currentTarget)
- $addAwardBtn = $('.js-add-award.is-active')
- $votesBlock = $($addAwardBtn.closest('.js-award-holder').data('target'))
-
- if $addAwardBtn.length is 0
- $votesBlock = $emojiBtn.closest('.js-awards-block')
- else if $votesBlock.length is 0
- $votesBlock = $addAwardBtn.closest('.js-awards-block')
-
- $votesBlock.addClass 'js-awards-block'
- awardUrl = $votesBlock.data 'award-url'
- emoji = $emojiBtn.find('.icon').data('emoji')
-
- if emoji in [ 'thumbsup', 'thumbsdown' ]
- mutualVote = if emoji is 'thumbsup' then 'thumbsdown' else 'thumbsup'
-
- isAlreadyVoted = $("[data-emoji=#{mutualVote}]").parent().hasClass 'active'
- @addAward awardUrl, mutualVote if isAlreadyVoted
-
- @addAward awardUrl, emoji
+ emoji = $(e.currentTarget).find('.icon').data 'emoji'
+ @getVotesBlock().addClass 'js-awards-block'
+ @addAward @getAwardUrl(), emoji
showEmojiMenu: ($addBtn) ->
@@ -105,16 +88,21 @@ class @AwardsHandler
$menu.css(css)
- addAward: (awardUrl, emoji) ->
+
+ addAward: (awardUrl, emoji, checkMutuality = yes) ->
+
emoji = @normilizeEmojiName(emoji)
@postEmoji awardUrl, emoji, =>
- @addAwardToEmojiBar(emoji)
+ @addAwardToEmojiBar(emoji, checkMutuality)
$('.js-awards-block-current').removeClass 'js-awards-block-current'
- $(".emoji-menu").removeClass "is-visible"
+ $('.emoji-menu').removeClass 'is-visible'
- addAwardToEmojiBar: (emoji) ->
+
+ addAwardToEmojiBar: (emoji, checkForMutuality = yes) ->
+
+ @checkMutuality emoji if checkForMutuality
@addEmojiToFrequentlyUsedList(emoji)
emoji = @normilizeEmojiName(emoji)
@@ -131,6 +119,24 @@ class @AwardsHandler
else
@createEmoji(emoji)
+
+ getVotesBlock: -> return $ '.awards.js-awards-block'
+
+
+ getAwardUrl: -> @getVotesBlock().data 'award-url'
+
+
+ checkMutuality: (emoji) ->
+
+ awardUrl = @getAwardUrl()
+
+ if emoji in [ 'thumbsup', 'thumbsdown' ]
+ mutualVote = if emoji is 'thumbsup' then 'thumbsdown' else 'thumbsup'
+
+ isAlreadyVoted = $("[data-emoji=#{mutualVote}]").parent().hasClass 'active'
+ @addAward awardUrl, mutualVote, no if isAlreadyVoted
+
+
isActive: ($emojiBtn) ->
$emojiBtn.hasClass("active")