Skip to content
Snippets Groups Projects
Commit 9dd7c016 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Elmar Ludwig
Browse files

add before unload handler to avoid data loss in wiki, fixes #4522

Closes #4522

Merge request studip/studip!3332
parent ac9ef82d
No related branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,10 @@ const Wiki = { ...@@ -76,6 +76,10 @@ const Wiki = {
this.$nextTick(() => { this.$nextTick(() => {
this.editor.editing.view.focus(); this.editor.editing.view.focus();
}); });
},
securityHandler(event) {
event.preventDefault();
event.returnValue = true;
} }
}, },
mounted() { mounted() {
...@@ -86,7 +90,7 @@ const Wiki = { ...@@ -86,7 +90,7 @@ const Wiki = {
editor.editing.view.focus(); editor.editing.view.focus();
} }
editor.model.document.on('change:data',() => { editor.model.document.on('change:data',() => {
this.isChanged = true; this.isChanged = editor.getData() !== this.content;
this.lastChangeDate = new Date(); this.lastChangeDate = new Date();
}); });
this.editor = editor; this.editor = editor;
...@@ -99,6 +103,15 @@ const Wiki = { ...@@ -99,6 +103,15 @@ const Wiki = {
.sort((a, b) => a.fullname.localeCompare(b.fullname)); .sort((a, b) => a.fullname.localeCompare(b.fullname));
} }
}, },
watch: {
isChanged(current) {
if (current) {
window.addEventListener('beforeunload', this.securityHandler);
} else {
window.removeEventListener('beforeunload', this.securityHandler);
}
}
},
components: { WikiEditorOnlineUsers } components: { WikiEditorOnlineUsers }
}); });
}).then((app) => { }).then((app) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment