source: Dev/trunk/src/client/qed-client/ui/LoginDialogWrapper.js @ 494

Last change on this file since 494 was 494, checked in by hendrikvanantwerpen, 11 years ago
  • Removed all Coffeescript from codebase (build process is still there).
  • Nicer message on failed login.
  • Own all event subscriptions from widgets.
  • Update objects in _ObjectPage with invalid info too, or our refresh will overwrite what user did.
File size: 1.8 KB
Line 
1define(["../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});
Note: See TracBrowser for help on using the repository browser.