forked from verdnatura/hedera-web
112 lines
2.0 KiB
JavaScript
112 lines
2.0 KiB
JavaScript
var Tpl = require('./login.xml');
|
|
require('./login.scss');
|
|
|
|
module.exports = new Class({
|
|
Extends: Vn.Component,
|
|
Properties:
|
|
{
|
|
conn:
|
|
{
|
|
type: Db.Connection
|
|
,set(x) {
|
|
this.link({_conn: x}, {'loading-changed': this._onConnLoadChange});
|
|
}
|
|
,get() {
|
|
return this._conn;
|
|
}
|
|
}
|
|
}
|
|
|
|
,initialize(props) {
|
|
Vn.Component.prototype.initialize.call(this, props);
|
|
this.loadTemplateFromString(Tpl);
|
|
|
|
//this.$.socialBar.conn = this._conn;
|
|
|
|
var self = this;
|
|
this.$.form.onsubmit = function() {
|
|
self._onSubmit();
|
|
return false;
|
|
};
|
|
}
|
|
|
|
,_onConnLoadChange(conn, isLoading) {
|
|
if (isLoading)
|
|
this.$.spinner.start();
|
|
else
|
|
this.$.spinner.stop();
|
|
}
|
|
|
|
,show() {
|
|
document.body.appendChild(this.node);
|
|
|
|
var lastUser = localStorage.getItem('hederaLastUser');
|
|
|
|
if (lastUser)
|
|
this.$.user.value = lastUser;
|
|
|
|
this._focusUserInput();
|
|
}
|
|
|
|
,_onSubmit() {
|
|
this._conn.open(
|
|
this.$.user.value,
|
|
this.$.pass.value,
|
|
this.$.remember.checked,
|
|
this._onConnOpen.bind(this)
|
|
);
|
|
this._disableUi(true);
|
|
}
|
|
|
|
,_onConnOpen(conn, success, error) {
|
|
this.$.pass.value = '';
|
|
this._disableUi(false);
|
|
|
|
if (success) {
|
|
var user = this.$.user.value;
|
|
|
|
if (user)
|
|
localStorage.setItem('hederaLastUser', user);
|
|
|
|
this.emit('login');
|
|
} else {
|
|
this._focusUserInput();
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
,hide() {
|
|
Vn.Node.remove(this.node);
|
|
}
|
|
|
|
,_focusUserInput() {
|
|
var userEntry = this.$.user;
|
|
userEntry.focus();
|
|
userEntry.select();
|
|
}
|
|
|
|
,_disableUi(disabled) {
|
|
this.$.user.disabled = disabled;
|
|
this.$.pass.disabled = disabled;
|
|
this.$.submit.disabled = disabled;
|
|
}
|
|
|
|
,onPasswordLost() {
|
|
var user = this.$.user.value;
|
|
|
|
if (!user)
|
|
Htk.Toast.showError(_('Please write your user name'));
|
|
else
|
|
this._conn.send('user/recover-password', {recoverUser: user},
|
|
this._onPasswordRecovered.bind(this));
|
|
}
|
|
|
|
,_onPasswordRecovered(json, error) {
|
|
if (error)
|
|
throw error;
|
|
|
|
Htk.Toast.showMessage(_('A mail has been sent wich you can recover your password'));
|
|
}
|
|
});
|
|
|