diff --git a/resources/assets/javascripts/bootstrap/beforeunload-event-listener.js b/resources/assets/javascripts/bootstrap/beforeunload-event-listener.js deleted file mode 100644 index 4e966308cd0de441e06eca65ff1d9593debca1a5..0000000000000000000000000000000000000000 --- a/resources/assets/javascripts/bootstrap/beforeunload-event-listener.js +++ /dev/null @@ -1,6 +0,0 @@ -STUDIP.domReady(() => { - // Before-unload event listener. - window.addEventListener('beforeunload', (e) => { - STUDIP.eventBus.emit('studip:beforeunload', e); - }, {capture: true}); -}); diff --git a/resources/assets/javascripts/entry-base.js b/resources/assets/javascripts/entry-base.js index b577ce49a2f31f57c6262a2eb2172c29df4f0cdb..9464a9cc4efa40bf70431e71dd9bc561d94de73f 100644 --- a/resources/assets/javascripts/entry-base.js +++ b/resources/assets/javascripts/entry-base.js @@ -86,7 +86,6 @@ import "./bootstrap/admin-courses.js" import "./bootstrap/cache-admin.js" import "./bootstrap/oer.js" import "./bootstrap/courseware.js" -import "./bootstrap/beforeunload-event-listener.js" import "./bootstrap/responsive-navigation.js" import "./mvv_course_wizard.js" diff --git a/resources/vue/components/courseware/CoursewareAccordionContainer.vue b/resources/vue/components/courseware/CoursewareAccordionContainer.vue index 92029c69b899ed0b26201b225b8c6e2b956b5770..8e4d0984d1aab3ccb4ff8ec19a30fd83c6bc7b90 100644 --- a/resources/vue/components/courseware/CoursewareAccordionContainer.vue +++ b/resources/vue/components/courseware/CoursewareAccordionContainer.vue @@ -8,7 +8,6 @@ @storeContainer="storeContainer" @closeEdit="initCurrentData" @sortBlocks="enableSort" - @setSortMode="setSortMode" > <template v-slot:containerContent> <courseware-collapsible-box @@ -245,9 +244,6 @@ export default { if (blockAdder.container !== undefined && blockAdder.container.id === this.container.id) { this.initCurrentData(); } - }, - setSortMode(mode) { - this.sortMode = mode; } }, watch: { diff --git a/resources/vue/components/courseware/CoursewareActionWidget.vue b/resources/vue/components/courseware/CoursewareActionWidget.vue index 89f27ea549e509cbc913c339c4682ca3e7a52d23..f4d690683aa4b0c1ea723a4af2dbc9f20a250306 100644 --- a/resources/vue/components/courseware/CoursewareActionWidget.vue +++ b/resources/vue/components/courseware/CoursewareActionWidget.vue @@ -74,12 +74,6 @@ export default { SidebarWidget, }, mixins: [CoursewareExport], - data() { - return { - objectIsBlocked: false, - blockedFrom: '' - } - }, computed: { ...mapGetters({ userId: 'userId', @@ -92,9 +86,6 @@ export default { blockerId: 'currentElementBlockerId', blockedByThisUser: 'currentElementBlockedByThisUser', blockedByAnotherUser: 'currentElementBlockedByAnotherUser', - editDialogState: 'showStructuralElementEditDialog', - deleteDialogState: 'showStructuralElementDeleteDialog', - structuralElementSortMode: 'structuralElementSortMode' }), isRoot() { if (!this.structuralElement) { @@ -135,7 +126,6 @@ export default { companionInfo: 'companionInfo', addBookmark: 'addBookmark', lockObject: 'lockObject', - unlockObject: 'unlockObject', setConsumeMode: 'coursewareConsumeMode', setViewMode: 'coursewareViewMode', setShowToolbar: 'coursewareShowToolbar', @@ -151,8 +141,6 @@ export default { } try { await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; - this.blockedFrom = 'editDialogState'; } catch(error) { if (error.status === 409) { this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); @@ -176,8 +164,6 @@ export default { } try { await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; - this.blockedFrom = 'structuralElementSortMode'; } catch (error) { if (error.status === 409) { this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); @@ -202,8 +188,6 @@ export default { return false; } await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; - this.blockedFrom = 'deleteDialogState'; this.showElementDeleteDialog(true); }, addElement() { @@ -229,60 +213,6 @@ export default { }, linkElement() { this.showElementLinkDialog(true); - }, - async beforeUnloadActions() { - this.beforeUnloadCleanup(); - if (this.objectIsBlocked) { - await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - } - }, - beforeUnloadCleanup() { - // The following dialogs and elements must be set to be closed, in order to avoid lockObject conflicts. - this.showElementEditDialog(false); - this.setStructuralElementSortMode(false); - this.showElementDeleteDialog(false); - }, - async beforeUnloadHandler(event) { - if (this.objectIsBlocked) { - event.preventDefault(); - event.returnValue = 'There are unsaved changes, do you want to leave?'; - await this.beforeUnloadActions(); - return event.returnValue; - } - return null; - } - }, - mounted () { - STUDIP.eventBus.on('studip:beforeunload', this.beforeUnloadHandler); - }, - beforeDestroy () { - STUDIP.eventBus.off('studip:beforeunload', this.beforeUnloadHandler); - }, - watch: { - blockedByThisUser(newValue) { - if (!newValue) { - this.objectIsBlocked = false - } - }, - editDialogState(newValue) { - if (!newValue && this.blockedFrom == 'editDialogState') { - this.objectIsBlocked = false - } - }, - structuralElementSortMode(newValue) { - if (!newValue && this.blockedFrom == 'structuralElementSortMode') { - this.objectIsBlocked = false - } - }, - deleteDialogState(newValue) { - if (!newValue && this.blockedFrom == 'deleteDialogState') { - this.objectIsBlocked = false - } - }, - objectIsBlocked(newValue) { - if (!newValue) { - this.blockedFrom = ''; - } } }, }; diff --git a/resources/vue/components/courseware/CoursewareBlockEdit.vue b/resources/vue/components/courseware/CoursewareBlockEdit.vue index f48a6b062805f3c1f7478c6f4604543cedd699ad..55b8b3a1b9b06a4557b5ff4d16681f973b556e1e 100644 --- a/resources/vue/components/courseware/CoursewareBlockEdit.vue +++ b/resources/vue/components/courseware/CoursewareBlockEdit.vue @@ -18,7 +18,6 @@ export default { name: 'courseware-block-edit', props: { block: Object, - objectIsBlocked: Boolean, }, data() { return { @@ -34,28 +33,12 @@ export default { this.$store.dispatch('coursewareBlockAdder', {}); this.$store.dispatch('coursewareShowToolbar', false); }, - beforeUnloadHandler(event) { - if (this.exitHandler || this.objectIsBlocked) { - event.preventDefault(); - this.autoSave(); - event.returnValue = 'There are unsaved changes, do you want to leave?'; - return event.returnValue; - } - return null; - }, - async autoSave() { - this.$emit('store'); - this.exitHandler = false; - } }, beforeDestroy() { if (this.exitHandler) { - this.autoSave(); + console.log('autosave'); + this.$emit('store'); } - STUDIP.eventBus.off('studip:beforeunload', this.beforeUnloadHandler); - }, - mounted () { - STUDIP.eventBus.on('studip:beforeunload', this.beforeUnloadHandler); - }, + } }; </script> diff --git a/resources/vue/components/courseware/CoursewareDefaultBlock.vue b/resources/vue/components/courseware/CoursewareDefaultBlock.vue index 6a9ad39f9ab73a4a5a8437f0f1268d1e2986d845..14ab304ec61394975a38038b5cceb7db59b517ba 100644 --- a/resources/vue/components/courseware/CoursewareDefaultBlock.vue +++ b/resources/vue/components/courseware/CoursewareDefaultBlock.vue @@ -36,7 +36,6 @@ <courseware-block-edit v-if="canEdit && showEdit" :block="block" - :objectIsBlocked="objectIsBlocked" @store="prepareStoreEdit" @close="closeEdit" > @@ -131,7 +130,6 @@ export default { textDeleteAlert: this.$gettext('Möchten Sie diesen Block wirklich löschen?'), textRemoveLockTitle: this.$gettext('Sperre aufheben'), textRemoveLockAlert: this.$gettext('Möchten Sie die Sperre dieses Blocks wirklich aufheben?'), - objectIsBlocked: false, }; }, computed: { @@ -219,7 +217,6 @@ export default { await this.loadBlock({ id: this.block.id, options: { include: 'edit-blocker' } }); if (!this.blocked) { await this.lockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = true; if (!this.preview) { this.showContent = false; } @@ -267,23 +264,15 @@ export default { } if (this.blockerId === null) { await this.lockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = true; this.$emit('storeEdit'); } - - // To make sure the object is not blocked. - if (this.objectIsBlocked || this.blockedByThisUser) { - await this.unlockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = false; - } }, async closeEdit() { await this.loadBlock({ id: this.block.id , options: { include: 'edit-blocker' } }); // has block editor lock changed? this.displayFeature(false); this.$emit('closeEdit'); - if (this.blockedByThisUser || this.blockedByThisUser) { + if (this.blockedByThisUser) { await this.unlockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = false; } this.loadBlock({ id: this.block.id , options: { include: 'edit-blocker' } }); // to update block editor lock }, @@ -291,7 +280,6 @@ export default { await this.loadBlock({ id: this.block.id, options: { include: 'edit-blocker' } }); if (!this.blocked) { await this.lockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = true; this.showDeleteDialog = true; } else { if (this.blockedByThisUser) { @@ -310,7 +298,6 @@ export default { await this.loadBlock({ id: this.block.id, options: { include: 'edit-blocker' } }); if (this.blockedByThisUser) { await this.unlockObject({ id: this.block.id, type: 'courseware-blocks' }); - this.objectIsBlocked = false; } this.showDeleteDialog = false; }, @@ -336,7 +323,6 @@ export default { // lock parent container await this.lockObject({ id: containerId, type: 'courseware-containers' }); - this.objectIsBlocked = true; // update container information for (let i = 0; i < sections.length; i++) { for (let j = 0; j < sections[i].blocks.length; j++) { @@ -351,7 +337,6 @@ export default { await this.updateContainer({ container, structuralElementId }); // unlock container await this.unlockObject({ id: containerId, type: 'courseware-containers' }); - this.objectIsBlocked = false; await this.loadContainer(containerId); this.deleteBlock({ blockId: this.block.id, @@ -363,21 +348,14 @@ export default { }, async executeRemoveLock() { await this.unlockObject({ id: this.block.id , type: 'courseware-blocks' }); - this.objectIsBlocked = false; await this.loadBlock({ id: this.block.id }); this.showRemoveLockDialog = false; - }, - async performUnloadObject() { - await this.unlockObject({ id: this.block.id , type: 'courseware-blocks' }); - this.objectIsBlocked = false; } }, watch: { showEdit(state) { - if (state) { - this.objectIsBlocked = true; - } + this.$emit('showEdit', state); } } }; diff --git a/resources/vue/components/courseware/CoursewareDefaultContainer.vue b/resources/vue/components/courseware/CoursewareDefaultContainer.vue index 38f6b09863cb93eb718535e41a0f1592833f55c0..70a6da708f0f66215174ea40408d847e2b221fe6 100644 --- a/resources/vue/components/courseware/CoursewareDefaultContainer.vue +++ b/resources/vue/components/courseware/CoursewareDefaultContainer.vue @@ -93,7 +93,6 @@ export default { textDeleteAlert: this.$gettext('Möchten Sie diesen Abschnitt wirklich löschen?'), textRemoveLockTitle: this.$gettext('Sperre aufheben'), textRemoveLockAlert: this.$gettext('Möchten Sie die Sperre dieses Abschnitts wirklich aufheben?'), - objectIsBlocked: false, }; }, computed: { @@ -148,7 +147,6 @@ export default { } await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = true; this.showEditDialog = true; }, async closeEdit() { @@ -157,7 +155,6 @@ export default { this.showEditDialog = false; if (this.blockedByThisUser) { await this.unlockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = false; } await this.loadContainer({ id: this.container.id, options: { include: 'edit-blocker' } }); }, @@ -177,7 +174,6 @@ export default { } if (this.blockerId === null) { await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = true; this.$emit('storeContainer'); } this.showEditDialog = false; @@ -186,7 +182,6 @@ export default { await this.loadContainer({ id: this.container.id, options: { include: 'edit-blocker' } }); if (!this.blocked) { await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = true; this.showDeleteDialog = true; } else { if (this.blockedByThisUser) { @@ -205,7 +200,6 @@ export default { await this.loadContainer({ id: this.container.id, options: { include: 'edit-blocker' } }); if (this.blockedByThisUser) { await this.unlockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = false; } this.showDeleteDialog = false; }, @@ -237,7 +231,6 @@ export default { return false; } await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); - this.objectIsBlocked = true; this.$emit('sortBlocks'); }, displayRemoveLockDialog() { @@ -245,37 +238,10 @@ export default { }, async executeRemoveLock() { await this.unlockObject({ id: this.container.id , type: 'courseware-containers' }); - this.objectIsBlocked = false; await this.loadContainer({ id: this.container.id }); this.showRemoveLockDialog = false; }, - async beforeUnloadActions() { - this.beforeUnloadCleanup(); - if (this.blockedByThisUser || this.objectIsBlocked) { - await this.unlockObject({ id: this.container.id , type: 'courseware-containers' }); - } - }, - beforeUnloadCleanup() { - // The following dialogs and elements must be set to be closed, in order to avoid lockObject conflicts. - this.showEditDialog = false; - this.showDeleteDialog = false; - this.$emit('setSortMode', false); - }, - async beforeUnloadHandler(event) { - if (this.blockedByThisUser || this.objectIsBlocked) { - event.preventDefault(); - event.returnValue = 'There are unsaved changes, do you want to leave?'; - await this.beforeUnloadActions(); - return event.returnValue; - } - return null; - } - }, - mounted () { - STUDIP.eventBus.on('studip:beforeunload', this.beforeUnloadHandler); - }, - beforeDestroy () { - STUDIP.eventBus.off('studip:beforeunload', this.beforeUnloadHandler); + }, watch: { diff --git a/resources/vue/components/courseware/CoursewareStructuralElement.vue b/resources/vue/components/courseware/CoursewareStructuralElement.vue index d029e65e5d3ccde6172ab0401ca71cdbb0156f9e..96b175d3d8cad0e3c66109da1390b7ccc66d92e8 100644 --- a/resources/vue/components/courseware/CoursewareStructuralElement.vue +++ b/resources/vue/components/courseware/CoursewareStructuralElement.vue @@ -732,7 +732,6 @@ export default { 'expire-date': '' }, deletingPreviewImage: false, - objectIsBlocked: false, }; }, @@ -1349,8 +1348,7 @@ export default { this.uploadFileError = ''; this.deletingPreviewImage = false; }, - async menuAction(action, type = 'open') { - this.lastAction = action; + async menuAction(action) { switch (action) { case 'removeLock': this.displayRemoveLockDialog(); @@ -1364,7 +1362,6 @@ export default { } try { await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; } catch(error) { if (error.status === 409) { this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); @@ -1396,7 +1393,6 @@ export default { return false; } await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; this.showElementDeleteDialog(true); break; case 'showInfo': @@ -1423,7 +1419,6 @@ export default { } try { await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; } catch (error) { if (error.status === 409) { this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); @@ -1444,7 +1439,6 @@ export default { await this.loadStructuralElement(this.currentElement.id); if (this.blockedByThisUser) { await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; await this.loadStructuralElement(this.currentElement.id); } this.showElementEditDialog(false); @@ -1482,7 +1476,6 @@ export default { } if (!this.blocked) { await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = true; } const file = this.$refs?.upload_image?.files[0]; if (file) { @@ -1519,7 +1512,6 @@ export default { id: this.currentId, }); await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; this.$emit('select', this.currentId); this.initCurrent(); }, @@ -1528,7 +1520,7 @@ export default { this.setStructuralElementSortMode(true); }, - async storeSort() { + storeSort() { this.setStructuralElementSortMode(false); this.sortContainersInStructualElements({ @@ -1536,19 +1528,11 @@ export default { containers: this.containerList, }); this.$emit('select', this.currentId); - if (this.blockedByThisUser) { - await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; - } }, - async resetSort() { + resetSort() { this.setStructuralElementSortMode(false); this.containerList = this.containers; - if (this.blockedByThisUser) { - await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; - } }, async exportCurrentElement(data) { @@ -1596,7 +1580,6 @@ export default { await this.loadStructuralElement(this.currentElement.id); if (this.blockedByThisUser) { await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; } this.showElementDeleteDialog(false); }, @@ -1658,7 +1641,7 @@ export default { this.companionSuccess({ info: this.$gettextInterpolate( - this.$gettext('Die Seite %{ pageTitle } wurde erfolgreich angelegt.'), + this.$gettext('Die Seite %{ pageTitle } wurde erfolgreich angelegt.'), { pageTitle: newElement.attributes.title } ) }); @@ -1726,42 +1709,13 @@ export default { }, async executeRemoveLock() { await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - this.objectIsBlocked = false; await this.loadStructuralElement(this.currentElement.id); this.showElementRemoveLockDialog(false); - }, - async beforeUnloadActions() { - this.beforeUnloadCleanup(); - if (this.blockedByThisUser && this.blocked || this.objectIsBlocked) { - await this.unlockObject({ id: this.currentId, type: 'courseware-structural-elements' }); - } - }, - beforeUnloadCleanup() { - // The following dialogs and elements must be set to be closed, in order to avoid lockObject conflicts. - this.showElementEditDialog(false); - this.showElementDeleteDialog(false); - this.setStructuralElementSortMode(false); - this.showElementAddDialog(false); - }, - async beforeUnloadHandler(event) { - if ((this.blockedByThisUser && this.blocked) || this.objectIsBlocked) { - event.preventDefault(); - event.returnValue = 'There are unsaved changes, do you want to leave?'; - await this.beforeUnloadActions(); - return event.returnValue; - } - return null; } }, created() { this.pluginManager.registerComponentsLocally(this); }, - mounted () { - STUDIP.eventBus.on('studip:beforeunload', this.beforeUnloadHandler); - }, - beforeDestroy () { - STUDIP.eventBus.off('studip:beforeunload', this.beforeUnloadHandler); - }, watch: { async structuralElement() {