Restructure some popups to use <form>

This commit is contained in:
the-djmaze 2022-02-25 13:12:44 +01:00
parent 169dbfecca
commit b82d26b71b
7 changed files with 201 additions and 227 deletions

View file

@ -2,7 +2,6 @@ import { getNotification } from 'Common/Translator';
import Remote from 'Remote/User/Fetch'; import Remote from 'Remote/User/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { AbstractViewPopup } from 'Knoin/AbstractViews';
export class AccountPopupView extends AbstractViewPopup { export class AccountPopupView extends AbstractViewPopup {
@ -26,22 +25,15 @@ export class AccountPopupView extends AbstractViewPopup {
this.email.subscribe(() => this.emailError(false)); this.email.subscribe(() => this.emailError(false));
this.password.subscribe(() => this.passwordError(false)); this.password.subscribe(() => this.passwordError(false));
decorateKoCommands(this, {
addAccountCommand: self => !self.submitRequest()
});
}
addAccountCommand() {
this.emailError(!this.email().trim());
this.passwordError(!this.password().trim());
if (this.emailError() || this.passwordError()) {
return false;
} }
submitForm() {
if (!this.submitRequest()) {
const email = this.email().trim(), pass = this.password();
this.emailError(!email);
this.passwordError(!pass);
if (!this.emailError() && pass) {
this.submitRequest(true); this.submitRequest(true);
Remote.request('AccountSetup', (iError, data) => { Remote.request('AccountSetup', (iError, data) => {
this.submitRequest(false); this.submitRequest(false);
if (iError) { if (iError) {
@ -52,13 +44,13 @@ export class AccountPopupView extends AbstractViewPopup {
this.closeCommand(); this.closeCommand();
} }
}, { }, {
Email: this.email(), Email: email,
Password: this.password(), Password: pass,
New: this.isNew() ? 1 : 0 New: this.isNew() ? 1 : 0
} }
); );
}
return true; }
} }
onShow(account) { onShow(account) {

View file

@ -11,7 +11,6 @@ import { SettingsUserStore } from 'Stores/User/Settings';
import Remote from 'Remote/User/Fetch'; import Remote from 'Remote/User/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { AbstractViewPopup } from 'Knoin/AbstractViews';
import { setFolder, getFolderFromCacheList } from 'Common/Cache'; import { setFolder, getFolderFromCacheList } from 'Common/Cache';
@ -42,13 +41,10 @@ export class FolderCreatePopupView extends AbstractViewPopup {
); );
this.defaultOptionsAfterRender = defaultOptionsAfterRender; this.defaultOptionsAfterRender = defaultOptionsAfterRender;
decorateKoCommands(this, {
createFolderCommand: self => self.simpleFolderNameValidation(self.folderName())
});
} }
createFolderCommand() { submitForm() {
if (/^[^\\/]+$/g.test(this.folderName())) {
let parentFolderName = this.selectedParentValue(); let parentFolderName = this.selectedParentValue();
if (!parentFolderName && 1 < FolderUserStore.namespace.length) { if (!parentFolderName && 1 < FolderUserStore.namespace.length) {
parentFolderName = FolderUserStore.namespace.slice(0, FolderUserStore.namespace.length - 1); parentFolderName = FolderUserStore.namespace.slice(0, FolderUserStore.namespace.length - 1);
@ -81,9 +77,6 @@ export class FolderCreatePopupView extends AbstractViewPopup {
this.closeCommand(); this.closeCommand();
} }
simpleFolderNameValidation(sName) {
return /^[^\\/]+$/g.test(sName);
} }
onShow() { onShow() {

View file

@ -2,7 +2,6 @@ import { getNotification } from 'Common/Translator';
import Remote from 'Remote/User/Fetch'; import Remote from 'Remote/User/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { AbstractViewPopup } from 'Knoin/AbstractViews';
const reEmail = /^[^@\s]+@[^@\s]+$/; const reEmail = /^[^@\s]+@[^@\s]+$/;
@ -60,12 +59,10 @@ export class IdentityPopupView extends AbstractViewPopup {
this.replyTo.valueHasMutated(); this.replyTo.valueHasMutated();
this.bcc.valueHasMutated(); this.bcc.valueHasMutated();
*/ */
decorateKoCommands(this, {
addOrEditIdentityCommand: self => !self.submitRequest()
});
} }
addOrEditIdentityCommand() { submitForm() {
if (!this.submitRequest()) {
if (this.signature && this.signature.__fetchEditorValue) { if (this.signature && this.signature.__fetchEditorValue) {
this.signature.__fetchEditorValue(); this.signature.__fetchEditorValue();
} }
@ -79,17 +76,17 @@ export class IdentityPopupView extends AbstractViewPopup {
this.emailFocused(true); this.emailFocused(true);
} }
return false; return;
} }
if (this.replyToHasError()) { if (this.replyToHasError()) {
this.replyToFocused(true); this.replyToFocused(true);
return false; return;
} }
if (this.bccHasError()) { if (this.bccHasError()) {
this.bccFocused(true); this.bccFocused(true);
return false; return;
} }
this.submitRequest(true); this.submitRequest(true);
@ -112,8 +109,7 @@ export class IdentityPopupView extends AbstractViewPopup {
SignatureInsertBefore: this.signatureInsertBefore() ? 1 : 0 SignatureInsertBefore: this.signatureInsertBefore() ? 1 : 0
} }
); );
}
return true;
} }
clearPopup() { clearPopup() {

View file

@ -5,33 +5,30 @@
<span data-bind="visible: !isNew()" data-i18n="POPUPS_ADD_ACCOUNT/TITLE_UPDATE_ACCOUNT"></span> <span data-bind="visible: !isNew()" data-i18n="POPUPS_ADD_ACCOUNT/TITLE_UPDATE_ACCOUNT"></span>
</h3> </h3>
</header> </header>
<form class="modal-body form-horizontal" autocomplete="off"> <form id="accountform" class="modal-body form-horizontal" autocomplete="off" data-bind="submit: submitForm">
<div class="alert" data-bind="visible: '' !== submitError()"> <div class="alert" data-bind="visible: '' !== submitError()">
<a href="#" class="close" data-bind="click: function () { submitError('') }">×</a> <a href="#" class="close" data-bind="click: function () { submitError('') }">×</a>
<span data-bind="text: submitError"></span> <span data-bind="text: submitError"></span>
<div data-bind="visible: submitErrorAdditional"> <div data-bind="visible: submitErrorAdditional, text: submitErrorAdditional"></div>
<br>
<span data-bind="text: submitErrorAdditional"></span>
</div>
</div> </div>
<div class="control-group" data-bind="css: {'error': emailError}"> <div class="control-group" data-bind="css: {'error': emailError}">
<label data-i18n="GLOBAL/EMAIL"></label> <label data-i18n="GLOBAL/EMAIL"></label>
<strong style="margin-top: 5px;" data-bind="visible: !isNew(), text: email"></strong> <strong style="margin-top: 5px;" data-bind="visible: !isNew(), text: email"></strong>
<input type="email" class="input-xlarge" <input type="email" class="input-xlarge"
autofocus="" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="visible: isNew, textInput: email, onEnter: addAccountCommand"> data-bind="visible: isNew, textInput: email">
</div> </div>
<div class="control-group" data-bind="css: {'error': passwordError}"> <div class="control-group" data-bind="css: {'error': passwordError}">
<label data-i18n="GLOBAL/PASSWORD"></label> <label data-i18n="GLOBAL/PASSWORD"></label>
<input type="password" class="input-xlarge" autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" <input type="password" class="input-xlarge" autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: password, onEnter: addAccountCommand"> required="" data-bind="value: password">
</div> </div>
</form> </form>
<footer> <footer>
<a class="btn buttonAddAccount" data-bind="command: addAccountCommand"> <button form="accountform" class="btn buttonAddAccount">
<i data-bind="visible: isNew, css: {'icon-user-add': !submitRequest(), 'icon-spinner': submitRequest()}"></i> <i data-bind="visible: isNew, css: {'icon-user-add': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
<span data-bind="visible: isNew" data-i18n="POPUPS_ADD_ACCOUNT/BUTTON_ADD_ACCOUNT"></span> <span data-bind="visible: isNew" data-i18n="POPUPS_ADD_ACCOUNT/BUTTON_ADD_ACCOUNT"></span>
<i data-bind="visible: !isNew(), css: {'icon-ok': !submitRequest(), 'icon-spinner': submitRequest()}"></i> <i data-bind="visible: !isNew(), css: {'icon-ok': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
<span data-bind="visible: !isNew()" data-i18n="POPUPS_ADD_ACCOUNT/BUTTON_UPDATE_ACCOUNT"></span> <span data-bind="visible: !isNew()" data-i18n="POPUPS_ADD_ACCOUNT/BUTTON_UPDATE_ACCOUNT"></span>
</a> </button>
</footer> </footer>

View file

@ -2,8 +2,7 @@
<a href="#" class="close" data-bind="command: closeCommand">×</a> <a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="SEARCH/TITLE_ADV"></h3> <h3 data-i18n="SEARCH/TITLE_ADV"></h3>
</header> </header>
<div class="modal-body"> <form id="modal-body searchform" class="form-horizontal" action="#/" autocomplete="off" data-bind="submit: submitForm">
<form id="searchform" class="form-horizontal" action="#/" autocomplete="off" data-bind="submit: submitForm">
<div class="row"> <div class="row">
<div class="span4"> <div class="span4">
<div class="control-group"> <div class="control-group">
@ -82,8 +81,7 @@
</div> </div>
</div> </div>
</div> </div>
</form> </form>
</div>
<footer> <footer>
<button type="submit" form="searchform" class="btn buttonAdvSearch" data-icon="🔎" data-i18n="GLOBAL/SEARCH"></button> <button form="searchform" class="btn buttonAdvSearch" data-icon="🔎" data-i18n="GLOBAL/SEARCH"></button>
</footer> </footer>

View file

@ -2,8 +2,7 @@
<a href="#" class="close" data-bind="command: closeCommand">×</a> <a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_CREATE_FOLDER/TITLE_CREATE_FOLDER"></h3> <h3 data-i18n="POPUPS_CREATE_FOLDER/TITLE_CREATE_FOLDER"></h3>
</header> </header>
<div class="modal-body"> <form id="createfolderform" class="modal-body form-horizontal" autocomplete="off" data-bind="submit: submitForm">
<div class="form-horizontal">
<div class="control-group"> <div class="control-group">
<label data-i18n="POPUPS_CREATE_FOLDER/LABEL_PARENT"></label> <label data-i18n="POPUPS_CREATE_FOLDER/LABEL_PARENT"></label>
<select data-bind="options: parentFolderSelectList, value: selectedParentValue, <select data-bind="options: parentFolderSelectList, value: selectedParentValue,
@ -13,7 +12,7 @@
<label data-i18n="GLOBAL/NAME"></label> <label data-i18n="GLOBAL/NAME"></label>
<input type="text" <input type="text"
autofocus="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="textInput: folderName, onEnter: createFolderCommand"> required="" pattern="^[^\\/]+$" data-bind="textInput: folderName">
</div> </div>
<div class="control-group" data-bind="component: { <div class="control-group" data-bind="component: {
name: 'Checkbox', name: 'Checkbox',
@ -22,11 +21,10 @@
value: folderSubscribe value: folderSubscribe
} }
}"></div> }"></div>
</div> </form>
</div>
<footer> <footer>
<a class="btn buttonCreate" data-bind="command: createFolderCommand"> <button form="createfolderform" class="btn buttonCreate">
<i class="icon-folder-add"></i> <i class="icon-folder-add"></i>
<span data-i18n="POPUPS_CREATE_FOLDER/BUTTON_CREATE"></span> <span data-i18n="POPUPS_CREATE_FOLDER/BUTTON_CREATE"></span>
</a> </button>
</footer> </footer>

