mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
Display details about the search context in the placeholder
This commit is contained in:
@@ -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')
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user