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