Cleanup Identity edit window

This commit is contained in:
the-djmaze 2023-02-21 16:26:21 +01:00
parent d495369688
commit 0f82ad1109
2 changed files with 27 additions and 49 deletions

View file

@ -1,4 +1,5 @@
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { addObservablesTo } from 'External/ko';
import { getNotification } from 'Common/Translator'; import { getNotification } from 'Common/Translator';
@ -6,49 +7,34 @@ import Remote from 'Remote/User/Fetch';
import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { AbstractViewPopup } from 'Knoin/AbstractViews';
import { IdentityModel } from 'Model/Identity';
export class IdentityPopupView extends AbstractViewPopup { export class IdentityPopupView extends AbstractViewPopup {
constructor() { constructor() {
super('Identity'); super('Identity');
this.id = '';
addObservablesTo(this, { addObservablesTo(this, {
id: '',
edit: false, edit: false,
owner: false,
email: '', email: '',
emailFocused: false, emailFocused: false,
name: '', name: '',
nameFocused: false,
replyTo: '', replyTo: '',
replyToFocused: false, showReplyTo: false,
bcc: '', bcc: '',
bccFocused: false, showBcc: false,
bccHasError: false,
signature: '', signature: '',
signatureInsertBefore: false, signatureInsertBefore: false,
showBcc: false,
showReplyTo: false,
submitRequest: false, submitRequest: false,
submitError: '' submitError: ''
}); });
addSubscribablesTo(this, {
replyTo: value => {
if (false === this.showReplyTo() && value.length) {
this.showReplyTo(true);
}
},
bcc: value => {
if (false === this.showBcc() && value.length) {
this.showBcc(true);
}
}
});
/* /*
this.email.valueHasMutated(); this.email.valueHasMutated();
this.replyTo.valueHasMutated(); this.replyTo.valueHasMutated();
@ -61,8 +47,9 @@ export class IdentityPopupView extends AbstractViewPopup {
this.signature?.__fetchEditorValue?.(); this.signature?.__fetchEditorValue?.();
this.submitRequest(true); this.submitRequest(true);
const data = new FormData(form); const data = new FormData(form);
data.set('Id', this.id); data.set('Id', this.id());
data.set('Signature', this.signature()); data.set('Signature', this.signature());
data.set('SignatureInsertBefore', this.signatureInsertBefore() ? 1 : 0);
Remote.request('IdentityUpdate', iError => { Remote.request('IdentityUpdate', iError => {
this.submitRequest(false); this.submitRequest(false);
if (iError) { if (iError) {
@ -88,32 +75,23 @@ export class IdentityPopupView extends AbstractViewPopup {
if (identity) { if (identity) {
this.edit(true); 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);
} else { } else {
this.edit(false); this.edit(false);
identity = new IdentityModel;
this.id = Jua.randomId(); identity.id(Jua.randomId());
this.name('');
this.email('');
this.replyTo('');
this.bcc('');
this.signature('');
this.signatureInsertBefore(false);
this.owner(false);
} }
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());
} }
afterShow() { afterShow() {
this.owner() || this.emailFocused(true); this.id() ? this.emailFocused(true) : this.nameFocused(true);
} }
} }

View file

@ -12,29 +12,29 @@
<div class="control-group"> <div class="control-group">
<label data-i18n="GLOBAL/EMAIL"></label> <label data-i18n="GLOBAL/EMAIL"></label>
<div> <div>
<div class="textEmail" data-bind="text: email, visible: owner"></div> <div class="textEmail" data-bind="text: email, visible: !id()"></div>
<input name="Email" type="email" class="input-xlarge" autofocus="" <input name="Email" type="email" class="input-xlarge" autofocus=""
autocomplete="off" autocorrect="off" autocapitalize="off" autocomplete="off" autocorrect="off" autocapitalize="off"
data-bind="visible: !owner(), value: email, hasfocus: emailFocused, attr: {required: !owner()}"> data-bind="visible: id, value: email, hasfocus: emailFocused, attr: {required: id}">
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label data-i18n="GLOBAL/NAME"></label> <label data-i18n="GLOBAL/NAME"></label>
<input name="Name" type="text" class="input-xlarge" <input name="Name" type="text" class="input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" autocomplete="off" autocorrect="off" autocapitalize="off"
data-bind="value: name"> data-bind="value: name, hasfocus: nameFocused">
</div> </div>
<div class="control-group" data-bind="visible: showReplyTo"> <div class="control-group" data-bind="visible: showReplyTo">
<label data-i18n="GLOBAL/REPLY_TO"></label> <label data-i18n="GLOBAL/REPLY_TO"></label>
<input name="ReplyTo" type="email" class="inputReplyTo input-xlarge" <input name="ReplyTo" type="email" class="inputReplyTo input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" autocomplete="off" autocorrect="off" autocapitalize="off"
data-bind="value: replyTo, hasfocus: replyToFocused"> data-bind="value: replyTo">
</div> </div>
<div class="control-group" data-bind="visible: showBcc"> <div class="control-group" data-bind="visible: showBcc">
<label data-i18n="GLOBAL/BCC"></label> <label data-i18n="GLOBAL/BCC"></label>
<input name="Bcc" type="email" class="inputBcc input-xlarge" <input name="Bcc" type="email" class="inputBcc input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" autocomplete="off" autocorrect="off" autocapitalize="off"
data-bind="value: bcc, hasfocus: bccFocused"> data-bind="value: bcc">
</div> </div>
<div class="control-group" data-bind="visible: !showReplyTo() || !showBcc()"> <div class="control-group" data-bind="visible: !showReplyTo() || !showBcc()">
<div> <div>