1 | define(["../session", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", "dijit/registry", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang", "dojo/on", "dojo/when", "dojo/text!./templates/LoginDialogWrapper.html"], function(session, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, registry, declare, event, lang, on, when, template) { |
---|
2 | return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { |
---|
3 | templateString: template, |
---|
4 | _fx: null, |
---|
5 | startup: function() { |
---|
6 | if (this._started) { return; } |
---|
7 | this.inherited(arguments); |
---|
8 | this.own(on(session, 'change', lang.hitch(this, 'onUserChange'))); |
---|
9 | this.own(this.loginForm.on('change', lang.hitch(this, '_handleFormChange'))); |
---|
10 | this.onUserChange(session.get()); |
---|
11 | }, |
---|
12 | _handleFormChange: function() { |
---|
13 | this.infoNode.innerHTML = ""; |
---|
14 | }, |
---|
15 | onLogin: function(evt) { |
---|
16 | this.infoNode.innerHTML = ""; |
---|
17 | if (this.loginForm.validate()) { |
---|
18 | var value = this.loginForm.get('value'); |
---|
19 | session.login(value.username, value.password) |
---|
20 | .then(lang.hitch(this,function() { |
---|
21 | this._fx = when(this._fx).then(lang.hitch(this.loginDialog,'hide')); |
---|
22 | }), lang.hitch(this,function() { |
---|
23 | this.infoNode.innerHTML = "Login failed."; |
---|
24 | })); |
---|
25 | } |
---|
26 | if (evt) { event.stop(evt); } |
---|
27 | return false; |
---|
28 | }, |
---|
29 | onUserChange: function(user) { |
---|
30 | this.infoNode.innerHTML = ""; |
---|
31 | this._fx = when(this._fx).then(lang.hitch(this.loginDialog,function() { |
---|
32 | return user ? this.hide() : this.show(); |
---|
33 | })); |
---|
34 | } |
---|
35 | }); |
---|
36 | }); |
---|