From ff8b281f5bb2a4a1f4afebf357371eb7a7ae2dc1 Mon Sep 17 00:00:00 2001 From: Waqas Khalid Date: Mon, 13 Oct 2014 04:24:12 +0500 Subject: [PATCH] Clicking the magnifying glass should perform search In forum search is only working when user enter some text in the search textfield and press the Enter button. It should also work when we click on magnifying glass. TNL-526 --- .../view/discussion_thread_list_view_spec.coffee | 15 +++++++++++++++ .../views/discussion_thread_list_view.coffee | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee b/common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee index 35ed55e4ad..eeeb37c88f 100644 --- a/common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee +++ b/common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee @@ -16,6 +16,7 @@ describe "DiscussionThreadListView", -> @@ -331,6 +332,20 @@ describe "DiscussionThreadListView", -> @view.collection.trigger("change", new Thread({id: 1})) expect(@view.clearSearchAlerts).toHaveBeenCalled() + describe "Search events", -> + + it "perform search when enter pressed inside search textfield", -> + setupAjax() + spyOn(@view, "searchFor") + @view.$el.find(".forum-nav-search-input").trigger($.Event("keydown", {which: 13})) + expect(@view.searchFor).toHaveBeenCalled() + + it "perform search when search icon is clicked", -> + setupAjax() + spyOn(@view, "searchFor") + @view.$el.find(".icon-search").click() + expect(@view.searchFor).toHaveBeenCalled() + describe "username search", -> it "makes correct ajax calls", -> diff --git a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index c2c0e7e508..3d823fac9b 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -7,6 +7,7 @@ if Backbone? "click .forum-nav-browse-menu-wrapper": "ignoreClick" "click .forum-nav-browse-title": "selectTopicHandler" "keydown .forum-nav-search-input": "performSearch" + "click .icon-search": "performSearch" "change .forum-nav-sort-control": "sortThreads" "click .forum-nav-thread-link": "threadSelected" "click .forum-nav-load-more-link": "loadMorePages" @@ -425,7 +426,8 @@ if Backbone? @retrieveFirstPage(event) performSearch: (event) -> - if event.which == 13 + #event.which 13 represent the Enter button + if event.which == 13 or event.type == 'click' event.preventDefault() @hideBrowseMenu() @setCurrentTopicDisplay(gettext("Search Results"))