BigW Consortium Gitlab

milestone.js 1.64 KB
Newer Older
1
/* 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 */
2
/* global Flash */
3
/* global Sortable */
4

Fatih Acet committed
5 6 7 8
(function() {
  this.Milestone = (function() {
    function Milestone() {
      this.bindTabsSwitching();
9 10 11 12

      // 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'));
13 14

      this.loadInitialTab();
Fatih Acet committed
15 16 17
    }

    Milestone.prototype.bindTabsSwitching = function() {
18 19 20
      return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
        const $target = $(e.target);

21 22
        location.hash = $target.attr('href');
        this.loadTab($target);
Fatih Acet committed
23 24 25
      });
    };

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    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');
        });
      }
49 50
    };

Fatih Acet committed
51 52
    return Milestone;
  })();
53
}).call(window);