debian-mirror-gitlab/app/assets/javascripts/milestone.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import axios from './lib/utils/axios_utils';
import flash from './flash';
2018-10-15 14:42:47 +05:30
import { mouseenter, debouncedMouseleave, togglePopover } from './shared/popover';
2019-09-04 21:01:54 +05:30
import { __ } from './locale';
2018-03-17 18:26:18 +05:30
export default class Milestone {
constructor() {
this.bindTabsSwitching();
// 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'));
this.loadInitialTab();
}
bindTabsSwitching() {
2018-12-13 13:39:08 +05:30
return $('a[data-toggle="tab"]').on('show.bs.tab', e => {
2018-03-17 18:26:18 +05:30
const $target = $(e.target);
2018-11-08 19:23:39 +05:30
window.location.hash = $target.attr('href');
2018-03-17 18:26:18 +05:30
this.loadTab($target);
});
}
// eslint-disable-next-line class-methods-use-this
loadInitialTab() {
2018-11-08 19:23:39 +05:30
const $target = $(`.js-milestone-tabs a[href="${window.location.hash}"]`);
2018-03-17 18:26:18 +05:30
if ($target.length) {
$target.tab('show');
2016-09-13 17:45:13 +05:30
}
2018-03-17 18:26:18 +05:30
}
// 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-12-13 13:39:08 +05:30
axios
.get(endpoint)
2018-03-17 18:26:18 +05:30
.then(({ data }) => {
2017-08-17 22:00:37 +05:30
$(tabElId).html(data.html);
$target.addClass('is-loaded');
2018-03-17 18:26:18 +05:30
})
2019-09-04 21:01:54 +05:30
.catch(() => flash(__('Error loading milestone tab')));
2018-03-17 18:26:18 +05:30
}
}
2018-10-15 14:42:47 +05:30
static initDeprecationMessage() {
2018-12-13 13:39:08 +05:30
const deprecationMesssageContainer = document.querySelector(
'.js-milestone-deprecation-message',
);
2018-10-15 14:42:47 +05:30
if (!deprecationMesssageContainer) return;
2018-12-13 13:39:08 +05:30
const deprecationMessage = deprecationMesssageContainer.querySelector(
'.js-milestone-deprecation-message-template',
).innerHTML;
2018-10-15 14:42:47 +05:30
const $popover = $('.js-popover-link', deprecationMesssageContainer);
const hideOnScroll = togglePopover.bind($popover, false);
2018-12-13 13:39:08 +05:30
$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-10-15 14:42:47 +05:30
}
2018-03-17 18:26:18 +05:30
}