2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-use-before-define, camelcase, quotes, object-shorthand, no-shadow, no-unused-vars, comma-dangle, no-var, prefer-template, no-underscore-dangle, consistent-return, one-var, one-var-declaration-per-line, default-case, prefer-arrow-callback, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Flash */
|
2017-01-06 11:52:18 -05:00
|
|
|
/* global Sortable */
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
this.Milestone = (function() {
|
|
|
|
function Milestone() {
|
|
|
|
this.bindTabsSwitching();
|
2017-04-25 11:06:17 -04: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
|
|
|
|
|
|
|
this.loadInitialTab();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Milestone.prototype.bindTabsSwitching = function() {
|
2017-04-25 10:25:20 -04:00
|
|
|
return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
|
|
|
|
const $target = $(e.target);
|
|
|
|
|
2017-04-25 11:06:17 -04:00
|
|
|
location.hash = $target.attr('href');
|
|
|
|
this.loadTab($target);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-04-25 11:06:17 -04:00
|
|
|
Milestone.prototype.loadInitialTab = function() {
|
|
|
|
const $target = $(`.js-milestone-tabs a[href="${location.hash}"]`);
|
|
|
|
|
|
|
|
if ($target.length) {
|
|
|
|
$target.tab('show');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Milestone.prototype.loadTab = function($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');
|
|
|
|
});
|
|
|
|
}
|
2017-04-25 10:25:20 -04:00
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return Milestone;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|