2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-10-02 08:32:53 -04:00
|
|
|
import Flash from './flash';
|
2017-07-21 06:43:04 -04:00
|
|
|
import { __, s__ } from './locale';
|
2017-11-23 02:52:15 -05:00
|
|
|
import { spriteIcon } from './lib/utils/common_utils';
|
2018-02-20 17:20:48 -05:00
|
|
|
import axios from './lib/utils/axios_utils';
|
2017-07-21 06:43:04 -04:00
|
|
|
|
2017-07-06 14:19:41 -04:00
|
|
|
export default class Star {
|
2017-06-30 17:27:31 -04:00
|
|
|
constructor() {
|
2018-02-20 17:20:48 -05:00
|
|
|
$('.project-home-panel .toggle-star').on('click', function toggleStarClickCallback() {
|
|
|
|
const $this = $(this);
|
|
|
|
const $starSpan = $this.find('span');
|
|
|
|
const $startIcon = $this.find('svg');
|
2017-10-11 04:10:35 -04:00
|
|
|
|
2018-02-20 17:20:48 -05:00
|
|
|
axios.post($this.data('endpoint'))
|
|
|
|
.then(({ data }) => {
|
|
|
|
const isStarred = $starSpan.hasClass('starred');
|
2017-10-11 04:10:35 -04:00
|
|
|
$this.parent().find('.star-count').text(data.star_count);
|
2018-02-20 17:20:48 -05:00
|
|
|
|
2017-10-11 04:10:35 -04:00
|
|
|
if (isStarred) {
|
|
|
|
$starSpan.removeClass('starred').text(s__('StarProject|Star'));
|
2017-11-23 02:52:15 -05:00
|
|
|
$startIcon.remove();
|
|
|
|
$this.prepend(spriteIcon('star-o'));
|
2017-10-11 04:10:35 -04:00
|
|
|
} else {
|
|
|
|
$starSpan.addClass('starred').text(__('Unstar'));
|
2017-11-23 02:52:15 -05:00
|
|
|
$startIcon.remove();
|
|
|
|
$this.prepend(spriteIcon('star'));
|
2017-10-11 04:10:35 -04:00
|
|
|
}
|
2018-02-20 17:20:48 -05:00
|
|
|
})
|
|
|
|
.catch(() => Flash('Star toggle failed. Try again later.'));
|
|
|
|
});
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2017-06-30 17:27:31 -04:00
|
|
|
}
|