gitlab-org--gitlab-foss/app/assets/javascripts/issuable/issuable_context.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery';
import { setCookie } from '~/lib/utils/common_utils';
import { loadCSSFile } from '~/lib/utils/css_utils';
import UsersSelect from '~/users_select';
2017-03-11 01:45:34 -05:00
export default class IssuableContext {
constructor(currentUser) {
this.userSelect = new UsersSelect(currentUser);
this.reviewersSelect = new UsersSelect(currentUser, '.js-reviewer-search');
const $select2 = $('select.select2');
if ($select2.length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
// eslint-disable-next-line promise/no-nesting
loadCSSFile(gon.select2_css_path)
.then(() => {
$select2.select2({
width: 'resolve',
dropdownAutoWidth: true,
});
})
.catch(() => {});
})
.catch(() => {});
}
$('.issuable-sidebar .inline-update').on('change', 'select', function onClickSelect() {
return $(this).submit();
});
$('.issuable-sidebar .inline-update').on('change', '.js-assignee', function onClickAssignee() {
return $(this).submit();
});
$(document)
.off('click', '.issuable-sidebar .dropdown-content a')
.on('click', '.issuable-sidebar .dropdown-content a', (e) => e.preventDefault());
$(document)
.off('click', '.edit-link')
.on('click', '.edit-link', function onClickEdit(e) {
2016-07-24 16:45:11 -04:00
e.preventDefault();
const $block = $(this).parents('.block');
const $selectbox = $block.find('.selectbox');
2016-07-24 16:45:11 -04:00
if ($selectbox.is(':visible')) {
$selectbox.hide();
$block.find('.value:not(.dont-hide)').show();
2016-07-24 16:45:11 -04:00
} else {
$selectbox.show();
$block.find('.value:not(.dont-hide)').hide();
2016-07-24 16:45:11 -04:00
}
2016-07-24 16:45:11 -04:00
if ($selectbox.is(':visible')) {
setTimeout(() => $block.find('.dropdown-menu-toggle').trigger('click'), 0);
2016-07-24 16:45:11 -04:00
}
});
window.addEventListener('beforeunload', () => {
// collapsed_gutter cookie hides the sidebar
const bpBreakpoint = bp.getBreakpointSize();
const supportedSizes = ['xs', 'sm', 'md'];
if (supportedSizes.includes(bpBreakpoint)) {
setCookie('collapsed_gutter', true);
}
});
}
}