summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable_index.js
blob: 0b123a11a3b50d97e9564c5af40f4b11242aa55e (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
38
39
40
41
42
import IssuableBulkUpdateSidebar from './issuable_bulk_update_sidebar';
import IssuableBulkUpdateActions from './issuable_bulk_update_actions';

export default class IssuableIndex {
  constructor(pagePrefix) {
    this.initBulkUpdate(pagePrefix);
    IssuableIndex.resetIncomingEmailToken();
  }
  initBulkUpdate(pagePrefix) {
    const userCanBulkUpdate = $('.issues-bulk-update').length > 0;
    const alreadyInitialized = !!this.bulkUpdateSidebar;

    if (userCanBulkUpdate && !alreadyInitialized) {
      IssuableBulkUpdateActions.init({
        prefixId: pagePrefix,
      });

      this.bulkUpdateSidebar = new IssuableBulkUpdateSidebar();
    }
  }

  static resetIncomingEmailToken() {
    $('.incoming-email-token-reset').on('click', (e) => {
      e.preventDefault();

      $.ajax({
        type: 'PUT',
        url: $('.incoming-email-token-reset').attr('href'),
        dataType: 'json',
        success(response) {
          $('#issue_email').val(response.new_issue_address).focus();
        },
        beforeSend() {
          $('.incoming-email-token-reset').text('resetting...');
        },
        complete() {
          $('.incoming-email-token-reset').text('reset it');
        },
      });
    });
  }
}