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';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
export default class Star {
|
|
|
|
constructor() {
|
2018-03-17 18:26:18 +05:30
|
|
|
$('.project-home-panel .toggle-star')
|
|
|
|
.on('ajax:success', function handleSuccess(e, data) {
|
|
|
|
const $this = $(this);
|
|
|
|
const $starSpan = $this.find('span');
|
|
|
|
const $startIcon = $this.find('svg');
|
|
|
|
|
|
|
|
function toggleStar(isStarred) {
|
|
|
|
$this.parent().find('.star-count').text(data.star_count);
|
|
|
|
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'));
|
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
toggleStar($starSpan.hasClass('starred'));
|
|
|
|
})
|
|
|
|
.on('ajax:error', () => {
|
|
|
|
Flash('Star toggle failed. Try again later.', 'alert');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
}
|