2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from './flash';
|
2018-03-27 19:54:05 +05:30
|
|
|
import axios from './lib/utils/axios_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { spriteIcon } from './lib/utils/common_utils';
|
|
|
|
import { __, s__ } from './locale';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
export default class Star {
|
2019-02-15 15:39:39 +05:30
|
|
|
constructor(container = '.project-home-panel') {
|
|
|
|
$(`${container} .toggle-star`).on('click', function toggleStarClickCallback() {
|
2018-03-27 19:54:05 +05:30
|
|
|
const $this = $(this);
|
|
|
|
const $starSpan = $this.find('span');
|
2019-02-15 15:39:39 +05:30
|
|
|
const $starIcon = $this.find('svg');
|
|
|
|
const iconClasses = $starIcon.attr('class').split(' ');
|
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');
|
2021-03-08 18:12:59 +05:30
|
|
|
$this.parent().find('.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'));
|
2019-02-15 15:39:39 +05:30
|
|
|
$starIcon.remove();
|
|
|
|
$this.prepend(spriteIcon('star-o', iconClasses));
|
2018-03-17 18:26:18 +05:30
|
|
|
} else {
|
|
|
|
$starSpan.addClass('starred').text(__('Unstar'));
|
2019-02-15 15:39:39 +05:30
|
|
|
$starIcon.remove();
|
|
|
|
$this.prepend(spriteIcon('star', iconClasses));
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
})
|
2019-09-04 21:01:54 +05:30
|
|
|
.catch(() => Flash(__('Star toggle failed. Try again later.')));
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
}
|