diff --git a/app/assets/javascripts/discourse/controllers/search_controller.js b/app/assets/javascripts/discourse/controllers/search_controller.js index 5f9fe23b136..f01cc4d68f5 100644 --- a/app/assets/javascripts/discourse/controllers/search_controller.js +++ b/app/assets/javascripts/discourse/controllers/search_controller.js @@ -24,6 +24,7 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, { searchTerm: Discourse.debouncePromise(function(term, typeFilter) { var searchController = this; this.set('count', 0); + return Discourse.Search.forTerm(term, typeFilter).then(function(results) { searchController.set('results', results); if (results) { diff --git a/app/assets/javascripts/discourse/routes/list_category_route.js b/app/assets/javascripts/discourse/routes/list_category_route.js index 686b0324244..7dadf1dd746 100644 --- a/app/assets/javascripts/discourse/routes/list_category_route.js +++ b/app/assets/javascripts/discourse/routes/list_category_route.js @@ -38,8 +38,23 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({ listController.set('category', category); router.controllerFor('listTopics').set('content', topicList); }); + }, + + activate: function() { + this._super(); + + // Add a search context + this.controllerFor('search').set('searchContext', this.modelFor('listCategory')); + }, + + deactivate: function() { + this._super(); + + // Clear the search context + this.controllerFor('search').set('searchContext', null); } + }); diff --git a/app/assets/javascripts/discourse/routes/topic_route.js b/app/assets/javascripts/discourse/routes/topic_route.js index ad73fc0ba43..65a3b2eafef 100644 --- a/app/assets/javascripts/discourse/routes/topic_route.js +++ b/app/assets/javascripts/discourse/routes/topic_route.js @@ -18,11 +18,22 @@ Discourse.TopicRoute = Discourse.Route.extend({ return Discourse.Topic.create(params); }, - enter: function() { - Discourse.set('transient.lastTopicIdViewed', parseInt(this.modelFor('topic').get('id'), 10)); + activate: function() { + this._super(); + + var topic = this.modelFor('topic'); + Discourse.set('transient.lastTopicIdViewed', parseInt(topic.get('id'), 10)); + + // Set the search context + this.controllerFor('search').set('searchContext', topic); }, - exit: function() { + deactivate: function() { + this._super(); + + // Clear the search context + this.controllerFor('search').set('searchContext', null); + var headerController, topicController; topicController = this.controllerFor('topic'); topicController.cancelFilter(); diff --git a/app/assets/javascripts/discourse/routes/user_route.js b/app/assets/javascripts/discourse/routes/user_route.js index 73fac487cc9..8cb7991877b 100644 --- a/app/assets/javascripts/discourse/routes/user_route.js +++ b/app/assets/javascripts/discourse/routes/user_route.js @@ -26,11 +26,17 @@ Discourse.UserRoute = Discourse.Route.extend({ Discourse.MessageBus.subscribe("/users/" + user.get('username_lower'), function(data) { user.loadUserAction(data); }); + + // Add a search context + this.controllerFor('search').set('searchContext', user); }, deactivate: function() { this._super(); Discourse.MessageBus.unsubscribe("/users/" + this.modelFor('user').get('username_lower')); + + // Remove the search context + this.controllerFor('search').set('searchContext', null); }