Drop cancelCommand in favor of closeCommand and improve AbstractViewPopup handling

This commit is contained in:
the-djmaze 2022-02-24 22:40:17 +01:00
parent 06b5b83588
commit 2edd55f01f
36 changed files with 82 additions and 118 deletions

View file

@ -3,9 +3,7 @@ import 'External/User/ko';
import { isArray, pString } from 'Common/Utils';
import { mailToHelper, setLayoutResizer } from 'Common/UtilsUser';
import {
Scope
} from 'Common/Enums';
import { Scope } from 'Common/Enums';
import {
FolderType,

View file

@ -57,36 +57,30 @@ export class AbstractViewPopup extends AbstractView
constructor(name)
{
super('Popups' + name, ViewType.Popup);
if (name in Scope) {
this.keyScope.scope = Scope[name];
}
this.bDisabeCloseOnEsc = false;
this.keyScope.scope = name;
this.modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
}
/*
onShowWithDelay() {}
onHideWithDelay() {}
cancelCommand() {}
closeCommand() {}
*/
/**
* @returns {void}
*/
registerPopupKeyDown() {
addEventListener('keydown', event => {
if (event && this.modalVisibility()) {
if (!this.bDisabeCloseOnEsc && 'Escape' == event.key) {
this.cancelCommand();
return false;
} else if ('Backspace' == event.key && !inFocus()) {
return false;
}
this.onClose = this.onClose.debounce(200);
shortcuts.add('escape,close', '', name, () => {
if (this.modalVisibility() && this.onClose()) {
this.closeCommand();
return false;
}
return true;
});
shortcuts.add('backspace', '', name, inFocus());
}
onClose() {
return true;
}
/*
afterShow() {}
afterHide() {}
closeCommand() {}
*/
}
AbstractViewPopup.showModal = function(params = []) {

View file

@ -48,7 +48,7 @@ const
ViewModelClass.__dom = vmDom;
if (ViewType.Popup === position) {
vm.cancelCommand = vm.closeCommand = createCommand(() => hideScreenPopup(ViewModelClass));
vm.closeCommand = createCommand(() => hideScreenPopup(ViewModelClass));
// Firefox / Safari HTMLDialogElement not defined
if (!vmDom.showModal) {
@ -75,10 +75,10 @@ const
if (e.target === vmDom) {
if (vmDom.classList.contains('animate')) {
autofocus(vmDom);
vm.onShowWithDelay && vm.onShowWithDelay();
vm.afterShow && vm.afterShow();
} else {
vmDom.close();
vm.onHideWithDelay && vm.onHideWithDelay();
vm.afterHide && vm.afterHide();
}
}
};
@ -115,12 +115,7 @@ const
}
*/
});
if ('ontransitionend' in vmDom) {
vmDom.addEventListener('transitionend', endShowHide);
} else {
// For Edge < 79 and mobile browsers
vm.modalVisibility.subscribe(() => ()=>setTimeout(endShowHide({target:vmDom}), 500));
}
vmDom.addEventListener('transitionend', endShowHide);
}
ko.applyBindingAccessorsToNode(
@ -133,9 +128,6 @@ const
);
vm.onBuild && vm.onBuild(vmDom);
if (vm && ViewType.Popup === position) {
vm.registerPopupKeyDown();
}
fireEvent('rl-view-model', vm);
} else {

View file

@ -49,7 +49,7 @@ export class AccountPopupView extends AbstractViewPopup {
this.submitErrorAdditional((data && data.ErrorMessageAdditional) || '');
} else {
rl.app.accountsAndIdentities();
this.cancelCommand();
this.closeCommand();
}
}, {
Email: this.email(),

View file

@ -57,7 +57,7 @@ export class AdvancedSearchPopupView extends AbstractViewPopup {
MessagelistUserStore.mainSearch(search);
}
this.cancelCommand();
this.closeCommand();
}
parseSearchStringValue(search) {

View file

@ -19,17 +19,16 @@ export class AskPopupView extends AbstractViewPopup {
this.fNoAction = null;
this.focusOnShow = true;
this.bDisabeCloseOnEsc = true;
}
yesClick() {
this.cancelCommand();
this.closeCommand();
isFunction(this.fYesAction) && this.fYesAction();
}
noClick() {
this.cancelCommand();
this.closeCommand();
isFunction(this.fNoAction) && this.fNoAction();
}
@ -52,10 +51,15 @@ export class AskPopupView extends AbstractViewPopup {
this.focusOnShow = focusOnShow ? (askPass ? 'input[type="password"]' : '.buttonYes') : '';
}
onShowWithDelay() {
afterShow() {
this.focusOnShow && this.querySelector(this.focusOnShow).focus();
}
onClose() {
this.noClick();
return false;
}
onBuild() {
// shortcuts.add('tab', 'shift', 'Ask', () => {
shortcuts.add('tab,arrowright,arrowleft', '', 'Ask', () => {
@ -66,11 +70,6 @@ export class AskPopupView extends AbstractViewPopup {
btn.focus();
return false;
});
shortcuts.add('escape', '', 'Ask', () => {
this.noClick();
return false;
});
}
}

View file

@ -259,8 +259,6 @@ export class ComposePopupView extends AbstractViewPopup {
]
});
this.bDisabeCloseOnEsc = true;
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
this.iTimer = 0;
@ -643,6 +641,11 @@ export class ComposePopupView extends AbstractViewPopup {
}
}
onClose() {
this.skipCommand();
return false;
}
skipCommand() {
this.bSkipNextHide = true;
@ -1330,10 +1333,6 @@ export class ComposePopupView extends AbstractViewPopup {
shortcuts.add('contextmenu', '', ScopeCompose, e => this.popupMenu(e));
shortcuts.add('m', 'meta', ScopeCompose, e => this.popupMenu(e));
shortcuts.add('escape,close', '', ScopeCompose, () => {
this.skipCommand();
return false;
});
shortcuts.add('arrowdown', 'meta', ScopeCompose, () => {
this.skipCommand();
return false;
@ -1360,7 +1359,7 @@ export class ComposePopupView extends AbstractViewPopup {
});
shortcuts.add('escape,close', 'shift', ScopeCompose, () => {
this.modalVisibility() && this.tryToClosePopup();
this.tryToClosePopup();
return false;
});

View file

@ -157,7 +157,7 @@ export class FilterPopupView extends AbstractViewPopup {
}
}
onShowWithDelay() {
afterShow() {
this.isNew() && this.filter() && this.filter().nameFocused(true);
}
}

View file

@ -54,7 +54,7 @@ export class FolderClearPopupView extends AbstractViewPopup {
this.clearingError(getNotification(iError));
} else {
MessagelistUserStore.reload(true);
this.cancelCommand();
this.closeCommand();
}
}, {
Folder: folderToClear.fullName

View file

@ -79,7 +79,7 @@ export class FolderCreatePopupView extends AbstractViewPopup {
}
);
this.cancelCommand();
this.closeCommand();
}
simpleFolderNameValidation(sName) {

View file

@ -100,7 +100,7 @@ export class IdentityPopupView extends AbstractViewPopup {
this.submitError(getNotification(iError));
} else {
rl.app.accountsAndIdentities();
this.cancelCommand();
this.closeCommand();
}
}, {
Id: this.id,
@ -162,11 +162,11 @@ export class IdentityPopupView extends AbstractViewPopup {
}
}
onShowWithDelay() {
afterShow() {
this.owner() || this.emailFocused(true);
}
onHideWithDelay() {
afterHide() {
this.clearPopup();
}
}

View file

@ -52,6 +52,6 @@ export class LanguagesPopupView extends AbstractViewPopup {
changeLanguage(lang) {
this.fLang && this.fLang(lang);
this.cancelCommand();
this.closeCommand();
}
}

View file

@ -70,7 +70,7 @@ export class OpenPgpGeneratePopupView extends AbstractViewPopup {
if (keyPair) {
const fn = () => {
this.submitRequest(false);
this.cancelCommand();
this.closeCommand();
};
OpenPGPUserStore.storeKeyPair(keyPair);

View file

@ -63,7 +63,7 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
return;
}
this.cancelCommand();
this.closeCommand();
}
onShow() {

View file

@ -28,11 +28,8 @@ export class PluginPopupView extends AbstractViewPopup {
hasConfiguration: () => 0 < this.config().length
});
this.bDisabeCloseOnEsc = true;
this.keyScope.scope = Scope.All;
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
decorateKoCommands(this, {
saveCommand: self => self.hasConfiguration()
});
@ -64,7 +61,7 @@ export class PluginPopupView extends AbstractViewPopup {
Remote.request('AdminPluginSettingsUpdate',
iError => iError
? this.saveError(getNotification(iError))
: this.cancelCommand(),
: this.closeCommand(),
oConfig);
}
@ -98,21 +95,13 @@ export class PluginPopupView extends AbstractViewPopup {
}
}
tryToClosePopup() {
onClose() {
if (AskPopupView.hidden()) {
showScreenPopup(AskPopupView, [
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
() => this.modalVisibility() && this.cancelCommand()
() => this.closeCommand()
]);
}
}
onBuild() {
shortcuts.add('escape', '', Scope.All, () => {
if (this.modalVisibility()) {
this.tryToClosePopup();
return false;
}
});
return false;
}
}

