2016-06-02 11:05:42 +05:30
|
|
|
@ProjectsList =
|
|
|
|
init: ->
|
|
|
|
$(".projects-list-filter").off('keyup')
|
|
|
|
this.initSearch()
|
|
|
|
this.initPagination()
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
initSearch: ->
|
2016-08-24 12:49:21 +05:30
|
|
|
projectsListFilter = $('.projects-list-filter')
|
|
|
|
debounceFilter = _.debounce ProjectsList.filterResults, 500
|
|
|
|
projectsListFilter.on 'keyup', (e) ->
|
|
|
|
debounceFilter() if projectsListFilter.val() isnt ''
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
filterResults: ->
|
2016-06-02 11:05:42 +05:30
|
|
|
$('.projects-list-holder').fadeTo(250, 0.5)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
form = null
|
|
|
|
form = $("form#project-filter-form")
|
|
|
|
search = $(".projects-list-filter").val()
|
|
|
|
project_filter_url = form.attr('action') + '?' + form.serialize()
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
$.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"
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
initPagination: ->
|
|
|
|
$('.projects-list-holder .pagination').on('ajax:success', (e, data) ->
|
|
|
|
$('.projects-list-holder').replaceWith(data.html)
|
|
|
|
)
|