snappymail/dev/View/Popup/Account.js

84 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { getNotification } from 'Common/Translator';
import Remote from 'Remote/User/Fetch';
2014-08-25 15:10:51 +08:00
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class AccountPopupView extends AbstractViewPopup {
constructor() {
super('Account');
2014-08-22 23:08:56 +08:00
this.addObservables({
isNew: true,
email: '',
password: '',
2014-10-22 00:49:15 +08:00
emailError: false,
passwordError: false,
submitRequest: false,
submitError: '',
submitErrorAdditional: ''
});
this.email.subscribe(() => this.emailError(false));
this.password.subscribe(() => this.passwordError(false));
decorateKoCommands(this, {
addAccountCommand: self => !self.submitRequest()
});
2016-09-10 06:38:16 +08:00
}
2016-09-10 06:38:16 +08:00
addAccountCommand() {
this.emailError(!this.email().trim());
this.passwordError(!this.password().trim());
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (this.emailError() || this.passwordError()) {
2016-09-10 06:38:16 +08:00
return false;
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.submitRequest(true);
2014-08-21 23:08:34 +08:00
Remote.request('AccountSetup', (iError, data) => {
2019-07-05 03:19:24 +08:00
this.submitRequest(false);
if (iError) {
this.submitError(getNotification(iError));
this.submitErrorAdditional((data && data.ErrorMessageAdditional) || '');
2019-07-05 03:19:24 +08:00
} else {
rl.app.accountsAndIdentities();
this.cancelCommand();
2016-09-10 06:38:16 +08:00
}
}, {
Email: this.email(),
Password: this.password(),
New: this.isNew() ? 1 : 0
}
2019-07-05 03:19:24 +08:00
);
2016-09-10 06:38:16 +08:00
return true;
}
2021-11-03 21:58:34 +08:00
onShow(account) {
2021-11-15 17:56:52 +08:00
if (account && account.isAdditional()) {
2021-11-03 21:58:34 +08:00
this.isNew(false);
this.email(account.email);
} else {
this.isNew(true);
this.email('');
}
this.password('');
2014-08-21 23:08:34 +08:00
this.emailError(false);
this.passwordError(false);
this.submitRequest(false);
this.submitError('');
this.submitErrorAdditional('');
}
}
2013-12-29 04:42:07 +08:00
2019-07-05 03:19:24 +08:00
export { AccountPopupView, AccountPopupView as default };