View file

@ -129,7 +129,7 @@ export class SieveScriptPopupView extends AbstractViewPopup {
this.saveError(false);
}
onShowWithDelay() {
afterShow() {
// Sometimes not everything is translated, try again
i18nToNodes(this.viewModelDom);
}

View file

@ -1,15 +1,8 @@
import ko from 'ko';
import {
Capa,
Scope
} from 'Common/Enums';
import { Capa, Scope } from 'Common/Enums';
import {
ComposeType,
FolderType,
MessageSetAction
} from 'Common/EnumsUser';
import { ComposeType, FolderType, MessageSetAction } from 'Common/EnumsUser';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';

View file

@ -1,5 +1,5 @@
<header>
<a class="close" href="#" data-bind="command: cancelCommand">×</a>
<a class="close" href="#" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_TWO_FACTOR_TEST/TITLE_TEST_CODE"></h3>
</header>
<div class="modal-body form-horizontal">

View file

@ -82,7 +82,7 @@
<span data-i18n="POPUPS_TWO_FACTOR_CFG/BUTTON_ACTIVATE"></span>
</a>
<!--
<a class="btn" data-bind="command: cancelCommand, visible: viewEnable() || !lock()">
<a class="btn" data-bind="command: closeCommand, visible: viewEnable() || !lock()">
<i class="icon-ok" ></i>
<span data-i18n="GLOBAL/DONE"></span>
</a>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-bind="text: headerText"></h3>
</header>
<div class="modal-body">
@ -189,7 +189,7 @@
<i class="fontastic" data-bind="css: {'icon-spinner': testing()}"></i>
<span data-i18n="POPUPS_DOMAIN/BUTTON_TEST"></span>
</a>
<a class="btn buttonClose" data-bind="command: cancelCommand" data-icon="✖" data-i18n="POPUPS_DOMAIN/BUTTON_CLOSE"></a>
<a class="btn buttonClose" data-bind="command: closeCommand" data-icon="✖" data-i18n="POPUPS_DOMAIN/BUTTON_CLOSE"></a>
<a class="btn" data-bind="command: createOrAddCommand, visible: edit()">
<i class="fontastic" data-bind="css: {'icon-spinner': saving()}"></i>
<span data-i18n="POPUPS_DOMAIN/BUTTON_UPDATE"></span>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_DOMAIN_ALIAS/TITLE_ADD_DOMAIN_ALIAS"></h3>
</header>
<div class="modal-body">
@ -31,7 +31,7 @@
</div>
</div>
<footer>
<a class="btn buttonClose" data-bind="command: cancelCommand" data-icon="✖" data-i18n="POPUPS_DOMAIN_ALIAS/BUTTON_CLOSE"></a>
<a class="btn buttonClose" data-bind="command: closeCommand" data-icon="✖" data-i18n="POPUPS_DOMAIN_ALIAS/BUTTON_CLOSE"></a>
<a class="btn" data-bind="command: createCommand">
<i class="fontastic" data-bind="visible: !saving()"></i>
<i class="icon-spinner" data-bind="visible: saving"></i>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h4>
<span data-i18n="POPUPS_PLUGIN/TITLE_PLUGIN"></span>
&nbsp;
@ -30,6 +30,6 @@
</form>
</div>
<footer>
<a class="btn buttonClose" data-bind="command: cancelCommand" data-icon="✖" data-i18n="POPUPS_PLUGIN/BUTTON_CLOSE"></a>
<a class="btn buttonClose" data-bind="command: closeCommand" data-icon="✖" data-i18n="POPUPS_PLUGIN/BUTTON_CLOSE"></a>
<a class="btn" data-bind="command: saveCommand, visible: hasConfiguration" data-icon="✔" data-i18n="GLOBAL/SAVE"></a>
</footer>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_LANGUAGES/TITLE_LANGUAGES"></h3>
</header>
<div class="modal-body" style="min-height: 150px;" data-bind="foreach: languages">

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3>
<span data-bind="visible: isNew" data-i18n="POPUPS_ADD_ACCOUNT/TITLE_ADD_ACCOUNT"></span>
<span data-bind="visible: !isNew()" data-i18n="POPUPS_ADD_ACCOUNT/TITLE_UPDATE_ACCOUNT"></span>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="SEARCH/TITLE_ADV"></h3>
</header>
<div class="modal-body">
@ -9,22 +9,22 @@
<div class="control-group">
<label data-i18n="GLOBAL/FROM"></label>
<input type="text" autofocus="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: from, onEsc: cancelCommand">
data-bind="value: from, onEsc: closeCommand">
</div>
<div class="control-group">
<label data-i18n="GLOBAL/TO"></label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: to, onEsc: cancelCommand">
data-bind="value: to, onEsc: closeCommand">
</div>
<div class="control-group">
<label data-i18n="GLOBAL/SUBJECT"></label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: subject, onEsc: cancelCommand">
data-bind="value: subject, onEsc: closeCommand">
</div>
<div class="control-group">
<label data-i18n="SEARCH/LABEL_ADV_TEXT"></label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: text, onEsc: cancelCommand">
data-bind="value: text, onEsc: closeCommand">
</div>
</div>
<div class="span4">

View file

@ -1,6 +1,6 @@
<header class="b-header-toolbar g-ui-user-select-none">
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<div class="btn-toolbar">

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3>
<span data-i18n="POPUPS_FILTER/TITLE_CREATE_FILTER" data-bind="visible: isNew"></span>
<span data-i18n="POPUPS_FILTER/TITLE_EDIT_FILTER" data-bind="visible: !isNew()"></span>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3>
<span data-i18n="POPUPS_CLEAR_FOLDER/TITLE_CLEAR_FOLDER" data-bind="visible: !clearingProcess()"></span>
<span data-i18n="POPUPS_CLEAR_FOLDER/TITLE_CLEARING_PROCESS" data-bind="visible: clearingProcess"></span>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_CREATE_FOLDER/TITLE_CREATE_FOLDER"></h3>
</header>
<div class="modal-body">

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="POPUPS_SYSTEM_FOLDERS/TITLE_SYSTEM_FOLDERS"></h3>
</header>
<div class="modal-body">

View file

@ -1,5 +1,5 @@
<header class="g-ui-user-select-none">
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3>
<span data-bind="visible: !edit()" data-i18n="POPUPS_IDENTITY/TITLE_ADD_IDENTITY"></span>
<span data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></span>

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="SHORTCUTS_HELP/LEGEND_SHORTCUTS_HELP"></h3>
</header>
<div class="modal-body">

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="OPENPGP/POPUP_GENERATE_TITLE"></h3>
</header>
<form id="openpgp-generate" class="modal-body form-horizontal" autocomplete="off" data-bind="submit: submitForm">

View file

@ -1,5 +1,5 @@
<header>
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="OPENPGP/POPUP_IMPORT_TITLE"></h3>
</header>
<form id="openpgp-import" class="modal-body form-horizontal" autocomplete="off" data-bind="submit: submitForm">

View file

@ -1,5 +1,5 @@
<header class="g-ui-user-select-none">
<a href="#" class="close" data-bind="command: cancelCommand">×</a>
<a href="#" class="close" data-bind="command: closeCommand">×</a>
<h3 data-i18n="OPENPGP/POPUP_VIEW_TITLE"></h3>
</header>
<div class="modal-body">
@ -10,6 +10,6 @@
</div>
</div>
<footer>
<a class="btn buttonClose" data-bind="command: cancelCommand" data-icon="✖" data-i18n="GLOBAL/CLOSE"></a>
<a class="btn buttonClose" data-bind="command: closeCommand" data-icon="✖" data-i18n="GLOBAL/CLOSE"></a>
<a class="btn buttonClose" data-bind="click: selectKey" data-icon="🔑" data-i18n="OPENPGP/POPUP_VIEW_BUTTON"></a>
</footer>

View file

@ -1,6 +1,6 @@
<!-- ko with: script -->
<header>
<a href="#" class="close" data-bind="command: $root.cancelCommand">×</a>
<a href="#" class="close" data-bind="command: $root.closeCommand">×</a>
<h3>
<span data-i18n="POPUPS_SIEVE_SCRIPT/TITLE_CREATE" data-bind="visible: !exists()"></span>
<span data-i18n="POPUPS_SIEVE_SCRIPT/TITLE_EDIT" data-bind="visible: exists"></span>