Created
January 10, 2014 20:31
-
-
Save endash/8362018 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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