2022-10-31 05:19:52 +08:00
|
|
|
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
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-01-24 17:25:23 +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 {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Identity');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.id = '';
|
2022-10-31 05:19:52 +08:00
|
|
|
addObservablesTo(this, {
|
2020-10-26 19:54:03 +08:00
|
|
|
edit: false,
|
|
|
|
owner: false,
|
2020-10-27 18:09:24 +08:00
|
|
|
|
|
|
|
email: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
emailFocused: false,
|
2020-10-27 18:09:24 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
name: '',
|
2020-10-27 18:09:24 +08:00
|
|
|
|
|
|
|
replyTo: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
replyToFocused: false,
|
2020-10-27 18:09:24 +08:00
|
|
|
|
|
|
|
bcc: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
bccFocused: false,
|
2020-10-27 18:09:24 +08:00
|
|
|
bccHasError: false,
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
signature: '',
|
|
|
|
signatureInsertBefore: false,
|
|
|
|
|
|
|
|
showBcc: false,
|
|
|
|
showReplyTo: false,
|
|
|
|
|
|
|
|
submitRequest: false,
|
|
|
|
submitError: ''
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-10-31 05:19:52 +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);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
});
|
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
|
|
|
}
|
2015-02-06 23:26:20 +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();
|
2022-03-04 16:21:24 +08:00
|
|
|
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
|
|
|
);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-09-24 07:20:02 +08:00
|
|
|
/**
|
|
|
|
* @param {?IdentityModel} oIdentity
|
|
|
|
*/
|
|
|
|
onShow(identity) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.showBcc(false);
|
|
|
|
this.showReplyTo(false);
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.submitRequest(false);
|
|
|
|
this.submitError('');
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (identity) {
|
2016-08-17 06:01:20 +08:00
|
|
|
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());
|
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
this.owner(!this.id);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2022-09-24 07:20:02 +08:00
|
|
|
this.edit(false);
|
|
|
|
|
2020-10-03 05:54:15 +08:00
|
|
|
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-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2022-02-25 05:40:17 +08:00
|
|
|
afterShow() {
|
2021-02-15 23:05:38 +08:00
|
|
|
this.owner() || this.emailFocused(true);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|