summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commits.js
blob: 9132089adcdde55f080e64cc69c3992ac627cdbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
49
50
51
52
53
54
55
56
57
58
59
(function() {
  this.CommitsList = (function() {
    function CommitsList() {}

    CommitsList.timer = null;

    CommitsList.init = function(limit) {
      $("body").on("click", ".day-commits-table li.commit", function(event) {
        if (event.target.nodeName !== "A") {
          location.href = $(this).attr("url");
          e.stopPropagation();
          return false;
        }
      });
      Pager.init(limit, false);
      this.content = $("#commits-list");
      this.searchField = $("#commits-search");
      return this.initSearch();
    };

    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));
    };

    CommitsList.filterResults = function() {
      var commitsUrl, form, search;
      form = $(".commits-search-form");
      search = CommitsList.searchField.val();
      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.content.html(data.html);
          return history.replaceState({
            page: commitsUrl
          // Change url so if user reload a page - search results are saved
          }, document.title, commitsUrl);
        },
        dataType: "json"
      });
    };

    return CommitsList;

  })();

}).call(this);