1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dijit/Dialog', |
---|
2 | 'dijit/_WidgetsInTemplateMixin','../auth', 'dojo/text!./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 | this.inherited(arguments); |
---|
12 | this.loginForm.on('submit',lang.hitch(this,'onLogin')); |
---|
13 | }, |
---|
14 | show: function() { |
---|
15 | this.loginErrors.innerHTML = ''; |
---|
16 | this.loginForm.reset(); |
---|
17 | this.inherited(arguments); |
---|
18 | }, |
---|
19 | onLogin: function(evt) { |
---|
20 | this.loginErrors.innerHTML = ''; |
---|
21 | var data = this.loginForm.get('value'); |
---|
22 | auth.login(data.email,data.password) |
---|
23 | .then(lang.hitch(this,function() { |
---|
24 | this.hide(); |
---|
25 | content.initial(); |
---|
26 | }),lang.hitch(this,function() { |
---|
27 | this.loginErrors.innerHTML = 'Login failed.'; |
---|
28 | })); |
---|
29 | event.stop(evt); |
---|
30 | return false; |
---|
31 | }, |
---|
32 | onRegister: function() { |
---|
33 | this.loginErrors.innerHTML = ''; |
---|
34 | var data = this.loginForm.get('value'); |
---|
35 | auth.register(data.email,data.password) |
---|
36 | .then(lang.hitch(this,function() { |
---|
37 | this.hide(); |
---|
38 | content.initial(); |
---|
39 | }),lang.hitch(this,function() { |
---|
40 | this.loginErrors.innerHTML = 'Register failed.'; |
---|
41 | })); |
---|
42 | } |
---|
43 | }); |
---|
44 | }); |
---|