From 6313d1ac7ad33fe5f383ca501bdf3232acc46a82 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 25 Jul 2024 15:20:19 -0600 Subject: [PATCH] Add dirty warning for mobile --- api/lang/egw_en.lang | 1 + pixelegg/js/fw_mobile.js | 41 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/api/lang/egw_en.lang b/api/lang/egw_en.lang index 86c9c7ea25..72abca7288 100644 --- a/api/lang/egw_en.lang +++ b/api/lang/egw_en.lang @@ -258,6 +258,7 @@ chad common en CHAD change common en Change change owner common en Change Owner changed common en Changed +changes that you made may not be saved. common en Changes that you made may not be saved. charset common en Charset check all common en Check all check for empty values in if statements. example {{if url~empty~~website:}} - if url is not empty, writes "website:" common en Check for empty values in IF statements. Example {{IF url~EMPTY~~Website:}} - If url is not empty, writes "Website:" diff --git a/pixelegg/js/fw_mobile.js b/pixelegg/js/fw_mobile.js index 70e770af24..5f79713bd7 100644 --- a/pixelegg/js/fw_mobile.js +++ b/pixelegg/js/fw_mobile.js @@ -277,11 +277,44 @@ import {tapAndSwipe} from "../../api/js/tapandswipe"; * @param {type} _idx remove the given popup index from the popups array * @returns {undefined} */ - close: function (_idx) + close: async function (_idx) { - this.$container.detach(); - //Remove the closed popup from popups array - window.framework.popups.splice(_idx,1); + let stop = false; + // Trigger template beforeunload since iframe doesn't, and ask directly + this.$iFrame.get(0).contentDocument.body.querySelectorAll(".et2_container").forEach(t => + { + const template = this.$iFrame.get(0).contentWindow.etemplate2.getById(t.id); + if (template && template.close_prompt) + { + let e = new Event("beforeunload", {bubbles: true, cancelable: true}); + template.DOMContainer.dispatchEvent(e); + stop = stop || e.defaultPrevented; + } + }); + if (stop) + { + // Dirty dialog, ask to close + const dialog = Et2Dialog.show_dialog( + null, + egw.lang("Changes that you made may not be saved."), + egw.lang("Discard changes"), + {}, Et2Dialog.BUTTONS_OK_CANCEL, Et2Dialog.WARNING_MESSAGE + ); + // Set dialog z-index since framework uses 999 instead of variable + dialog.style.setProperty('--sl-z-index-dialog', parseInt(getComputedStyle(this.$container.get(0)).zIndex) + 1); + + stop = await dialog.getComplete().then(([button, value]) => + { + return button != Et2Dialog.OK_BUTTON; + }) + } + + if (!stop) + { + this.$container.detach(); + //Remove the closed popup from popups array + window.framework.popups.splice(_idx, 1); + } }, /**