View file

@ -5,7 +5,7 @@
<span data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></span> <span data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></span>
</h3> </h3>
</header> </header>
<div class="modal-body"> <form id="identityform" class="modal-body" autocomplete="off" data-bind="submit: submitForm">
<div class="form-horizontal g-ui-user-select-none"> <div class="form-horizontal g-ui-user-select-none">
<div class="alert" data-bind="visible: '' !== submitError()"> <div class="alert" data-bind="visible: '' !== submitError()">
<a href="#" class="close" data-bind="click: function () { submitError('') }">×</a> <a href="#" class="close" data-bind="click: function () { submitError('') }">×</a>
@ -17,26 +17,26 @@
<div class="textEmail" data-bind="text: email, visible: owner"></div> <div class="textEmail" data-bind="text: email, visible: owner"></div>
<input type="email" class="input-xlarge" autofocus="" <input type="email" class="input-xlarge" autofocus=""
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="visible: !owner(), value: email, onEnter: addOrEditIdentityCommand, hasfocus: emailFocused"> data-bind="visible: !owner(), value: email, hasfocus: emailFocused">
</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 type="text" class="input-xlarge" <input type="text" class="input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: name, onEnter: addOrEditIdentityCommand"> data-bind="value: name">
</div> </div>
<div class="control-group" data-bind="visible: showReplyTo, css: {'error': replyToHasError}"> <div class="control-group" data-bind="visible: showReplyTo, css: {'error': replyToHasError}">
<label data-i18n="GLOBAL/REPLY_TO"></label> <label data-i18n="GLOBAL/REPLY_TO"></label>
<input type="text" class="inputReplyTo input-xlarge" <input type="text" class="inputReplyTo input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: replyTo, onEnter: addOrEditIdentityCommand, hasfocus: replyToFocused"> data-bind="value: replyTo, hasfocus: replyToFocused">
</div> </div>
<div class="control-group" data-bind="visible: showBcc, css: {'error': bccHasError}"> <div class="control-group" data-bind="visible: showBcc, css: {'error': bccHasError}">
<label data-i18n="GLOBAL/BCC"></label> <label data-i18n="GLOBAL/BCC"></label>
<input type="text" class="inputBcc input-xlarge" <input type="text" class="inputBcc input-xlarge"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: bcc, onEnter: addOrEditIdentityCommand, hasfocus: bccFocused"> data-bind="value: bcc, hasfocus: bccFocused">
</div> </div>
<div class="control-group" data-bind="visible: !showReplyTo() || !showBcc()"> <div class="control-group" data-bind="visible: !showReplyTo() || !showBcc()">
<div> <div>
@ -63,12 +63,12 @@
}"></div> }"></div>
</div> </div>
<div class="e-signature-place" data-bind="editor: signature"></div> <div class="e-signature-place" data-bind="editor: signature"></div>
</div> </form>
<footer> <footer>
<a class="btn buttonAddIdentity" data-bind="command: addOrEditIdentityCommand"> <button form="identityform" class="btn buttonAddIdentity">
<i data-bind="visible: !edit(), css: {'icon-user-add': !submitRequest(), 'icon-spinner': submitRequest()}"></i> <i data-bind="visible: !edit(), css: {'icon-user-add': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
<span data-bind="visible: !edit()" data-i18n="POPUPS_IDENTITY/BUTTON_ADD_IDENTITY"></span> <span data-bind="visible: !edit()" data-i18n="POPUPS_IDENTITY/BUTTON_ADD_IDENTITY"></span>
<i data-bind="visible: edit, css: {'icon-ok': !submitRequest(), 'icon-spinner': submitRequest()}"></i> <i data-bind="visible: edit, css: {'icon-ok': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
<span data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/BUTTON_UPDATE_IDENTITY"></span> <span data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/BUTTON_UPDATE_IDENTITY"></span>
</a> </button>
</footer> </footer>