diff --git a/frontend/src/components/Authors.vue b/frontend/src/components/Authors.vue index b5c29cb..04ee122 100644 --- a/frontend/src/components/Authors.vue +++ b/frontend/src/components/Authors.vue @@ -178,22 +178,26 @@ export default { DeleteAuthor (obj) { this.showModal = true this.$on('delete-submit', function () { - HTTP.delete('authors/' + obj.ID.content) - .then(response => { - if (response.status === 200 && response.data.Message === 'success') { - // Fire a notification - this.$notify({ - type: 'success', - title: this.langGeneral.success, - text: this.translate('authors').deleteSuccess - }) + // Prevent deleting already deleted authors + if (obj) { + HTTP.delete('authors/' + obj.ID.content) + .then(response => { + if (response.status === 200 && response.data.Message === 'success') { + // Fire a notification + this.$notify({ + type: 'success', + title: this.langGeneral.success, + text: this.translate('authors').deleteSuccess + }) + this.loadAuthors() + } + }) + .catch(e => { + this.errorNotification(e) this.loadAuthors() - } - }) - .catch(e => { - this.errorNotification(e) - this.loadAuthors() - }) + }) + } + obj = null this.showModal = false }) }, diff --git a/frontend/src/components/Books.vue b/frontend/src/components/Books.vue index e6d7066..5562b73 100644 --- a/frontend/src/components/Books.vue +++ b/frontend/src/components/Books.vue @@ -233,22 +233,26 @@ export default { deleteBook (obj) { this.showModal = true this.$on('delete-submit', function () { - HTTP.delete('books/' + obj.ID.content) - .then(response => { - if (response.status === 200 && response.data.Message === 'success') { - // Fire a notification - this.$notify({ - type: 'success', - title: this.langGeneral.success, - text: this.langBook.deleteSuccess - }) + // Prevent deleting already deleted books + if (obj) { + HTTP.delete('books/' + obj.ID.content) + .then(response => { + if (response.status === 200 && response.data.Message === 'success') { + // Fire a notification + this.$notify({ + type: 'success', + title: this.langGeneral.success, + text: this.langBook.deleteSuccess + }) + this.loadBooks() + } + }) + .catch(e => { + this.errorNotification(e) this.loadBooks() - } - }) - .catch(e => { - this.errorNotification(e) - this.loadBooks() - }) + }) + } + obj = null this.showModal = false }) }, diff --git a/frontend/src/components/Modal.vue b/frontend/src/components/Modal.vue index dcea488..bddc6ce 100644 --- a/frontend/src/components/Modal.vue +++ b/frontend/src/components/Modal.vue @@ -40,9 +40,9 @@ this.$emit('close') } // Send it when enter is pressed - if (e.keyCode === 13) { + /* if (e.keyCode === 13) { this.$emit('submit') - } + } */ }) } } diff --git a/frontend/src/components/Publishers.vue b/frontend/src/components/Publishers.vue index 5769adb..b851a67 100644 --- a/frontend/src/components/Publishers.vue +++ b/frontend/src/components/Publishers.vue @@ -177,21 +177,25 @@ export default { DeletePublisher (obj) { this.showModal = true this.$on('delete-submit', function () { - HTTP.delete('publishers/' + obj.ID.content) - .then(response => { - if (response.status === 200 && response.data.Message === 'success') { - // Fire a notification - this.$notify({ - type: 'success', - title: this.langGeneral.success, - text: this.translate('publishers').deleteSuccess - }) - this.loadPublishers() - } - }) - .catch(e => { - this.errorNotification(e) - }) + // Prevent again deleting already deleted publishers + if (obj) { + HTTP.delete('publishers/' + obj.ID.content) + .then(response => { + if (response.status === 200 && response.data.Message === 'success') { + // Fire a notification + this.$notify({ + type: 'success', + title: this.langGeneral.success, + text: this.translate('publishers').deleteSuccess + }) + this.loadPublishers() + } + }) + .catch(e => { + this.errorNotification(e) + }) + } + obj = null this.showModal = false }) }, diff --git a/models/books_add_update.go b/models/books_add_update.go index 0f70c5e..279c5a5 100644 --- a/models/books_add_update.go +++ b/models/books_add_update.go @@ -35,12 +35,18 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) { } } + fmt.Println(publisherid) + _, exists, err = GetPublisherByID(publisherid) if err != nil { return Book{}, err } - if !exists { + // If the publisher exists, make it the new publisher of the book + if exists { + book.PublisherID = publisherid + } else { + // Otherwise insert it and make it the new publisher afterwards newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.Publisher.Name}) if err != nil { return Book{}, err diff --git a/models/publishers_add.go b/models/publishers_add.go index b356999..21bdc41 100644 --- a/models/publishers_add.go +++ b/models/publishers_add.go @@ -3,10 +3,12 @@ package models // AddOrUpdatePublisher adds or updates a publisher from a publisher struct func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) { if publisher.ID == 0 { - _, err = x.Insert(&publisher) + if publisher.Name != "" { // Only insert it if the name is not empty + _, err = x.Insert(&publisher) - if err != nil { - return Publisher{}, err + if err != nil { + return Publisher{}, err + } } } else { _, err = x.Where("id = ?", publisher.ID).Update(&publisher)