mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Display details about the search context in the placeholder
This commit is contained in:
parent
b1bdebd611
commit
4cf1d9c266
7 changed files with 45 additions and 8 deletions
|
@ -15,7 +15,7 @@ Discourse.Category = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
searchContext: function() {
|
||||
return ({ type: 'category', id: this.get('id') });
|
||||
return ({ type: 'category', id: this.get('id'), category: this });
|
||||
}.property('id'),
|
||||
|
||||
url: function() {
|
||||
|
|
|
@ -29,7 +29,7 @@ Discourse.User = Discourse.Model.extend({
|
|||
}).property('username'),
|
||||
|
||||
searchContext: function() {
|
||||
return ({ type: 'user', id: this.get('username_lower') });
|
||||
return ({ type: 'user', id: this.get('username_lower'), user: this });
|
||||
}.property('username_lower'),
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,9 @@ Discourse.UserRoute = Discourse.Route.extend({
|
|||
|
||||
setupController: function(controller, user) {
|
||||
user.findDetails();
|
||||
|
||||
// Add a search context
|
||||
this.controllerFor('search').set('searchContext', user.get('searchContext'));
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
|
@ -26,9 +29,6 @@ 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.get('searchContext'));
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{textField value=term placeholderKey="search.placeholder"}}
|
||||
{{view Discourse.SearchTextField valueBinding="term" searchContextBinding="searchContext"}}
|
||||
{{#unless loading}}
|
||||
{{#unless noResults}}
|
||||
{{#each resultType in content}}
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
Discourse.TextField = Ember.TextField.extend({
|
||||
attributeBindings: ['autocorrect', 'autocapitalize', 'autofocus'],
|
||||
|
||||
placeholder: (function() {
|
||||
placeholder: function() {
|
||||
if( this.get('placeholderKey') ) {
|
||||
return Em.String.i18n(this.get('placeholderKey'));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}).property('placeholderKey')
|
||||
}.property('placeholderKey')
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
This is a text field that supports a dynamic placeholder based on search context.
|
||||
|
||||
@class SearchTextField
|
||||
@extends Discourse.TextField
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.SearchTextField = Discourse.TextField.extend({
|
||||
|
||||
/**
|
||||
A dynamic placeholder for the search field based on our context
|
||||
|
||||
@property placeholder
|
||||
**/
|
||||
placeholder: function() {
|
||||
|
||||
var ctx = this.get('searchContext');
|
||||
if (ctx) {
|
||||
switch(Em.get(ctx, 'type')) {
|
||||
case 'user':
|
||||
return Em.String.i18n('search.prefer.user', {username: Em.get(ctx, 'user.username')});
|
||||
case 'category':
|
||||
return Em.String.i18n('search.prefer.category', {category: Em.get(ctx, 'category.name')});
|
||||
}
|
||||
}
|
||||
|
||||
return Em.String.i18n('search.placeholder');
|
||||
}.property('searchContext')
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -435,6 +435,10 @@ en:
|
|||
no_results: "No results found."
|
||||
searching: "Searching ..."
|
||||
|
||||
prefer:
|
||||
user: "search will prefer results by @{{username}}"
|
||||
category: "search will prefer results in {{category}}"
|
||||
|
||||
site_map: "go to another topic list or category"
|
||||
go_back: 'go back'
|
||||
current_user: 'go to your user page'
|
||||
|
|
Loading…
Reference in a new issue