2015-12-23 20:36:29 -05:00
|
|
|
class @Star
|
|
|
|
constructor: ->
|
|
|
|
$('.project-home-panel .toggle-star').on('ajax:success', (e, data, status, xhr) ->
|
|
|
|
$this = $(this)
|
|
|
|
$starSpan = $this.find('span')
|
|
|
|
$starIcon = $this.find('i')
|
|
|
|
|
|
|
|
toggleStar = (isStarred) ->
|
2016-01-19 11:48:43 -05:00
|
|
|
$this.parent().find('.star-count').text data.star_count
|
2015-12-23 20:36:29 -05:00
|
|
|
if isStarred
|
|
|
|
$starSpan.removeClass('starred').text 'Star'
|
|
|
|
$starIcon.removeClass('fa-star').addClass 'fa-star-o'
|
|
|
|
else
|
|
|
|
$starSpan.addClass('starred').text 'Unstar'
|
|
|
|
$starIcon.removeClass('fa-star-o').addClass 'fa-star'
|
|
|
|
return
|
|
|
|
|
|
|
|
toggleStar $starSpan.hasClass('starred')
|
|
|
|
return
|
|
|
|
).on 'ajax:error', (e, xhr, status, error) ->
|
|
|
|
new Flash('Star toggle failed. Try again later.', 'alert')
|
2016-01-19 11:48:43 -05:00
|
|
|
return
|