snappymail/dev/View/Popup/Account.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

import { addObservablesTo } from 'External/ko';
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 { AbstractViewPopup } from 'Knoin/AbstractViews';
2022-02-24 21:01:41 +08:00
export class AccountPopupView extends AbstractViewPopup {
constructor() {
super('Account');
2014-08-22 23:08:56 +08:00
addObservablesTo(this, {
isNew: true,
name: '',
email: '',
password: '',
2014-10-22 00:49:15 +08:00
submitRequest: false,
submitError: '',
submitErrorAdditional: ''
});
2016-09-10 06:38:16 +08:00
}
2022-09-24 07:20:02 +08:00
submitForm(form) {
if (!this.submitRequest() && form.reportValidity()) {
const data = new FormData(form);
data.set('New', this.isNew() ? 1 : 0);
this.submitRequest(true);
Remote.request('AccountSetup', (iError, data) => {
this.submitRequest(false);
if (iError) {
this.submitError(getNotification(iError));
this.submitErrorAdditional(data?.ErrorMessageAdditional);
} else {
rl.app.accountsAndIdentities();
this.close();
2022-02-25 20:12:44 +08:00
}
2022-09-24 07:20:02 +08:00
}, data
);
2022-02-25 20:12:44 +08:00
}
}
onHide() {
this.password('');
this.submitRequest(false);
this.submitError('');
this.submitErrorAdditional('');
}
onShow(account) {
let edit = account?.isAdditional();
this.isNew(!edit);
this.name(edit ? account.name : '');
this.email(edit ? account.email : '');
}
}