2021-02-14 13:09:20 -05:00
|
|
|
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2022-02-01 16:12:02 -05:00
|
|
|
import { setCookie } from '~/lib/utils/common_utils';
|
2021-12-07 10:15:03 -05:00
|
|
|
import { loadCSSFile } from '~/lib/utils/css_utils';
|
|
|
|
import UsersSelect from '~/users_select';
|
2017-03-11 01:45:34 -05:00
|
|
|
|
2017-10-26 16:14:18 -04:00
|
|
|
export default class IssuableContext {
|
|
|
|
constructor(currentUser) {
|
|
|
|
this.userSelect = new UsersSelect(currentUser);
|
2020-09-29 05:09:49 -04:00
|
|
|
this.reviewersSelect = new UsersSelect(currentUser, '.js-reviewer-search');
|
2017-10-26 16:14:18 -04:00
|
|
|
|
2021-07-09 08:08:17 -04:00
|
|
|
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(() => {});
|
|
|
|
}
|
2017-10-26 16:14:18 -04:00
|
|
|
|
|
|
|
$('.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')
|
2020-12-23 19:10:25 -05:00
|
|
|
.on('click', '.issuable-sidebar .dropdown-content a', (e) => e.preventDefault());
|
2017-10-26 16:14:18 -04:00
|
|
|
|
|
|
|
$(document)
|
|
|
|
.off('click', '.edit-link')
|
|
|
|
.on('click', '.edit-link', function onClickEdit(e) {
|
2016-07-24 16:45:11 -04:00
|
|
|
e.preventDefault();
|
2017-10-26 16:14:18 -04:00
|
|
|
const $block = $(this).parents('.block');
|
|
|
|
const $selectbox = $block.find('.selectbox');
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($selectbox.is(':visible')) {
|
|
|
|
$selectbox.hide();
|
2018-04-18 18:29:58 -04:00
|
|
|
$block.find('.value:not(.dont-hide)').show();
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
|
|
|
$selectbox.show();
|
2018-04-18 18:29:58 -04:00
|
|
|
$block.find('.value:not(.dont-hide)').hide();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-10-26 16:14:18 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($selectbox.is(':visible')) {
|
2017-10-26 16:14:18 -04:00
|
|
|
setTimeout(() => $block.find('.dropdown-menu-toggle').trigger('click'), 0);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-26 16:14:18 -04:00
|
|
|
window.addEventListener('beforeunload', () => {
|
|
|
|
// collapsed_gutter cookie hides the sidebar
|
|
|
|
const bpBreakpoint = bp.getBreakpointSize();
|
2020-01-02 19:07:45 -05:00
|
|
|
const supportedSizes = ['xs', 'sm', 'md'];
|
|
|
|
|
|
|
|
if (supportedSizes.includes(bpBreakpoint)) {
|
2022-02-01 16:12:02 -05:00
|
|
|
setCookie('collapsed_gutter', true);
|
2017-10-26 16:14:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|