Skip to content

Commit

Permalink
Display details about the search context in the placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed May 29, 2013
1 parent b1bdebd commit 4cf1d9c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/discourse/models/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/discourse/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

/**
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/discourse/routes/user_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

});

Expand Down
33 changes: 33 additions & 0 deletions app/assets/javascripts/discourse/views/search/search_text_field.js
Original file line number Diff line number Diff line change
@@ -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')

});


4 changes: 4 additions & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 4cf1d9c

Please sign in to comment.