ログインという非常に単純なものを作成しようとしています。
これは私のテンプレートです:
<script type="text/x-handlebars" data-template-name="login">
<div class="row well">
<form class="form-inline">
{{input value=email type="text" placeholder="Email?"}}
{{input value=password type="password" placeholder="Password?"}}
{{#view App.LoginView}}
<button id="login-button" type="submit" class="btn">Sign in</button>
{{/view}}
</form>
{{#if not_logged}}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>
{{/if}}
</div>
</script>
景色:
App.LoginView = Ember.View.extend(
{
tagName: "span",
click: function()
{
this.$("#login-button").button("loading");
this.get("controller").send("do_login");
}
});
コントローラ:
App.LoginController = Ember.Controller.extend(
{
is_logged: true,
do_login: function()
{
/** some ajax comes here **/
}
});
したがって、ユーザーがボタンをクリックすると、状態が「読み込み中」に変わります。問題は、ログインが失敗した場合、どうすればそれをビューに通知して、これを実行できるかということです. $("#login-button").button("reset"); ?