Files
snappymail/dev/View/Popup/Account.js
RainLoop Team 17669b7be0 es5 -> es2015 (last stage)
Signature plugin fixes
Add view decorator
A large number of fixes
2016-08-20 20:30:16 +03:00

122 lines
2.5 KiB
JavaScript

import ko from 'ko';
import {StorageResultType, Notification} from 'Common/Enums';
import {trim, createCommand} from 'Common/Utils';
import {getNotification} from 'Common/Translator';
import Remote from 'Remote/User/Ajax';
import {getApp} from 'Helper/Apps/User';
import {view, ViewType} from 'Knoin/Knoin';
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
@view({
name: 'View/Popup/Account',
type: ViewType.Popup,
templateID: 'PopupsAccount'
})
class AccountPopupView extends AbstractViewNext
{
constructor() {
super();
this.isNew = ko.observable(true);
this.email = ko.observable('');
this.password = ko.observable('');
this.emailError = ko.observable(false);
this.passwordError = ko.observable(false);
this.email.subscribe(() => {
this.emailError(false);
});
this.password.subscribe(() => {
this.passwordError(false);
});
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.submitErrorAdditional = ko.observable('');
this.emailFocus = ko.observable(false);
this.addAccountCommand = createCommand(() => {
this.emailError('' === trim(this.email()));
this.passwordError('' === trim(this.password()));
if (this.emailError() || this.passwordError())
{
return false;
}
this.submitRequest(true);
Remote.accountSetup((result, data) => {
this.submitRequest(false);
if (StorageResultType.Success === result && data)
{
if (data.Result)
{
getApp().accountsAndIdentities();
this.cancelCommand();
}
else
{
this.submitError(data.ErrorCode ? getNotification(data.ErrorCode) :
getNotification(Notification.UnknownError));
if (data.ErrorMessageAdditional)
{
this.submitErrorAdditional(data.ErrorMessageAdditional);
}
}
}
else
{
this.submitError(getNotification(Notification.UnknownError));
this.submitErrorAdditional('');
}
}, this.email(), this.password(), this.isNew());
return true;
}, () => !this.submitRequest());
}
clearPopup() {
this.isNew(true);
this.email('');
this.password('');
this.emailError(false);
this.passwordError(false);
this.submitRequest(false);
this.submitError('');
this.submitErrorAdditional('');
}
onShow(account) {
this.clearPopup();
if (account && account.canBeEdit())
{
this.isNew(false);
this.email(account.email);
}
}
onShowWithDelay() {
this.emailFocus(true);
}
}
module.exports = AccountPopupView;