2016-03-03 07:09:58 -05:00
|
|
|
@ProjectsList =
|
|
|
|
init: ->
|
|
|
|
$(".projects-list-filter").off('keyup')
|
|
|
|
this.initSearch()
|
2016-03-10 07:41:23 -05:00
|
|
|
this.initPagination()
|
2015-03-04 20:22:55 -05:00
|
|
|
|
2016-03-03 07:09:58 -05:00
|
|
|
initSearch: ->
|
|
|
|
@timer = null
|
|
|
|
$(".projects-list-filter").on('keyup', ->
|
|
|
|
clearTimeout(@timer)
|
|
|
|
@timer = setTimeout(ProjectsList.filterResults, 500)
|
|
|
|
)
|
2016-01-11 21:38:31 -05:00
|
|
|
|
2016-03-03 07:09:58 -05:00
|
|
|
filterResults: =>
|
|
|
|
$('.projects-list-holder').fadeTo(250, 0.5)
|
2016-02-03 17:24:14 -05:00
|
|
|
|
2016-03-03 07:09:58 -05:00
|
|
|
form = null
|
|
|
|
form = $("form#project-filter-form")
|
|
|
|
search = $(".projects-list-filter").val()
|
|
|
|
project_filter_url = form.attr('action') + '?' + form.serialize()
|
2016-02-05 10:56:22 -05:00
|
|
|
|
2016-03-03 07:09:58 -05:00
|
|
|
$.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-03-10 07:41:23 -05:00
|
|
|
|
|
|
|
initPagination: ->
|
2016-03-10 07:55:01 -05:00
|
|
|
$('.projects-list-holder .pagination').on('ajax:success', (e, data) ->
|
2016-03-10 07:41:23 -05:00
|
|
|
$('.projects-list-holder').replaceWith(data.html)
|
|
|
|
)
|