BigW Consortium Gitlab

projects_list.js.coffee 1.16 KB
Newer Older
1 2 3 4
@ProjectsList =
  init: ->
    $(".projects-list-filter").off('keyup')
    this.initSearch()
5
    this.initPagination()
6

7
  initSearch: ->
8
    projectsListFilter = $('.projects-list-filter')
Luke "Jared" Bennett committed
9 10 11
    debounceFilter = _.debounce ProjectsList.filterResults, 500
    projectsListFilter.on 'keyup', (e) ->
      debounceFilter() if projectsListFilter.val() isnt ''
12

13
  filterResults: ->
14
    $('.projects-list-holder').fadeTo(250, 0.5)
15

16 17 18 19
    form = null
    form = $("form#project-filter-form")
    search = $(".projects-list-filter").val()
    project_filter_url = form.attr('action') + '?' + form.serialize()
20

21 22 23 24 25 26 27 28 29 30 31
    $.ajax
      type: "GET"
      url: form.attr('action')
      data: form.serialize()
      complete: ->
        $('.projects-list-holder').fadeTo(250, 1)
      success: (data) ->
        $('.projects-list-holder').replaceWith(data.html)
        # Change url so if user reload a page - search results are saved
        history.replaceState {page: project_filter_url}, document.title, project_filter_url
      dataType: "json"
32 33

  initPagination: ->
34
    $('.projects-list-holder .pagination').on('ajax:success', (e, data) ->
35 36
      $('.projects-list-holder').replaceWith(data.html)
    )