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';
|
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() {
|
2017-10-11 04:10:35 -04:00
|
|
|
$('.project-home-panel .toggle-star')
|
|
|
|
.on('ajax:success', function handleSuccess(e, data) {
|
|
|
|
const $this = $(this);
|
|
|
|
const $starSpan = $this.find('span');
|
2017-11-23 02:52:15 -05:00
|
|
|
const $startIcon = $this.find('svg');
|
2017-10-11 04:10:35 -04:00
|
|
|
|
|
|
|
function toggleStar(isStarred) {
|
|
|
|
$this.parent().find('.star-count').text(data.star_count);
|
|
|
|
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
|
|
|
}
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2017-10-11 04:10:35 -04:00
|
|
|
|
|
|
|
toggleStar($starSpan.hasClass('starred'));
|
|
|
|
})
|
|
|
|
.on('ajax:error', () => {
|
|
|
|
Flash('Star toggle failed. Try again later.', 'alert');
|
|
|
|
});
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2017-06-30 17:27:31 -04:00
|
|
|
}
|