1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dijit/Dialog', |
---|
2 | 'dijit/_WidgetsInTemplateMixin','../auth', 'dojo/text!./templates/LoginDialog.html', |
---|
3 | '../content','dijit/form/Form','dijit/form/Button','dijit/form/TextBox'], |
---|
4 | function (declare, lang, event, Dialog, _WidgetsInTemplateMixin, auth, template, content) { |
---|
5 | return declare([Dialog,_WidgetsInTemplateMixin], { |
---|
6 | templateString: template, |
---|
7 | widgetsInTemplate: true, |
---|
8 | title: "Login/Register", |
---|
9 | baseClass: "rftLoginDialog", |
---|
10 | startup: function() { |
---|
11 | if ( this._started ){ return; } |
---|
12 | this.inherited(arguments); |
---|
13 | this.loginForm.on('submit',lang.hitch(this,'onLogin')); |
---|
14 | }, |
---|
15 | show: function() { |
---|
16 | this.loginErrors.innerHTML = ''; |
---|
17 | this.loginForm.reset(); |
---|
18 | this.inherited(arguments); |
---|
19 | }, |
---|
20 | onLogin: function(evt) { |
---|
21 | this.loginErrors.innerHTML = ''; |
---|
22 | var data = this.loginForm.get('value'); |
---|
23 | auth.login(data.email,data.password) |
---|
24 | .then(lang.hitch(this,function() { |
---|
25 | this.hide(); |
---|
26 | content.initial(); |
---|
27 | }),lang.hitch(this,function() { |
---|
28 | this.loginErrors.innerHTML = 'Login failed.'; |
---|
29 | })); |
---|
30 | event.stop(evt); |
---|
31 | return false; |
---|
32 | }, |
---|
33 | onRegister: function() { |
---|
34 | this.loginErrors.innerHTML = ''; |
---|
35 | var data = this.loginForm.get('value'); |
---|
36 | auth.register(data.email,data.password) |
---|
37 | .then(lang.hitch(this,function() { |
---|
38 | this.hide(); |
---|
39 | content.initial(); |
---|
40 | }),lang.hitch(this,function() { |
---|
41 | this.loginErrors.innerHTML = 'Register failed.'; |
---|
42 | })); |
---|
43 | } |
---|
44 | }); |
---|
45 | }); |
---|