debian-mirror-gitlab/app/assets/javascripts/star.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import Flash from './flash';
2017-09-10 17:25:29 +05:30
import { __, s__ } from './locale';
2018-03-17 18:26:18 +05:30
import { spriteIcon } from './lib/utils/common_utils';
2018-03-27 19:54:05 +05:30
import axios from './lib/utils/axios_utils';
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
export default class Star {
constructor() {
2018-03-27 19:54:05 +05:30
$('.project-home-panel .toggle-star').on('click', function toggleStarClickCallback() {
const $this = $(this);
const $starSpan = $this.find('span');
const $startIcon = $this.find('svg');
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
axios.post($this.data('endpoint'))
.then(({ data }) => {
const isStarred = $starSpan.hasClass('starred');
2018-03-17 18:26:18 +05:30
$this.parent().find('.star-count').text(data.star_count);
2018-03-27 19:54:05 +05:30
2018-03-17 18:26:18 +05:30
if (isStarred) {
$starSpan.removeClass('starred').text(s__('StarProject|Star'));
$startIcon.remove();
$this.prepend(spriteIcon('star-o'));
} else {
$starSpan.addClass('starred').text(__('Unstar'));
$startIcon.remove();
$this.prepend(spriteIcon('star'));
}
2018-03-27 19:54:05 +05:30
})
.catch(() => Flash('Star toggle failed. Try again later.'));
});
2017-09-10 17:25:29 +05:30
}
}