mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-29 15:26:09 +00:00
122 lines
2.5 KiB
JavaScript
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;
|