BigW Consortium Gitlab

star.js 1.02 KB
Newer Older
1
import Flash from './flash';
2
import { __, s__ } from './locale';
3
import { spriteIcon } from './lib/utils/common_utils';
4

5
export default class Star {
6
  constructor() {
7 8 9 10
    $('.project-home-panel .toggle-star')
      .on('ajax:success', function handleSuccess(e, data) {
        const $this = $(this);
        const $starSpan = $this.find('span');
11
        const $startIcon = $this.find('svg');
12 13 14 15 16

        function toggleStar(isStarred) {
          $this.parent().find('.star-count').text(data.star_count);
          if (isStarred) {
            $starSpan.removeClass('starred').text(s__('StarProject|Star'));
17 18
            $startIcon.remove();
            $this.prepend(spriteIcon('star-o'));
19 20
          } else {
            $starSpan.addClass('starred').text(__('Unstar'));
21 22
            $startIcon.remove();
            $this.prepend(spriteIcon('star'));
23
          }
24
        }
25 26 27 28 29 30

        toggleStar($starSpan.hasClass('starred'));
      })
      .on('ajax:error', () => {
        Flash('Star toggle failed. Try again later.', 'alert');
      });
31
  }
32
}