summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/admin/admin.js
blob: e92262852cfc716a18ba7ea1f0843e980ef7e4ac (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import $ from 'jquery';
import { refreshCurrentPage } from '../../lib/utils/url_utility';

function showDenylistType() {
  if ($('input[name="denylist_type"]:checked').val() === 'file') {
    $('.js-denylist-file').show();
    $('.js-denylist-raw').hide();
  } else {
    $('.js-denylist-file').hide();
    $('.js-denylist-raw').show();
  }
}

export default function adminInit() {
  const modal = $('.change-owner-holder');

  $('input#user_force_random_password').on('change', function randomPasswordClick() {
    const $elems = $('#user_password, #user_password_confirmation');
    if ($(this).attr('checked')) {
      $elems.val('').prop('disabled', true);
    } else {
      $elems.prop('disabled', false);
    }
  });

  $('body').on('click', '.js-toggle-colors-link', (e) => {
    e.preventDefault();
    $('.js-toggle-colors-container').toggleClass('hide');
  });

  $('.log-tabs a').on('click', function logTabsClick(e) {
    e.preventDefault();
    $(this).tab('show');
  });

  $('.log-bottom').on('click', (e) => {
    e.preventDefault();
    const $visibleLog = $('.file-content:visible');

    // eslint-disable-next-line no-jquery/no-animate
    $visibleLog.animate(
      {
        scrollTop: $visibleLog.find('ol').height(),
      },
      'fast',
    );
  });

  $('.change-owner-link').on('click', function changeOwnerLinkClick(e) {
    e.preventDefault();
    $(this).hide();
    modal.show();
  });

  $('.change-owner-cancel-link').on('click', (e) => {
    e.preventDefault();
    modal.hide();
    $('.change-owner-link').show();
  });

  $('li.project_member, li.group_member').on('ajax:success', refreshCurrentPage);

  $("input[name='denylist_type']").on('click', showDenylistType);
  showDenylistType();
}