2018-06-16 13:20:30 +00:00
|
|
|
/* eslint-disable class-methods-use-this */
|
2017-03-11 06:45:34 +00:00
|
|
|
|
2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2017-03-11 06:45:34 +00:00
|
|
|
import Cookies from 'js-cookie';
|
2021-04-06 18:09:02 +00:00
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { s__ } from '~/locale';
|
2017-12-07 11:09:17 +00:00
|
|
|
import { localTimeAgo } from './lib/utils/datetime_utility';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Pager from './pager';
|
2016-11-20 05:52:53 +00:00
|
|
|
|
2017-12-14 11:50:40 +00:00
|
|
|
export default class Activities {
|
2021-04-06 18:09:02 +00:00
|
|
|
constructor(containerSelector = '') {
|
|
|
|
this.containerSelector = containerSelector;
|
|
|
|
this.containerEl = this.containerSelector
|
|
|
|
? document.querySelector(this.containerSelector)
|
|
|
|
: undefined;
|
|
|
|
this.$contentList = $('.content_list');
|
2017-06-03 01:40:20 +00:00
|
|
|
|
2021-04-06 18:09:02 +00:00
|
|
|
this.loadActivities();
|
2018-10-24 06:25:46 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
$('.event-filter-link').on('click', (e) => {
|
2017-03-11 07:30:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.toggleFilter(e.currentTarget);
|
|
|
|
this.reloadActivities();
|
|
|
|
});
|
|
|
|
}
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2021-04-06 18:09:02 +00:00
|
|
|
loadActivities() {
|
|
|
|
Pager.init({
|
|
|
|
limit: 20,
|
|
|
|
preload: true,
|
|
|
|
prepareData: (data) => data,
|
|
|
|
successCallback: () => this.updateTooltips(),
|
|
|
|
errorCallback: () =>
|
|
|
|
createFlash({
|
|
|
|
message: s__(
|
|
|
|
'Activity|An error occured while retrieving activity. Reload the page to try again.',
|
|
|
|
),
|
|
|
|
parent: this.containerEl,
|
|
|
|
}),
|
|
|
|
container: this.containerSelector,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
updateTooltips() {
|
2021-07-14 06:09:45 +00:00
|
|
|
localTimeAgo(document.querySelectorAll('.content_list .js-timeago'));
|
2017-03-11 07:30:44 +00:00
|
|
|
}
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
reloadActivities() {
|
2021-04-06 18:09:02 +00:00
|
|
|
this.$contentList.html('');
|
|
|
|
this.loadActivities();
|
2017-03-11 07:30:44 +00:00
|
|
|
}
|
2016-08-29 17:09:33 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
toggleFilter(sender) {
|
|
|
|
const $sender = $(sender);
|
|
|
|
const filter = $sender.attr('id').split('_')[0];
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
$('.event-filter .active').removeClass('active');
|
|
|
|
Cookies.set('event_filter', filter);
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
$sender.closest('li').toggleClass('active');
|
2016-11-20 05:52:53 +00:00
|
|
|
}
|
2017-03-11 07:30:44 +00:00
|
|
|
}
|