Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Created April 18, 2013 19:03
Show Gist options
  • Save boy-jer/5415373 to your computer and use it in GitHub Desktop.
Save boy-jer/5415373 to your computer and use it in GitHub Desktop.
template = template.replace(/@(\w+)/, "{{view Scvrush.UserLinkView username='$1'}}");
usernames = template.match(/@(\w+)/);
controllerFor('controllerWithText').set('usernames', usernames);
Scvrush.ControllerWithText = Em.Controller.extend({
init: function() {
var usernames = this.get('usernames'),
loadedusers = Scvrush.User.all();
usernames = usernames.filter(function(username) {
return !loadedusers.findProperty('username', username);
});
loadingusers = Scvrush.User.findQuery(usernames: usernames);
this.set('loadedUsers', loadedusers);
this.set('loadingUsers', loadingusers);
}
});
Scvrush.UserLinkView = Ember.View.extend({
tagName: "span",
didLoadUsers: function() {
if (this.get('controller.loadingUsers.isLoaded') {
this.notifyPropertyChange('user');
}
}.observes('controller.loadingUsers.isLoaded'),
user: function() {
return this.get("controller.loadedUsers").findProperty('username', this.get('username'));
}.property('username'),
template: Ember.Handlebars.compile("{{#if view.user}}{{#linkTo 'user' view.user}}@{{view.user.username}}{{/linkTo}}{{else}}@{{view.username}}{{/if}}")
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment