2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as flash } from './flash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from './lib/utils/axios_utils';
|
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();
|
|
|
|
this.loadInitialTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
bindTabsSwitching() {
|
2021-03-08 18:12:59 +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);
|
|
|
|
});
|
|
|
|
}
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
loadInitialTab() {
|
2021-01-03 14:25:43 +05:30
|
|
|
const $target = $(`.js-milestone-tabs a:not(.active)[href="${window.location.hash}"]`);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
if ($target.length) {
|
|
|
|
$target.tab('show');
|
2021-01-03 14:25:43 +05:30
|
|
|
} else {
|
|
|
|
this.loadTab($('.js-milestone-tabs a.active'));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|