Centralize tryToClose() for all popups

This commit is contained in:
the-djmaze 2024-08-06 21:41:52 +02:00
parent fa15742edb
commit c33dd8f856
5 changed files with 8 additions and 13 deletions

View file

@ -60,10 +60,9 @@ export class AbstractViewPopup extends AbstractView
this.keyScope.scope = name;
this.modalVisible = ko.observable(false).extend({ rateLimit: 0 });
this.close = () => this.modalVisible(false);
this.tryToClose = () => (false === this.onClose()) || this.close();
addShortcut('escape,close', '', name, () => {
if (this.modalVisible() && false !== this.onClose()) {
this.close();
}
this.modalVisible() && this.tryToClose();
return false;
// return true; Issue with supported modal close
});

View file

@ -167,7 +167,7 @@ const
if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) {
// Close all popups
for (let vm of visiblePopups) {
(false === vm.onClose()) || vm.close();
vm.tryToClose();
}
let vmScreen = screen(screenName);

View file

@ -298,7 +298,7 @@ export class ComposePopupView extends AbstractViewPopup {
]
});
this.tryToClose = this.tryToClose.debounce(200);
this.doClose = this.doClose.debounce(200);
this.iTimer = 0;
@ -665,7 +665,7 @@ export class ComposePopupView extends AbstractViewPopup {
this.saveCommand();
}
this.tryToClose();
this.doClose();
}
contactsCommand() {
@ -1072,7 +1072,7 @@ export class ComposePopupView extends AbstractViewPopup {
}, 100);
}
tryToClose() {
doClose() {
if (AskPopupView.hidden()) {
if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) {
this.close();
@ -1218,7 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup {
});
addShortcut('escape,close', 'shift', ScopeCompose, () => {
this.tryToClose();
this.doClose();
return false;
});

View file

@ -314,10 +314,6 @@ export class ContactsPopupView extends AbstractViewPopup {
}
}
tryToClose() {
(false === this.onClose()) || this.close();
}
onClose() {
const contact = this.contact();
if (AskPopupView.hidden() && contact?.hasChanges()) {

View file

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