2021-11-07 02:31:46 +01:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="edit-collection" :width="700" :height="'unset'" :processing="processing">
|
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
|
|
|
<p class="font-book text-3xl text-white truncate">Collection</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div class="p-4 w-full text-sm py-6 rounded-lg bg-bg shadow-lg border border-black-300 relative overflow-hidden" style="min-height: 400px; max-height: 80vh">
|
2021-11-13 02:43:16 +01:00
|
|
|
<template v-if="!showImageUploader">
|
|
|
|
<form @submit.prevent="submitForm">
|
|
|
|
<div class="flex">
|
|
|
|
<div>
|
2021-12-03 02:02:38 +01:00
|
|
|
<covers-collection-cover :book-items="books" :width="200" :height="100 * bookCoverAspectRatio" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-11-13 02:43:16 +01:00
|
|
|
<!-- <ui-btn type="button" @click="showImageUploader = true">Upload</ui-btn> -->
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-4">
|
|
|
|
<ui-text-input-with-label v-model="newCollectionName" label="Name" class="mb-2" />
|
2021-11-07 02:31:46 +01:00
|
|
|
|
2021-11-13 02:43:16 +01:00
|
|
|
<ui-textarea-with-label v-model="newCollectionDescription" label="Description" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="absolute bottom-0 left-0 right-0 w-full py-2 px-4 flex">
|
2022-08-31 22:46:10 +02:00
|
|
|
<ui-btn v-if="userCanDelete" small color="error" type="button" @click.stop="removeClick">Remove</ui-btn>
|
2021-11-13 02:43:16 +01:00
|
|
|
<div class="flex-grow" />
|
|
|
|
<ui-btn color="success" type="submit">Save</ui-btn>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<div class="flex items-center mb-3">
|
|
|
|
<div class="hover:bg-white hover:bg-opacity-10 cursor-pointer h-11 w-11 flex items-center justify-center rounded-full" @click="showImageUploader = false">
|
|
|
|
<span class="material-icons text-4xl">arrow_back</span>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
2021-11-13 02:43:16 +01:00
|
|
|
<p class="ml-2 text-xl mb-1">Collection Cover Image</p>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
2021-11-13 02:43:16 +01:00
|
|
|
<div class="flex mb-4">
|
|
|
|
<ui-btn small class="mr-2">Upload</ui-btn>
|
|
|
|
<ui-text-input v-model="newCoverImage" class="flex-grow" placeholder="Collection Cover Image" />
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
2021-11-13 02:43:16 +01:00
|
|
|
<div class="flex justify-end">
|
|
|
|
<ui-btn color="success">Upload</ui-btn>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<!-- <modals-upload-image-modal v-model="showUploadImageModal" entity="collection" :entity-id="collection.id" /> -->
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
processing: false,
|
|
|
|
newCollectionName: null,
|
2021-11-08 01:11:29 +01:00
|
|
|
newCollectionDescription: null,
|
2021-11-13 02:43:16 +01:00
|
|
|
showImageUploader: false
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.globals.showEditCollectionModal
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('globals/setShowEditCollectionModal', val)
|
|
|
|
}
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
collection() {
|
|
|
|
return this.$store.state.globals.selectedCollection || {}
|
|
|
|
},
|
|
|
|
collectionName() {
|
|
|
|
return this.collection.name
|
|
|
|
},
|
|
|
|
books() {
|
|
|
|
return this.collection.books || []
|
2022-08-31 22:46:10 +02:00
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
init() {
|
|
|
|
this.newCollectionName = this.collectionName
|
|
|
|
this.newCollectionDescription = this.collection.description || ''
|
|
|
|
},
|
|
|
|
removeClick() {
|
|
|
|
if (confirm(`Are you sure you want to remove collection "${this.collectionName}"?`)) {
|
|
|
|
this.processing = true
|
|
|
|
var collectionName = this.collectionName
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$delete(`/api/collections/${this.collection.id}`)
|
2021-11-07 02:31:46 +01:00
|
|
|
.then(() => {
|
|
|
|
this.processing = false
|
|
|
|
this.show = false
|
|
|
|
this.$toast.success(`Collection "${collectionName}" Removed`)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove collection', error)
|
|
|
|
this.processing = false
|
|
|
|
this.$toast.error(`Failed to remove collection`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
submitForm() {
|
|
|
|
if (this.newCollectionName === this.collectionName && this.newCollectionDescription === this.collection.description) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!this.newCollectionName) {
|
|
|
|
return this.$toast.error('Collection must have a name')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.processing = true
|
|
|
|
|
|
|
|
var collectionUpdate = {
|
|
|
|
name: this.newCollectionName,
|
|
|
|
description: this.newCollectionDescription || null
|
|
|
|
}
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$patch(`/api/collections/${this.collection.id}`, collectionUpdate)
|
2021-11-07 02:31:46 +01:00
|
|
|
.then((collection) => {
|
|
|
|
console.log('Collection Updated', collection)
|
|
|
|
this.processing = false
|
|
|
|
this.show = false
|
|
|
|
this.$toast.success(`Collection "${collection.name}" Updated`)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update collection', error)
|
|
|
|
this.processing = false
|
|
|
|
this.$toast.error(`Failed to update collection`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {},
|
|
|
|
beforeDestroy() {}
|
|
|
|
}
|
|
|
|
</script>
|