summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/activities.js
blob: 648cb4d5d854a9433404b745e9f251471b71982d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable no-param-reassign, class-methods-use-this */
/* global Pager */
/* global Cookies */

((global) => {
  class Activities {
    constructor() {
      Pager.init(20, true, false, this.updateTooltips);
      $('.event-filter-link').on('click', (e) => {
        e.preventDefault();
        this.toggleFilter(e.currentTarget);
        this.reloadActivities();
      });
    }

    updateTooltips() {
      gl.utils.localTimeAgo($('.js-timeago', '.content_list'));
    }

    reloadActivities() {
      $('.content_list').html('');
      Pager.init(20, true, false, this.updateTooltips);
    }

    toggleFilter(sender) {
      const $sender = $(sender);
      const filter = $sender.attr('id').split('_')[0];

      $('.event-filter .active').removeClass('active');
      Cookies.set('event_filter', filter);

      $sender.closest('li').toggleClass('active');
    }
  }

  global.Activities = Activities;
})(window.gl || (window.gl = {}));