BigW Consortium Gitlab

commits.js.coffee 1.05 KB
Newer Older
1
class @CommitsList
2
  @timer = null
3

Alfredo Sumaran committed
4
  @init: (limit) ->
5
    $("body").on "click", ".day-commits-table li.commit", (event) ->
6 7 8 9 10
      if event.target.nodeName != "A"
        location.href = $(this).attr("url")
        e.stopPropagation()
        return false

11
    Pager.init limit, false
12 13 14 15

    @content = $("#commits-list")
    @searchField = $("#commits-search")
    @initSearch()
16

17 18 19 20 21 22 23 24 25 26
  @initSearch: ->
    @timer = null
    @searchField.keyup =>
      clearTimeout(@timer)
      @timer = setTimeout(@filterResults, 500)

  @filterResults: =>
    form = $(".commits-search-form")
    search = @searchField.val()
    commitsUrl = form.attr("action") + '?' + form.serialize()
27
    @content.fadeTo('fast', 0.5)
28 29 30

    $.ajax
      type: "GET"
31 32 33
      url: form.attr("action")
      data: form.serialize()
      complete: =>
34
        @content.fadeTo('fast', 1.0)
35 36 37 38
      success: (data) =>
        @content.html(data.html)
        # Change url so if user reload a page - search results are saved
        history.replaceState {page: commitsUrl}, document.title, commitsUrl
39
      dataType: "json"