gitlab-org--gitlab-foss/app/assets/javascripts/milestone.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-01-06 11:52:18 -05:00
/* global Sortable */
import Flash from './flash';
2017-11-20 15:28:29 -05:00
export default class Milestone {
constructor() {
this.bindTabsSwitching();
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-11-20 15:28:29 -05:00
this.loadInitialTab();
}
bindTabsSwitching() {
return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
const $target = $(e.target);
2016-07-24 16:45:11 -04:00
2017-11-20 15:28:29 -05:00
location.hash = $target.attr('href');
this.loadTab($target);
});
}
// eslint-disable-next-line class-methods-use-this
loadInitialTab() {
const $target = $(`.js-milestone-tabs a[href="${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')) {
$.ajax({
url: endpoint,
dataType: 'JSON',
})
.fail(() => new Flash('Error loading milestone tab'))
.done((data) => {
$(tabElId).html(data.html);
$target.addClass('is-loaded');
2016-07-24 16:45:11 -04:00
});
2017-11-20 15:28:29 -05:00
}
}
}