snappymail/dev/View/Popup/Identity.js

97 lines
2 KiB
JavaScript
Raw Normal View History

2023-02-21 23:26:21 +08:00
import { addObservablesTo } from 'External/ko';
2019-07-05 03:19:24 +08:00
import { getNotification } from 'Common/Translator';
2016-06-30 08:02:45 +08:00
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
import { AbstractViewPopup } from 'Knoin/AbstractViews';
2016-06-30 08:02:45 +08:00
2023-02-21 23:26:21 +08:00
import { IdentityModel } from 'Model/Identity';
2022-02-24 21:01:41 +08:00
export class IdentityPopupView extends AbstractViewPopup {
constructor() {
super('Identity');
2016-06-30 08:02:45 +08:00
addObservablesTo(this, {
2023-02-21 23:26:21 +08:00
id: '',
edit: false,
2020-10-27 18:09:24 +08:00
email: '',
emailFocused: false,
2020-10-27 18:09:24 +08:00
name: '',
2023-02-21 23:26:21 +08:00
nameFocused: false,
2020-10-27 18:09:24 +08:00
replyTo: '',
2023-02-21 23:26:21 +08:00
showReplyTo: false,
2020-10-27 18:09:24 +08:00
bcc: '',
2023-02-21 23:26:21 +08:00
showBcc: false,
signature: '',
signatureInsertBefore: false,
submitRequest: false,
submitError: ''
});
2020-10-27 18:09:24 +08:00
/*
this.email.valueHasMutated();
this.replyTo.valueHasMutated();
this.bcc.valueHasMutated();
*/
2016-09-10 06:38:16 +08:00
}
2022-09-24 07:20:02 +08:00
submitForm(form) {
if (!this.submitRequest() && form.reportValidity()) {
2022-09-02 17:52:07 +08:00
this.signature?.__fetchEditorValue?.();
2022-02-25 20:12:44 +08:00
this.submitRequest(true);
2022-09-24 07:20:02 +08:00
const data = new FormData(form);
2023-02-21 23:26:21 +08:00
data.set('Id', this.id());
2022-09-24 07:20:02 +08:00
data.set('Signature', this.signature());
2022-02-25 20:12:44 +08:00
Remote.request('IdentityUpdate', iError => {
this.submitRequest(false);
if (iError) {
this.submitError(getNotification(iError));
} 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
);
}
}
2022-09-24 07:20:02 +08:00
/**
* @param {?IdentityModel} oIdentity
*/
onShow(identity) {
this.showBcc(false);
this.showReplyTo(false);
this.submitRequest(false);
this.submitError('');
2019-07-05 03:19:24 +08:00
if (identity) {
this.edit(true);
2019-07-05 03:19:24 +08:00
} else {
2022-09-24 07:20:02 +08:00
this.edit(false);
2023-02-21 23:26:21 +08:00
identity = new IdentityModel;
identity.id(Jua.randomId());
}
2023-02-21 23:26:21 +08:00
this.id(identity.id() || '');
this.name(identity.name());
this.email(identity.email());
this.replyTo(identity.replyTo());
this.showReplyTo(0 < identity.replyTo().length);
this.bcc(identity.bcc());
this.showBcc(0 < identity.bcc().length);
this.signature(identity.signature());
this.signatureInsertBefore(identity.signatureInsertBefore());
2016-06-30 08:02:45 +08:00
}
afterShow() {
2023-02-21 23:26:21 +08:00
this.id() ? this.emailFocused(true) : this.nameFocused(true);
2016-06-30 08:02:45 +08:00
}
}