BigW Consortium Gitlab

star.js 1.11 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-unused-vars, one-var, no-var, one-var-declaration-per-line, prefer-arrow-callback, no-new, max-len */
2 3
/* global Flash */

4 5
import { __, s__ } from './locale';

6
export default class Star {
7
  constructor() {
8 9 10 11 12 13 14 15
    $('.project-home-panel .toggle-star').on('ajax:success', function(e, data, status, xhr) {
      var $starIcon, $starSpan, $this, toggleStar;
      $this = $(this);
      $starSpan = $this.find('span');
      $starIcon = $this.find('i');
      toggleStar = function(isStarred) {
        $this.parent().find('.star-count').text(data.star_count);
        if (isStarred) {
16
          $starSpan.removeClass('starred').text(s__('StarProject|Star'));
17 18
          $starIcon.removeClass('fa-star').addClass('fa-star-o');
        } else {
19
          $starSpan.addClass('starred').text(__('Unstar'));
20 21 22 23 24 25 26 27
          $starIcon.removeClass('fa-star-o').addClass('fa-star');
        }
      };
      toggleStar($starSpan.hasClass('starred'));
    }).on('ajax:error', function(e, xhr, status, error) {
      new Flash('Star toggle failed. Try again later.', 'alert');
    });
  }
28
}