lib/alexandria/ui/dialogs/book_properties_dialog.rb in alexandria-book-collection-manager-0.7.2 vs lib/alexandria/ui/dialogs/book_properties_dialog.rb in alexandria-book-collection-manager-0.7.3

- old
+ new

@@ -116,28 +116,30 @@ def on_close if @entry_isbn.text == '' # If set to nil .to_yaml in library.save causes crash @book.isbn = '' else - ary = @library.select { |book| book.ident == @entry_isbn.text } + isbn = Library.canonicalise_ean(@entry_isbn.text) + unless isbn + ErrorDialog.new(@book_properties_dialog, + _("Couldn't modify the book"), + _("Couldn't validate the EAN/ISBN you " \ + 'provided. Make sure it is written ' \ + 'correcty, and try again.')).display + return + end + + ary = @library.select { |book| book.ident == isbn } unless ary.empty? || ((ary.length == 1) && (ary.first == @book)) - ErrorDialog.new(@parent, + ErrorDialog.new(@book_properties_dialog, _("Couldn't modify the book"), _('The EAN/ISBN you provided is already ' \ - 'used in this library.')) + 'used in this library.')).display return end - @book.isbn = begin - Library.canonicalise_ean(@entry_isbn.text) - rescue Alexandria::Library::InvalidISBNError - ErrorDialog.new(@parent, - _("Couldn't modify the book"), - _("Couldn't validate the EAN/ISBN you " \ - 'provided. Make sure it is written ' \ - 'correcty, and try again.')) - return - end + + @book.isbn = isbn end @book.title = @entry_title.text @book.publisher = @entry_publisher.text year = @entry_publish_date.text.to_i @book.publishing_year = year.zero? ? nil : year @@ -151,14 +153,11 @@ @book.loaned_to = @entry_loaned_to.text loaned_since = @date_loaned_since.text if loaned_since.strip.empty? @book.loaned_since = nil else - begin - t = parse_date(loaned_since) - @book.loaned_since = t - rescue - end + t = parse_date(loaned_since) + @book.loaned_since = t end @book.redd = @checkbutton_redd.active? if @book.redd redd_date = @redd_date.text