summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable_index.js
blob: f3f8b6ec71599e62ae2498c4dfcfc5f945693cee (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
import $ from 'jquery';
import axios from './lib/utils/axios_utils';
import flash from './flash';
import { s__, __ } from './locale';
import issuableInitBulkUpdateSidebar from './issuable_init_bulk_update_sidebar';

export default class IssuableIndex {
  constructor(pagePrefix) {
    issuableInitBulkUpdateSidebar.init(pagePrefix);
    IssuableIndex.resetIncomingEmailToken();
  }

  static resetIncomingEmailToken() {
    const $resetToken = $('.incoming-email-token-reset');

    $resetToken.on('click', e => {
      e.preventDefault();

      $resetToken.text(s__('EmailToken|resetting...'));

      axios
        .put($resetToken.attr('href'))
        .then(({ data }) => {
          $('#issuable_email')
            .val(data.new_address)
            .focus();

          $resetToken.text(s__('EmailToken|reset it'));
        })
        .catch(() => {
          flash(__('There was an error when reseting email token.'));

          $resetToken.text(s__('EmailToken|reset it'));
        });
    });
  }
}