diff --git a/app/assets/javascripts/discourse/controllers/search.js.es6 b/app/assets/javascripts/discourse/controllers/search.js.es6 index 317106eaaf5..28a316c6583 100644 --- a/app/assets/javascripts/discourse/controllers/search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/search.js.es6 @@ -9,9 +9,32 @@ export default Em.ArrayController.extend(Discourse.Presence, { contextChanged: function(){ - this.setProperties({ term: "", content: [], resultCount: 0, urls: [] }); + if(this.get('searchContextEnabled')){ + this._dontSearch = true; + this.set('searchContextEnabled', false); + this._dontSearch = false; + } }.observes("searchContext"), + searchContextDescription: function(){ + var ctx = this.get('searchContext'); + if (ctx) { + switch(Em.get(ctx, 'type')) { + case 'topic': + return I18n.t('search.context.topic'); + case 'user': + return I18n.t('search.context.user', {username: Em.get(ctx, 'user.username')}); + case 'category': + return I18n.t('search.context.category', {category: Em.get(ctx, 'category.name')}); + } + } + }.property('searchContext'), + + searchContextEnabledChanged: function(){ + if(this._dontSearch){ return; } + this.newSearchNeeded(); + }.observes('searchContextEnabled'), + // If we need to perform another search newSearchNeeded: function() { this.set('noResults', false); @@ -29,9 +52,14 @@ export default Em.ArrayController.extend(Discourse.Presence, { var self = this; this.setProperties({ resultCount: 0, urls: [] }); + var context; + if(this.get('searchContextEnabled')){ + context = this.get('searchContext'); + } + return Discourse.Search.forTerm(term, { typeFilter: typeFilter, - searchContext: this.get('searchContext') + searchContext: context }).then(function(results) { var urls = []; if (results) { diff --git a/app/assets/javascripts/discourse/templates/search.js.handlebars b/app/assets/javascripts/discourse/templates/search.js.handlebars index 68f7a971b97..2b1fbb1e86a 100644 --- a/app/assets/javascripts/discourse/templates/search.js.handlebars +++ b/app/assets/javascripts/discourse/templates/search.js.handlebars @@ -1,5 +1,14 @@ -{{view 'search-text-field' value=term searchContext=searchContext id="search-term"}} -{{#unless loading}} +{{view 'search-text-field' value=term searchContextEnabled=searchContextEnabled searchContext=searchContext id="search-term"}} +{{#if searchContext}} +
+ +
+{{/if}} +{{#if loading}} +
+{{else}} {{#unless noResults}} {{#each resultType in content}}