BigW Consortium Gitlab

commits.js 2.1 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, consistent-return, no-return-assign, no-param-reassign, one-var, no-var, one-var-declaration-per-line, no-unused-vars, prefer-template, object-shorthand, comma-dangle, max-len, prefer-arrow-callback */
2 3
/* global Pager */

4 5
window.CommitsList = (function() {
  var CommitsList = {};
Fatih Acet committed
6

7
  CommitsList.timer = null;
Fatih Acet committed
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  CommitsList.init = function(limit) {
    $("body").on("click", ".day-commits-table li.commit", function(e) {
      if (e.target.nodeName !== "A") {
        location.href = $(this).attr("url");
        e.stopPropagation();
        return false;
      }
    });
    Pager.init(limit, false, false, function() {
      gl.utils.localTimeAgo($('.js-timeago'));
    });
    this.content = $("#commits-list");
    this.searchField = $("#commits-search");
    this.lastSearch = this.searchField.val();
    return this.initSearch();
  };
Fatih Acet committed
25

26 27 28 29 30 31 32 33 34
  CommitsList.initSearch = function() {
    this.timer = null;
    return this.searchField.keyup((function(_this) {
      return function() {
        clearTimeout(_this.timer);
        return _this.timer = setTimeout(_this.filterResults, 500);
      };
    })(this));
  };
Fatih Acet committed
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  CommitsList.filterResults = function() {
    var commitsUrl, form, search;
    form = $(".commits-search-form");
    search = CommitsList.searchField.val();
    if (search === CommitsList.lastSearch) return;
    commitsUrl = form.attr("action") + '?' + form.serialize();
    CommitsList.content.fadeTo('fast', 0.5);
    return $.ajax({
      type: "GET",
      url: form.attr("action"),
      data: form.serialize(),
      complete: function() {
        return CommitsList.content.fadeTo('fast', 1.0);
      },
      success: function(data) {
        CommitsList.lastSearch = search;
        CommitsList.content.html(data.html);
        return history.replaceState({
          page: commitsUrl
        // Change url so if user reload a page - search results are saved
        }, document.title, commitsUrl);
      },
      error: function() {
        CommitsList.lastSearch = null;
      },
      dataType: "json"
    });
  };
Fatih Acet committed
64

65 66
  return CommitsList;
})();