snappymail/dev/View/Popup/Identity.js

121 lines
2.4 KiB
JavaScript
Raw Normal View History

import { addObservablesTo, addSubscribablesTo } 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
2022-02-24 21:01:41 +08:00
export class IdentityPopupView extends AbstractViewPopup {
constructor() {
super('Identity');
2016-06-30 08:02:45 +08:00
this.id = '';
addObservablesTo(this, {
edit: false,
owner: false,
2020-10-27 18:09:24 +08:00
email: '',
emailFocused: false,
2020-10-27 18:09:24 +08:00
name: '',
2020-10-27 18:09:24 +08:00
replyTo: '',
replyToFocused: false,
2020-10-27 18:09:24 +08:00
bcc: '',
bccFocused: false,
2020-10-27 18:09:24 +08:00
bccHasError: false,
signature: '',
signatureInsertBefore: false,
showBcc: false,
showReplyTo: false,
submitRequest: false,
submitError: ''
});
2016-06-30 08:02:45 +08:00
addSubscribablesTo(this, {
2020-10-27 18:09:24 +08:00
replyTo: value => {
if (false === this.showReplyTo() && value.length) {
this.showReplyTo(true);
}
},
bcc: value => {
if (false === this.showBcc() && value.length) {
this.showBcc(true);
}
}
});
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);
data.set('Id', this.id);
data.set('Signature', this.signature());
data.set('SignatureInsertBefore', this.signatureInsertBefore() ? 1 : 0);
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);
this.id = identity.id() || '';
this.name(identity.name());
this.email(identity.email());
this.replyTo(identity.replyTo());
this.bcc(identity.bcc());
this.signature(identity.signature());
this.signatureInsertBefore(identity.signatureInsertBefore());
this.owner(!this.id);
2019-07-05 03:19:24 +08:00
} else {
2022-09-24 07:20:02 +08:00
this.edit(false);
this.id = Jua.randomId();
2022-09-24 07:20:02 +08:00
this.name('');
this.email('');
this.replyTo('');
this.bcc('');
this.signature('');
this.signatureInsertBefore(false);
this.owner(false);
}
2016-06-30 08:02:45 +08:00
}
afterShow() {
2021-02-15 23:05:38 +08:00
this.owner() || this.emailFocused(true);
2016-06-30 08:02:45 +08:00
}
}