Skip to content

Instantly share code, notes, and snippets.

@endash
Created January 10, 2014 20:31
Show Gist options
  • Save endash/8362018 to your computer and use it in GitHub Desktop.
Save endash/8362018 to your computer and use it in GitHub Desktop.
App.UserTypeaheadView = Ember.TextField.extend({
clientId: null,
didInsertElement: function () {
this.$().typeahead({
name: 'client',
template: Handlebars.compile([
'<img src="{{icon_url}}" width="48" height="48" class="pull-left">',
'<label>',
'<strong>{{value}}</strong><br>',
'{{location}}',
'</label>'
].join('')),
remote: {
url: '/api/users?name=%QUERY',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Token " + App.get('current_user.access_token'));
},
filter: function (data) {
return Ember.A(data.users).map(function (u) {
return {
value: u.full_name,
location: u.location,
icon_url: u.icon_url,
id: u.id,
tokens: [u.first_name, u.last_name]
};
});
}
}
});
this.$().on('typeahead:selected', null, $.proxy(this.selected, this));
this.$().on('typeahead:autocompleted', null, $.proxy(this.selected, this));
},
selected: function (evt, datum) {
this.set('user', datum);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment