Reputation: 502
I am building a log-in form in Ember.
App.Router = Ember.Router.extend( // states here);
Then I have the following view
App.SignInView = Ember.View.extend
templateName: 'signin'
submitLogin: (event) ->
login = @getPath('email.value')
password = @getPath('password.value')
console.log "Login: " + login + " Password: " + password
// how do I redirect to a different state? I.e. "loggedIn"
submitLogin is triggered from the template by using {{action "submitLogin"}}
As you see from this snippet, I want to check a username/password before showing the "private" area of the web app. What's the best practice here?
Upvotes: 1
Views: 2206
Reputation: 502
This discussion Ember.js get view triggering event in the router led me to the following design:
Forward the event to the router by using smth. like this inside the view
App.router.send('signUp',context)
The key thing here is that I don't need to change the state of the router outside the router, but rather send the context to be handled by the current state of the router.
Upvotes: 1
Reputation: 9236
You should implement your submitLogin
hander inside the current route, and transition route from the handler, which becomes something like:
submitLogin: (router, event) ->
login = event.context.email // e.g
password = event.context.password // e.g
// do ajax call here...
// and from reply handlers:
router.transitionTo('loggedIn');
You will have to pass the email & password container in the action helper, e.g: {{action submitLogin this}}
Upvotes: 3