Created
April 18, 2013 19:03
-
-
Save boy-jer/5415373 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
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); | |
} | |
}); |
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
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