summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/star.js.coffee
blob: f27780dda931d712facd77389375280e2f761e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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) ->
        $this.parent().find('.star-count').text data.star_count
        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')
      return