Commit e43a92a7 by Matthew Mongeau

Show and hide search correctly. Added loading icon.

parent 2f1408ad
...@@ -17,6 +17,7 @@ if Backbone? ...@@ -17,6 +17,7 @@ if Backbone?
@sidebar_header_height = 87 @sidebar_header_height = 87
@boardName @boardName
@template = _.template($("#thread-list-template").html()) @template = _.template($("#thread-list-template").html())
@current_search = ""
reloadDisplayedCollection: (thread) => reloadDisplayedCollection: (thread) =>
thread_id = thread.get('id') thread_id = thread.get('id')
...@@ -133,6 +134,9 @@ if Backbone? ...@@ -133,6 +134,9 @@ if Backbone?
@$("a[data-id='#{thread_id}']").addClass("active") @$("a[data-id='#{thread_id}']").addClass("active")
showSearch: -> showSearch: ->
@$(".browse").removeClass('is-dropped')
@hideTopicDrop()
@$(".search").addClass('is-open') @$(".search").addClass('is-open')
@$(".browse").removeClass('is-open') @$(".browse").removeClass('is-open')
setTimeout (-> @$(".post-search-field").focus()), 200 setTimeout (-> @$(".post-search-field").focus()), 200
...@@ -142,16 +146,21 @@ if Backbone? ...@@ -142,16 +146,21 @@ if Backbone?
@$(".search").removeClass('is-open') @$(".search").removeClass('is-open')
@$(".browse").addClass('is-open') @$(".browse").addClass('is-open')
@$(".browse").toggleClass('is-dropped') @$(".browse").toggleClass('is-dropped')
if @$(".browse").hasClass('is-dropped') if @$(".browse").hasClass('is-dropped')
@$(".browse-topic-drop-menu-wrapper").show() @$(".browse-topic-drop-menu-wrapper").show()
$(".browse-topic-drop-search-input").focus() $(".browse-topic-drop-search-input").focus()
$("body").bind "click", @toggleTopicDrop $("body").bind "click", @toggleTopicDrop
$("body").bind "keydown", @setActiveItem $("body").bind "keydown", @setActiveItem
else else
@hideTopicDrop()
hideTopicDrop: ->
@$(".browse-topic-drop-menu-wrapper").hide() @$(".browse-topic-drop-menu-wrapper").hide()
$("body").unbind "click", @toggleTopicDrop $("body").unbind "click", @toggleTopicDrop
$("body").unbind "keydown", @setActiveItem $("body").unbind "keydown", @setActiveItem
setTopic: (event) -> setTopic: (event) ->
item = $(event.target).closest('a') item = $(event.target).closest('a')
boardName = item.find(".board-name").html() boardName = item.find(".board-name").html()
...@@ -195,6 +204,10 @@ if Backbone? ...@@ -195,6 +204,10 @@ if Backbone?
return name return name
filterTopic: (event) -> filterTopic: (event) ->
if @current_search != ""
@setTopic(event)
@clearSearch @filterTopic, event
else
@setTopic(event) @setTopic(event)
item = $(event.target).closest('li') item = $(event.target).closest('li')
if item.find("span.board-name").data("discussion_id") == "#all" if item.find("span.board-name").data("discussion_id") == "#all"
...@@ -219,13 +232,23 @@ if Backbone? ...@@ -219,13 +232,23 @@ if Backbone?
performSearch: (event) -> performSearch: (event) ->
if event.which == 13 if event.which == 13
event.preventDefault() event.preventDefault()
url = DiscussionUtil.urlFor("search")
text = @$(".post-search-field").val() text = @$(".post-search-field").val()
@searchFor(text)
searchFor: (text, callback, value) ->
@current_search = text
url = DiscussionUtil.urlFor("search")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".post-search-field") $elem: @$(".post-search-field")
data: { text: text } data: { text: text }
url: url url: url
type: "GET" type: "GET"
$loading: $
loadingCallback: =>
@$(".post-list").html('<li class="loading"><div class="loading-animation"></div></li>')
loadedCallback: =>
if callback
callback.apply @, [value]
success: (response, textStatus) => success: (response, textStatus) =>
if textStatus == 'success' if textStatus == 'success'
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
...@@ -235,6 +258,10 @@ if Backbone? ...@@ -235,6 +258,10 @@ if Backbone?
# so this would probably be necessary anyway # so this would probably be necessary anyway
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models)
clearSearch: (callback, value) ->
@$(".post-search-field").val("")
@searchFor("", callback, value)
setActiveItem: (event) -> setActiveItem: (event) ->
if event.which == 13 if event.which == 13
$(".browse-topic-drop-menu-wrapper .focused").click() $(".browse-topic-drop-menu-wrapper .focused").click()
......
...@@ -1006,6 +1006,9 @@ body.discussion { ...@@ -1006,6 +1006,9 @@ body.discussion {
.post-list { .post-list {
background-color: #ddd; background-color: #ddd;
.loading {
padding: 15px 0;
}
a { a {
position: relative; position: relative;
......
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