Commit 40c86c91 authored by Fatih Acet's avatar Fatih Acet Committed by Z.J. van de Weg

Refactor awardsHandler methods to work with votesBlock.

parent f261be09
...@@ -32,7 +32,7 @@ class @AwardsHandler ...@@ -32,7 +32,7 @@ class @AwardsHandler
emoji = $target.find('.icon').data 'emoji' emoji = $target.find('.icon').data 'emoji'
$target.closest('.js-awards-block').addClass 'current' $target.closest('.js-awards-block').addClass 'current'
@addAward @getAwardUrl(), emoji @addAward @getVotesBlock(), @getAwardUrl(), emoji
showEmojiMenu: ($addBtn) -> showEmojiMenu: ($addBtn) ->
...@@ -100,23 +100,23 @@ class @AwardsHandler ...@@ -100,23 +100,23 @@ class @AwardsHandler
$menu.css(css) $menu.css(css)
addAward: (awardUrl, emoji, checkMutuality = yes) -> addAward: (votesBlock, awardUrl, emoji, checkMutuality = yes) ->
emoji = @normilizeEmojiName emoji emoji = @normilizeEmojiName emoji
@postEmoji awardUrl, emoji, => @postEmoji awardUrl, emoji, =>
@addAwardToEmojiBar emoji, checkMutuality @addAwardToEmojiBar votesBlock, emoji, checkMutuality
$('.emoji-menu').removeClass 'is-visible' $('.emoji-menu').removeClass 'is-visible'
addAwardToEmojiBar: (emoji, checkForMutuality = yes) -> addAwardToEmojiBar: (votesBlock, emoji, checkForMutuality = yes) ->
@checkMutuality emoji if checkForMutuality @checkMutuality votesBlock, emoji if checkForMutuality
@addEmojiToFrequentlyUsedList(emoji) @addEmojiToFrequentlyUsedList emoji
emoji = @normilizeEmojiName(emoji) emoji = @normilizeEmojiName emoji
$emojiBtn = @findEmojiIcon(emoji).parent() $emojiBtn = @findEmojiIcon(votesBlock, emoji).parent()
if $emojiBtn.length > 0 if $emojiBtn.length > 0
if @isActive $emojiBtn if @isActive $emojiBtn
...@@ -125,10 +125,10 @@ class @AwardsHandler ...@@ -125,10 +125,10 @@ class @AwardsHandler
counter = $emojiBtn.find '.js-counter' counter = $emojiBtn.find '.js-counter'
counter.text parseInt(counter.text()) + 1 counter.text parseInt(counter.text()) + 1
$emojiBtn.addClass 'active' $emojiBtn.addClass 'active'
@addMeToUserList emoji @addMeToUserList votesBlock, emoji
else else
@getVotesBlock().removeClass 'hidden' votesBlock.removeClass 'hidden'
@createEmoji emoji @createEmoji votesBlock, emoji
getVotesBlock: -> return $ '.js-awards-block.current' getVotesBlock: -> return $ '.js-awards-block.current'
...@@ -137,7 +137,7 @@ class @AwardsHandler ...@@ -137,7 +137,7 @@ class @AwardsHandler
getAwardUrl: -> return @getVotesBlock().data 'award-url' getAwardUrl: -> return @getVotesBlock().data 'award-url'
checkMutuality: (emoji) -> checkMutuality: (votesBlock, emoji) ->
awardUrl = @getAwardUrl() awardUrl = @getAwardUrl()
...@@ -145,8 +145,8 @@ class @AwardsHandler ...@@ -145,8 +145,8 @@ class @AwardsHandler
mutualVote = if emoji is 'thumbsup' then 'thumbsdown' else 'thumbsup' mutualVote = if emoji is 'thumbsup' then 'thumbsdown' else 'thumbsup'
selector = "[data-emoji=#{mutualVote}]" selector = "[data-emoji=#{mutualVote}]"
isAlreadyVoted = @getVotesBlock().find(selector).parent().hasClass 'active' isAlreadyVoted = votesBlock.find(selector).parent().hasClass 'active'
@addAward awardUrl, mutualVote, no if isAlreadyVoted @addAward votesBlock, awardUrl, mutualVote, no if isAlreadyVoted
isActive: ($emojiBtn) -> $emojiBtn.hasClass 'active' isActive: ($emojiBtn) -> $emojiBtn.hasClass 'active'
...@@ -155,20 +155,20 @@ class @AwardsHandler ...@@ -155,20 +155,20 @@ class @AwardsHandler
decrementCounter: ($emojiBtn, emoji) -> decrementCounter: ($emojiBtn, emoji) ->
counter = $('.js-counter', $emojiBtn) counter = $('.js-counter', $emojiBtn)
counterNumber = parseInt(counter.text()) counterNumber = parseInt counter.text(), 10
if counterNumber > 1 if counterNumber > 1
counter.text(counterNumber - 1) counter.text counterNumber - 1
@removeMeFromUserList($emojiBtn, emoji) @removeMeFromUserList $emojiBtn, emoji
else if emoji is 'thumbsup' or emoji is 'thumbsdown' else if emoji is 'thumbsup' or emoji is 'thumbsdown'
$emojiBtn.tooltip('destroy') $emojiBtn.tooltip 'destroy'
counter.text('0') counter.text '0'
@removeMeFromUserList($emojiBtn, emoji) @removeMeFromUserList $emojiBtn, emoji
@removeEmoji $emojiBtn if $emojiBtn.parents('.note').length @removeEmoji $emojiBtn if $emojiBtn.parents('.note').length
else else
@removeEmoji $emojiBtn @removeEmoji $emojiBtn
$emojiBtn.removeClass('active') $emojiBtn.removeClass 'active'
removeEmoji: ($emojiBtn) -> removeEmoji: ($emojiBtn) ->
...@@ -207,9 +207,9 @@ class @AwardsHandler ...@@ -207,9 +207,9 @@ class @AwardsHandler
@resetTooltip(awardBlock) @resetTooltip(awardBlock)
addMeToUserList: (emoji) -> addMeToUserList: (votesBlock, emoji) ->
awardBlock = @findEmojiIcon(emoji).parent() awardBlock = @findEmojiIcon(votesBlock, emoji).parent()
origTitle = @getAwardTooltip awardBlock origTitle = @getAwardTooltip awardBlock
users = [] users = []
...@@ -231,29 +231,29 @@ class @AwardsHandler ...@@ -231,29 +231,29 @@ class @AwardsHandler
), 200 ), 200
createEmoji_: (emoji) -> createEmoji_: (votesBlock, emoji) ->
emojiCssClass = @resolveNameToCssClass emoji emojiCssClass = @resolveNameToCssClass emoji
buttonHtml = "<button class='btn award-control js-emoji-btn has-tooltip active' title='me' data-placement='bottom'>
buttonHtml = "<button class='btn award-control js-emoji-btn has-tooltip active' title='me' data-placement='bottom'>
<div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div> <div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div>
<span class='award-control-text js-counter'>1</span> <span class='award-control-text js-counter'>1</span>
</button>" </button>"
emoji_node = $(buttonHtml) emoji_node = $(buttonHtml)
.insertBefore '.js-awards-block.current .js-award-holder:not(.js-award-action-btn)' .insertBefore votesBlock.find '.js-award-holder:not(.js-award-action-btn)'
.find '.emoji-icon' .find '.emoji-icon'
.data 'emoji', emoji .data 'emoji', emoji
$('.award-control').tooltip() $('.award-control').tooltip()
$('.js-awards-block.current').removeClass 'current' votesBlock.removeClass 'current'
createEmoji: (emoji) -> createEmoji: (votesBlock, emoji) ->
return @createEmoji_ emoji if $('.emoji-menu').length if $('.emoji-menu').length
return @createEmoji_ votesBlock, emoji
@createEmojiMenu @getAwardMenuUrl(), => @createEmoji emoji @createEmojiMenu @getAwardMenuUrl(), => @createEmoji votesBlock, emoji
getAwardMenuUrl: -> return gl.awardMenuUrl or '/emojis' getAwardMenuUrl: -> return gl.awardMenuUrl or '/emojis'
...@@ -278,14 +278,14 @@ class @AwardsHandler ...@@ -278,14 +278,14 @@ class @AwardsHandler
callback.call() if data.ok callback.call() if data.ok
findEmojiIcon: (emoji) -> findEmojiIcon: (votesBlock, emoji) ->
return $(".js-awards-block.current > .js-emoji-btn [data-emoji='#{emoji}']") return votesBlock.find ".js-emoji-btn [data-emoji='#{emoji}']"
scrollToAwards: -> scrollToAwards: ->
options = scrollTop: $('.awards').offset().top - 80 options = scrollTop: $('.awards').offset().top - 110
$('body, html').animate options, 200 $('body, html').animate options, 200
......
...@@ -167,7 +167,8 @@ class @Notes ...@@ -167,7 +167,8 @@ class @Notes
return return
if note.award if note.award
awardsHandler.addAwardToEmojiBar(note.name) votesBlock = $('.js-awards-block').eq 0
awardsHandler.addAwardToEmojiBar votesBlock, note.name
awardsHandler.scrollToAwards() awardsHandler.scrollToAwards()
# render note if it not present in loaded list # render note if it not present in loaded list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment