2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-01-31 04:29:29 -05:00
|
|
|
import axios from './lib/utils/axios_utils';
|
|
|
|
import flash from './flash';
|
2018-03-27 13:17:36 -04:00
|
|
|
import { mouseenter, debouncedMouseleave, togglePopover } from './shared/popover';
|
2019-05-03 09:00:44 -04:00
|
|
|
import { __ } from './locale';
|
2017-10-02 08:32:53 -04:00
|
|
|
|
2017-11-20 15:28:29 -05:00
|
|
|
export default class Milestone {
|
|
|
|
constructor() {
|
|
|
|
this.bindTabsSwitching();
|
2017-04-25 11:06:17 -04:00
|
|
|
|
2017-11-20 15:28:29 -05:00
|
|
|
// Load merge request tab if it is active
|
|
|
|
// merge request tab is active based on different conditions in the backend
|
|
|
|
this.loadTab($('.js-milestone-tabs .active a'));
|
2017-04-25 12:45:11 -04:00
|
|
|
|
2017-11-20 15:28:29 -05:00
|
|
|
this.loadInitialTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
bindTabsSwitching() {
|
2018-10-10 03:13:34 -04:00
|
|
|
return $('a[data-toggle="tab"]').on('show.bs.tab', e => {
|
2017-11-20 15:28:29 -05:00
|
|
|
const $target = $(e.target);
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-06-15 11:58:27 -04:00
|
|
|
window.location.hash = $target.attr('href');
|
2017-11-20 15:28:29 -05:00
|
|
|
this.loadTab($target);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
loadInitialTab() {
|
2018-06-15 11:58:27 -04:00
|
|
|
const $target = $(`.js-milestone-tabs a[href="${window.location.hash}"]`);
|
2017-04-25 10:25:20 -04:00
|
|
|
|
2017-11-20 15:28:29 -05:00
|
|
|
if ($target.length) {
|
|
|
|
$target.tab('show');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
loadTab($target) {
|
|
|
|
const endpoint = $target.data('endpoint');
|
|
|
|
const tabElId = $target.attr('href');
|
|
|
|
|
|
|
|
if (endpoint && !$target.hasClass('is-loaded')) {
|
2018-10-10 03:13:34 -04:00
|
|
|
axios
|
|
|
|
.get(endpoint)
|
2018-01-31 04:29:29 -05:00
|
|
|
.then(({ data }) => {
|
|
|
|
$(tabElId).html(data.html);
|
|
|
|
$target.addClass('is-loaded');
|
|
|
|
})
|
2019-05-03 09:00:44 -04:00
|
|
|
.catch(() => flash(__('Error loading milestone tab')));
|
2017-11-20 15:28:29 -05:00
|
|
|
}
|
|
|
|
}
|
2018-03-13 10:44:06 -04:00
|
|
|
|
|
|
|
static initDeprecationMessage() {
|
2018-10-10 03:13:34 -04:00
|
|
|
const deprecationMesssageContainer = document.querySelector(
|
|
|
|
'.js-milestone-deprecation-message',
|
|
|
|
);
|
2018-03-13 10:44:06 -04:00
|
|
|
|
2018-03-26 13:46:42 -04:00
|
|
|
if (!deprecationMesssageContainer) return;
|
2018-03-13 10:44:06 -04:00
|
|
|
|
2018-10-10 03:13:34 -04:00
|
|
|
const deprecationMessage = deprecationMesssageContainer.querySelector(
|
|
|
|
'.js-milestone-deprecation-message-template',
|
|
|
|
).innerHTML;
|
2018-03-29 09:18:49 -04:00
|
|
|
const $popover = $('.js-popover-link', deprecationMesssageContainer);
|
2018-03-27 13:17:36 -04:00
|
|
|
const hideOnScroll = togglePopover.bind($popover, false);
|
2018-03-13 10:44:06 -04:00
|
|
|
|
2018-10-10 03:13:34 -04:00
|
|
|
$popover
|
|
|
|
.popover({
|
|
|
|
content: deprecationMessage,
|
|
|
|
html: true,
|
|
|
|
placement: 'bottom',
|
|
|
|
})
|
|
|
|
.on('mouseenter', mouseenter)
|
|
|
|
.on('mouseleave', debouncedMouseleave())
|
|
|
|
.on('show.bs.popover', () => {
|
|
|
|
window.addEventListener('scroll', hideOnScroll, { once: true });
|
|
|
|
});
|
2018-03-13 10:44:06 -04:00
|
|
|
}
|
2017-11-20 15:28:29 -05:00
|
|
|
}
|