diff --git a/assets/js/components/ChargingPlan.vue b/assets/js/components/ChargingPlan.vue index 056258b11..af38363db 100644 --- a/assets/js/components/ChargingPlan.vue +++ b/assets/js/components/ChargingPlan.vue @@ -224,12 +224,22 @@ export default { this.modal = Modal.getOrCreateInstance(this.$refs.modal); this.$refs.modal.addEventListener("show.bs.modal", this.modalVisible); this.$refs.modal.addEventListener("hidden.bs.modal", this.modalInvisible); + this.$refs.modal.addEventListener("hide.bs.modal", this.checkUnsavedOnClose); }, unmounted() { this.$refs.modal?.removeEventListener("show.bs.modal", this.modalVisible); this.$refs.modal?.removeEventListener("hidden.bs.modal", this.modalInvisible); + this.$refs.modal?.removeEventListener("hide.bs.modal", this.checkUnsavedOnClose); }, methods: { + checkUnsavedOnClose: function () { + const $applyButton = this.$refs.modal.querySelector("[data-testid=plan-apply]"); + if ($applyButton) { + if (confirm(this.$t("main.chargingPlan.unsavedChanges"))) { + $applyButton.click(); + } + } + }, modalVisible: function () { this.isModalVisible = true; }, diff --git a/i18n/de.toml b/i18n/de.toml index 30abb1024..ae4681376 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -208,6 +208,7 @@ time = "Zeit" title = "Plan" titleMinSoc = "Min. Ladung" titleTargetCharge = "Abfahrt" +unsavedChanges = "Ungespeicherte Änderungen vorhanden. Jetzt anwenden?" update = "Anwenden" [main.energyflow] diff --git a/i18n/en.toml b/i18n/en.toml index da8463672..64126f8c2 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -205,6 +205,7 @@ time = "Time" title = "Plan" titleMinSoc = "Min charge" titleTargetCharge = "Departure" +unsavedChanges = "There are unsaved changes. Apply now?" update = "Apply" [main.energyflow]