Created
February 7, 2013 03:29
-
-
Save walter/4728166 to your computer and use it in GitHub Desktop.
Example blog application route handlers and the mixin they use
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
| # see mixins/posts_formable below | |
| App.PostsNewRoute = Ember.Route.extend App.PostsFormable, | |
| # set up a new blank instance of Post for the form's content | |
| model: -> | |
| App.Post.createRecord() | |
| # perhaps alternatively, this could use 'needs post' in controller | |
| # for setting the model instance | |
| App.PostEditRoute = Ember.Route.extend App.PostsFormable, | |
| model: -> | |
| @modelFor 'post' | |
| # form mixin used by both new and edit | |
| # mixin, so new and edit can use same template/view | |
| App.PostsFormable = Ember.Mixin.create | |
| renderTemplate: -> | |
| @render 'posts/form', -> | |
| outlet: 'modal' | |
| events: | |
| cancel: (post) -> | |
| post.transaction.rollback() | |
| @transitionTo 'posts' | |
| submit: (post) -> | |
| # TODO: add validation handling | |
| post.get('store').commit() | |
| if post.didCreate | |
| @transitionTo 'posts' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment