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.keyScope.scope = name;
this.modalVisible = ko.observable(false).extend({ rateLimit: 0 }); this.modalVisible = ko.observable(false).extend({ rateLimit: 0 });
this.close = () => this.modalVisible(false); this.close = () => this.modalVisible(false);
this.tryToClose = () => (false === this.onClose()) || this.close();
addShortcut('escape,close', '', name, () => { addShortcut('escape,close', '', name, () => {
if (this.modalVisible() && false !== this.onClose()) { this.modalVisible() && this.tryToClose();
this.close();
}
return false; return false;
// return true; Issue with supported modal close // return true; Issue with supported modal close
}); });

View file

@ -167,7 +167,7 @@ const
if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) { if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) {
// Close all popups // Close all popups
for (let vm of visiblePopups) { for (let vm of visiblePopups) {
(false === vm.onClose()) || vm.close(); vm.tryToClose();
} }
let vmScreen = screen(screenName); 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; this.iTimer = 0;
@ -665,7 +665,7 @@ export class ComposePopupView extends AbstractViewPopup {
this.saveCommand(); this.saveCommand();
} }
this.tryToClose(); this.doClose();
} }
contactsCommand() { contactsCommand() {
@ -1072,7 +1072,7 @@ export class ComposePopupView extends AbstractViewPopup {
}, 100); }, 100);
} }
tryToClose() { doClose() {
if (AskPopupView.hidden()) { if (AskPopupView.hidden()) {
if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) { if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) {
this.close(); this.close();
@ -1218,7 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup {
}); });
addShortcut('escape,close', 'shift', ScopeCompose, () => { addShortcut('escape,close', 'shift', ScopeCompose, () => {
this.tryToClose(); this.doClose();
return false; return false;
}); });

View file

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

View file

@ -1,5 +1,5 @@
<header class="g-ui-user-select-none"> <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_ADD_IDENTITY"></h3>
<h3 data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></h3> <h3 data-bind="visible: edit" data-i18n="POPUPS_IDENTITY/TITLE_UPDATE_IDENTITY"></h3>
</header> </header>