Commit 2c871ca1 authored by Josh Frye's avatar Josh Frye

Delay filter until user stops typing

parent 7522ac0b
class @Dashboard class @Dashboard
constructor: -> constructor: ->
new ProjectsList() ProjectsList.init()
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
filterResults: => filterResults: =>
form = $("#issue_search_form") form = $("#issue_search_form")
search = $("#issue_search").val() search = $("#projects-list-filter").val()
$('.issues-holder').css("opacity", '0.5') $('.issues-holder').css("opacity", '0.5')
issues_url = form.attr('action') + '?' + form.serialize() issues_url = form.attr('action') + '?' + form.serialize()
......
class @ProjectsList @ProjectsList =
constructor: -> init: ->
$(".projects-list .js-expand").on 'click', (e) -> $(".projects-list .js-expand").on 'click', (e) ->
e.preventDefault() e.preventDefault()
list = $(this).closest('.projects-list') list = $(this).closest('.projects-list')
list.find("li").show() list.find("li").show()
list.find("li.bottom").hide() list.find("li.bottom").hide()
this.initSearch()
$(".projects-list-filter").keyup -> initSearch: ->
terms = $(this).val() @timer = null
uiBox = $('div.projects-list-holder') $("#projects-list-filter").keyup ->
filterSelector = $(this).data('filter-selector') || 'span.filter-title' clearTimeout(@timer)
@timer = setTimeout(ProjectsList.filterResults, 500)
$('.projects-list-holder').css("opacity", '0.5') filterResults: =>
form = $("#project-list-form") form = $("#project-list-form")
project_filter_url = form.attr('action') + '?' + form.serialize() search = $("#issue_search").val()
$.ajax uiBox = $('div.projects-list-holder')
type: "GET"
url: form.attr('action') $('.projects-list-holder').css("opacity", '0.5')
data: form.serialize()
complete: -> project_filter_url = form.attr('action') + '?' + form.serialize()
$('.projects-list-holder').css("opacity", '1.0') $.ajax
success: (data) -> type: "GET"
$('.projects-list-holder').html(data.html) url: form.attr('action')
# Change url so if user reload a page - search results are saved data: form.serialize()
history.replaceState {page: project_filter_url}, document.title, project_filter_url complete: ->
dataType: "json" $('.projects-list-holder').css("opacity", '1.0')
uiBox.find("ul.projects-list li.bottom").hide() success: (data) ->
$('.projects-list-holder').html(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"
uiBox.find("ul.projects-list li.bottom").hide()
class @User class @User
constructor: -> constructor: ->
$('.profile-groups-avatars').tooltip("placement": "top") $('.profile-groups-avatars').tooltip("placement": "top")
new ProjectsList() ProjectsList.init()
$('.hide-project-limit-message').on 'click', (e) -> $('.hide-project-limit-message').on 'click', (e) ->
path = '/' path = '/'
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
.nav-controls .nav-controls
= form_tag '', method: :get, class: 'project-list-form', id: 'project-list-form' do |f| = form_tag '', method: :get, class: 'project-list-form', id: 'project-list-form' do |f|
.append-right-10.hidden-xs.hidden-sm .append-right-10.hidden-xs.hidden-sm
= search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'projects-list-filter form-control issue_search search-text-input', spellcheck: false, id: 'projects-list-filter' = search_field_tag :filter_projects, params[:filter_projects], placeholder: 'Filter by name...', class: 'projects-list-filter form-control search-text-input', spellcheck: false, id: 'projects-list-filter'
- if current_user.can_create_project? - if current_user.can_create_project?
= link_to new_project_path, class: 'btn btn-new' do = link_to new_project_path, class: 'btn btn-new' do
= icon('plus') = icon('plus')
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
= render 'shared/projects/list', ci: true = render 'shared/projects/list', ci: true
:javascript :javascript
new ProjectsList(); ProjectsList.init()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment