diff --git a/client/components/widgets/BookDetailsEdit.vue b/client/components/widgets/BookDetailsEdit.vue
index b42082b5..5fbcaa20 100644
--- a/client/components/widgets/BookDetailsEdit.vue
+++ b/client/components/widgets/BookDetailsEdit.vue
@@ -3,67 +3,67 @@
@@ -105,6 +105,12 @@ export default {
}
},
methods: {
+ handleInputChange() {
+ this.$emit('change', {
+ libraryItemId: this.libraryItem.id,
+ hasChanges: this.checkForChanges().hasChanges
+ })
+ },
getDetails() {
this.forceBlur()
return this.checkForChanges()
@@ -136,6 +142,8 @@ export default {
}
}
}
+
+ this.handleInputChange()
},
forceBlur() {
if (this.$refs.titleInput) this.$refs.titleInput.blur()
diff --git a/client/pages/batch/index.vue b/client/pages/batch/index.vue
index 1f119387..5cc83176 100644
--- a/client/pages/batch/index.vue
+++ b/client/pages/batch/index.vue
@@ -97,8 +97,8 @@
@@ -108,7 +108,7 @@
-
{{ $strings.ButtonSave }}
+
{{ $strings.ButtonSave }}
@@ -170,7 +170,8 @@ export default {
abridged: false
},
appendableKeys: ['authors', 'genres', 'tags', 'narrators', 'series'],
- openMapOptions: false
+ openMapOptions: false,
+ itemsWithChanges: []
}
},
computed: {
@@ -221,9 +222,19 @@ export default {
},
hasSelectedBatchUsage() {
return Object.values(this.selectedBatchUsage).some((b) => !!b)
+ },
+ hasChanges() {
+ return this.itemsWithChanges.length > 0
}
},
methods: {
+ handleItemChange(itemChange) {
+ if (!itemChange.hasChanges) {
+ this.itemsWithChanges = this.itemsWithChanges.filter((id) => id !== itemChange.libraryItemId)
+ } else if (!this.itemsWithChanges.includes(itemChange.libraryItemId)) {
+ this.itemsWithChanges.push(itemChange.libraryItemId)
+ }
+ },
blurBatchForm() {
if (this.$refs.seriesSelect && this.$refs.seriesSelect.isFocused) {
this.$refs.seriesSelect.forceBlur()
@@ -283,38 +294,10 @@ export default {
removedSeriesItem(item) {},
newNarratorItem(item) {},
removedNarratorItem(item) {},
- newTagItem(item) {
- // if (item && !this.newTagItems.includes(item)) {
- // this.newTagItems.push(item)
- // }
- },
- removedTagItem(item) {
- // If newly added, remove if not used on any other items
- // if (item && this.newTagItems.includes(item)) {
- // var usedByOtherAb = this.libraryItemCopies.find((ab) => {
- // return ab.tags && ab.tags.includes(item)
- // })
- // if (!usedByOtherAb) {
- // this.newTagItems = this.newTagItems.filter((t) => t !== item)
- // }
- // }
- },
- newGenreItem(item) {
- // if (item && !this.newGenreItems.includes(item)) {
- // this.newGenreItems.push(item)
- // }
- },
- removedGenreItem(item) {
- // If newly added, remove if not used on any other items
- // if (item && this.newGenreItems.includes(item)) {
- // var usedByOtherAb = this.libraryItemCopies.find((ab) => {
- // return ab.book.genres && ab.book.genres.includes(item)
- // })
- // if (!usedByOtherAb) {
- // this.newGenreItems = this.newGenreItems.filter((t) => t !== item)
- // }
- // }
- },
+ newTagItem(item) {},
+ removedTagItem(item) {},
+ newGenreItem(item) {},
+ removedGenreItem(item) {},
init() {
// TODO: Better deep cloning of library items
this.libraryItemCopies = this.libraryItems.map((li) => {
@@ -376,6 +359,7 @@ export default {
.then((data) => {
this.isProcessing = false
if (data.updates) {
+ this.itemsWithChanges = []
this.$toast.success(`Successfully updated ${data.updates} items`)
this.$router.replace(`/library/${this.currentLibraryId}/bookshelf`)
} else {
@@ -387,10 +371,28 @@ export default {
this.$toast.error('Failed to batch update')
this.isProcessing = false
})
+ },
+ beforeUnload(e) {
+ if (!e || !this.hasChanges) return
+ e.preventDefault()
+ e.returnValue = ''
+ }
+ },
+ beforeRouteLeave(to, from, next) {
+ if (this.hasChanges) {
+ next(false)
+ window.location = to.path
+ } else {
+ next()
}
},
mounted() {
this.init()
+
+ window.addEventListener('beforeunload', this.beforeUnload)
+ },
+ beforeDestroy() {
+ window.removeEventListener('beforeunload', this.beforeUnload)
}
}