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-12-13 13:39:08 +05:30
|
|
|
axios
|
|
|
|
.post($this.data('endpoint'))
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(({ data }) => {
|
|
|
|
const isStarred = $starSpan.hasClass('starred');
|
2018-12-13 13:39:08 +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();
|
2019-01-03 12:48:30 +05:30
|
|
|
$this.prepend(spriteIcon('star-o'));
|
2018-03-17 18:26:18 +05:30
|
|
|
} else {
|
|
|
|
$starSpan.addClass('starred').text(__('Unstar'));
|
|
|
|
$startIcon.remove();
|
2019-01-03 12:48:30 +05:30
|
|
|
$this.prepend(spriteIcon('star'));
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
})
|
|
|
|
.catch(() => Flash('Star toggle failed. Try again later.'));
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
}
|